I making a game engine. i making it on mglw, then i decided to change moderngl_window to pygame, and
it shows only blank black screen.
here is the code:
`
import sys
import moderngl as mgl
import moderngl_window.geometry
import pygame as pg
class Engine:
def __init__(self, win_size=(1600, 900)):
pg.init()
self.WIN_SIZE = win_size
self.cam_pos = glm.vec3(0, 15, -5)
self.clock = pg.time.Clock()
pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
self.window = pg.display.set_mode(self.WIN_SIZE, flags=pg.OPENGL | pg.DOUBLEBUF)
pg.event.set_grab(True)
pg.mouse.set_visible(False)
self.ctx = mgl.create_context()
self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE)
moderngl_window.activate_context(self)
# i think its not work now
self.resizable = False
@staticmethod
def check_events():
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
def render(self):
dx, dy = pg.mouse.get_rel()
self.ctx.screen.use()
moderngl_window.geometry.quad_fs().render(self.ctx.program(fragment_shader='
`#version 330
out vec4 FragColor;
void main(){
vec3 col = vec3(1, 0, 0);
FragColor = vec4(col, 1.0);
}
`', vertex_shader='
`#version 330 core
in vec3 in_position;
void main() {
gl_Position = vec4(in_position, 1.0);
}
`'))
pg.display.flip()
self.clock.tick(60)
def run(self):
while True:
self.check_events()
self.render()
if __name__ == "__main__":
app = Engine()
app.run()
`
i expected it show me red screen, but it showed only black screen.
New contributor
Just a cat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.