def update_display(verts,tex_coords,texture=bird_texture): gl.glClearColor(0.2, 0.4, 0.5, 1.0) gl.glEnable(texture.target) gl.glBindTexture(texture.target, texture.id) gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc (gl.GL_GREATER, .1) #gl.glEnable(gl.GL_BLEND) #gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) n=len(verts[:]) #TODO verts._buffer.ctypes.data is awkward gl.glVertexPointer(3, vert_dtype.gl, 0, verts[:].ctypes.data) gl.glTexCoordPointer(3, tex_dtype.gl, 0, tex_coords[:].ctypes.data) gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n) #unset state gl.glPopAttrib() gl.glDisable(texture.target)
def setup(): """ Basic OpenGL configuration. """ # Set the color of "clear", i.e. the sky, in rgba. gl.glClearColor(0.5, 0.69, 1.0, 1) # Enable culling (not rendering) of back-facing facets -- facets that aren't # visible to you. gl.glEnable(gl.GL_CULL_FACE) #gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_DST_ALPHA) #gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR) gl.glEnable(gl.GL_BLEND) gl.glAlphaFunc(gl.GL_GREATER, 0.5); gl.glEnable(gl.GL_ALPHA_TEST); # Set the texture minification/magnification function to GL_NEAREST (nearest # in Manhattan distance) to the specified texture coordinates. GL_NEAREST # "is generally faster than GL_LINEAR, but it can produce textured images # with sharper edges because the transition between texture elements is not # as smooth." gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE) setup_fog()
def start(self, level=1): w, h = SCREEN_SIZE self.window = pyglet.window.Window(width=w, height=h, caption=NAME) self.game = self.scene = Scene(self, level=level) self.squid = self.game.world.squid self.editor = Editor(self, self.game.world) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_ALWAYS) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glTranslatef(0, 0, -0.5) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0) self.fps_display = pyglet.clock.ClockDisplay() pyglet.clock.schedule_interval(self.update, 1 / TARGET_FPS) pyglet.clock.set_fps_limit(TARGET_FPS) self.window.push_handlers(on_key_press=self.on_key_press) self.window.push_handlers() if level == 1: self.title_screen() else: self.next_level() pyglet.app.run()
def init(cls, caption: str, vsync: bool, w: int, h: int): cls.window = pyglet.window.Window(caption=caption, vsync=vsync, width=w, height=h) cls.window.push_handlers(cls.keys) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(pyglet.gl.GL_ALPHA_TEST) glAlphaFunc(pyglet.gl.GL_GREATER, .1) cls.window.on_draw = cls.on_draw from gameengine.managers.InputManager import InputManager cls.window.on_mouse_motion = InputManager().on_mouse_motion cls.window.on_mouse_press = InputManager().on_mouse_press cls.window.on_mouse_release = InputManager().on_mouse_release cls.window.on_mouse_drag = InputManager().on_mouse_drag cls.window.on_mouse_scroll = InputManager().on_mouse_scroll cls.window.on_key_press = InputManager().on_key_press cls.window.on_key_release = InputManager().on_key_release cls.fps_display = pyglet.window.FPSDisplay(cls.window)
def update_display(verts, tex_coords, texture=bird_texture): gl.glClearColor(0.2, 0.4, 0.5, 1.0) gl.glEnable(texture.target) gl.glBindTexture(texture.target, texture.id) gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, .1) #gl.glEnable(gl.GL_BLEND) #gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) n = len(verts[:]) #TODO verts._buffer.ctypes.data is awkward gl.glVertexPointer(3, vert_dtype.gl, 0, verts[:].ctypes.data) gl.glTexCoordPointer(3, tex_dtype.gl, 0, tex_coords[:].ctypes.data) gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n) #unset state gl.glPopAttrib() gl.glDisable(texture.target)
def setup(): """ Basic OpenGL configuration. """ # Set the color of "clear", i.e. the sky, in rgba. gl.glClearColor(0.5, 0.69, 1.0, 1) # Enable culling (not rendering) of back-facing facets -- facets that aren't # visible to you. gl.glEnable(gl.GL_CULL_FACE) #gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_DST_ALPHA) #gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR) gl.glEnable(gl.GL_BLEND) gl.glAlphaFunc(gl.GL_GREATER, 0.5) gl.glEnable(gl.GL_ALPHA_TEST) # Set the texture minification/magnification function to GL_NEAREST (nearest # in Manhattan distance) to the specified texture coordinates. GL_NEAREST # "is generally faster than GL_LINEAR, but it can produce textured images # with sharper edges because the transition between texture elements is not # as smooth." gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE) setup_fog()
def draw(self): """Draw the floor and any decals.""" gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0.0) self.get_floor_batch().draw() if wave.current_wave or keys[key.SPACE]: gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) for character in self.world.get_all_player_actors(): if character.weapon and character.weapon.field_of_fire: self.get_fof_effect(character.weapon.field_of_fire, character.colour).draw() gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) else: goals.draw_outline(self.camera) self.cursor.draw()
def render(self): # Enable blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # Enable transparency gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, .1) # Load textures self.texture = pyglet.image.TextureGrid( pyglet.image.ImageGrid( pyglet.image.load( self.test_data.get_file('images', 'multitexture.png')), 1, 4)) self.background = pyglet.image.load( self.test_data.get_file('images', 'grey_background.png')).get_texture() # Create vertex list showing the multi texture self.vertex_list = pyglet.graphics.vertex_list(4, ('v2f', (32, 332, 64, 332, 64, 364, 32, 364)), ('0t3f', self.texture[1].tex_coords), ('1t3f', self.texture[2].tex_coords), ('2t3f', self.texture[3].tex_coords))