-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_init.py
More file actions
57 lines (49 loc) · 1.89 KB
/
Copy pathtest_init.py
File metadata and controls
57 lines (49 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pygame
import moderngl
import numpy as np
from pyrr import Matrix44
import sys
import os
# Set dummy video driver for headless environments if needed,
# but here we want to test if it CAN initialize.
# os.environ['SDL_VIDEODRIVER'] = 'dummy'
def get_cube_data():
vertices = np.array([
-0.5, -0.5, 0.5, 1, 0, 0,
0.5, -0.5, 0.5, 0, 1, 0,
0.5, 0.5, 0.5, 0, 0, 1,
-0.5, 0.5, 0.5, 1, 1, 0,
-0.5, -0.5, -0.5, 1, 0, 1,
0.5, -0.5, -0.5, 0, 1, 1,
0.5, 0.5, -0.5, 1, 1, 1,
-0.5, 0.5, -0.5, 0, 0, 0,
], dtype='f4')
indices = np.array([0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 5, 4, 7, 7, 6, 5, 4, 0, 3, 3, 7, 4, 3, 2, 6, 6, 7, 3, 4, 5, 1, 1, 0, 4], dtype='i4')
return vertices, indices
def main():
try:
pygame.init()
# Use small window for test
pygame.display.set_mode((100, 100), pygame.OPENGL | pygame.DOUBLEBUF)
ctx = moderngl.create_context(standalone=True) # Use standalone for CI/test environments
print("ModernGL Context created successfully")
with open('renderer/shaders/basic.vert', 'r') as f:
vertex_shader = f.read()
with open('renderer/shaders/basic.frag', 'r') as f:
fragment_shader = f.read()
prog = ctx.program(vertex_shader=vertex_shader, fragment_shader=fragment_shader)
vertices, indices = get_cube_data()
vbo = ctx.buffer(vertices)
ibo = ctx.buffer(indices)
vao = ctx.vertex_array(prog, [(vbo, '3f 3f', 'in_position', 'in_color')], ibo)
ctx.clear(0.1, 0.1, 0.1)
vao.render()
print("Render call successful")
pygame.quit()
print("Initialization test PASSED")
sys.exit(0)
except Exception as e:
print(f"Initialization test FAILED: {e}")
sys.exit(1)
if __name__ == "__main__":
main()