File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ """ pygame.examples.window_opengl
2+
3+ Slightly modified version of the example at https://github.com/szabolcsdombi/zengl/blob/main/examples/pygame/hello_world.py
4+ Modified to use Window API instead of the display module
5+
6+ Posted here with permission from https://github.com/szabolcsdombi given in the PGC discord server
7+ """
8+
9+ import pygame
10+ import zengl
11+
12+ window_size = (1280 , 720 )
13+
14+ pygame .init ()
15+ window = pygame .Window (size = window_size , opengl = True )
16+
17+ ctx = zengl .context ()
18+
19+ image = ctx .image (window_size , "rgba8unorm" , samples = 4 )
20+
21+ pipeline = ctx .pipeline (
22+ vertex_shader = """
23+ #version 330 core
24+
25+ out vec3 v_color;
26+
27+ vec2 vertices[3] = vec2[](
28+ vec2(0.0, 0.8),
29+ vec2(-0.6, -0.8),
30+ vec2(0.6, -0.8)
31+ );
32+
33+ vec3 colors[3] = vec3[](
34+ vec3(1.0, 0.0, 0.0),
35+ vec3(0.0, 1.0, 0.0),
36+ vec3(0.0, 0.0, 1.0)
37+ );
38+
39+ void main() {
40+ gl_Position = vec4(vertices[gl_VertexID], 0.0, 1.0);
41+ v_color = colors[gl_VertexID];
42+ }
43+ """ ,
44+ fragment_shader = """
45+ #version 330 core
46+
47+ in vec3 v_color;
48+
49+ layout (location = 0) out vec4 out_color;
50+
51+ void main() {
52+ out_color = vec4(v_color, 1.0);
53+ out_color.rgb = pow(out_color.rgb, vec3(1.0 / 2.2));
54+ }
55+ """ ,
56+ framebuffer = [image ],
57+ topology = "triangles" ,
58+ vertex_count = 3 ,
59+ )
60+
61+ clock = pygame .Clock ()
62+
63+ while True :
64+ for event in pygame .event .get ():
65+ if event .type == pygame .QUIT :
66+ pygame .quit ()
67+ quit ()
68+
69+ ctx .new_frame ()
70+ image .clear ()
71+ pipeline .render ()
72+ image .blit ()
73+ ctx .end_frame ()
74+
75+ window .flip ()
76+ clock .tick (60 )
You can’t perform that action at this time.
0 commit comments