Python pyglet.gl.glBindTexture() Examples
The following are 9
code examples of pyglet.gl.glBindTexture().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyglet.gl
, or try the search function
.
Example #1
Source File: texture.py From pywonderland with MIT License | 7 votes |
def create_image_texture(imgfile): """Create a 2D texture from an image file. """ image = pyglet.image.load(imgfile) data = image.get_data("RGBA", image.width * 4) tex = gl.GLuint() gl.glGenTextures(1, ct.pointer(tex)) gl.glBindTexture(gl.GL_TEXTURE_2D, tex) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, image.width, image.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data) gl.glBindTexture(tex, 0) return tex
Example #2
Source File: loxodrome.py From pywonderland with MIT License | 6 votes |
def __init__(self, width, height, aa): pyglet.window.Window.__init__(self, width, height, caption="Loxodromic transformation", resizable=True, visible=False, vsync=False) self._start_time = time.clock() self.shader = Shader(["./glsl/loxodrome.vert"], ["./glsl/loxodrome.frag"]) self.buffer = pyglet.image.get_buffer_manager().get_color_buffer() texture = create_image_texture(WOOD_TEXTURE) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBindTexture(gl.GL_TEXTURE_2D, texture) with self.shader: self.shader.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1]) self.shader.uniformf("iResolution", width, height, 0.0) self.shader.uniformf("iTime", 0.0) self.shader.uniformi("iTexture", 0) self.shader.uniformi("AA", aa)
Example #3
Source File: texture.py From pywonderland with MIT License | 5 votes |
def create_texture_from_ndarray(array): """Create a 2D texture from a numpy ndarray. """ height, width = array.shape[:2] texture = pyglet.image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA32F_ARB) gl.glBindTexture(texture.target, texture.id) gl.glTexImage2D(texture.target, texture.level, gl.GL_RGBA32F_ARB, width, height, 0, gl.GL_RGBA, gl.GL_FLOAT, array.ctypes.data) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) gl.glBindTexture(texture.target, 0) return texture
Example #4
Source File: texture.py From pywonderland with MIT License | 5 votes |
def create_cubemap_texture(imgfiles): """Create a cubemap texture from image files. """ if len(imgfiles) != 6: raise ValueError("exactly six images are required for a cubemap texture") # generate a new texture cubemap = gl.GLuint() gl.glGenTextures(1, ct.pointer(cubemap)) # bind it to `GL_TEXTURE_CUBE_MAP` and set the filter and wrap mode gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, cubemap) gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_R, gl.GL_CLAMP_TO_EDGE) faces = [Image.open(img) for img in imgfiles] # set the faces of the cubemap texture for i, face in enumerate(faces): width, height = face.size try: data = face.tobytes("raw", "RGBX", 0, -1) except TypeError: data = face.tobytes("raw", "RGBA", 0, -1) gl.glTexImage2D(gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.GL_RGBA, width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data) gl.glGenerateMipmap(gl.GL_TEXTURE_CUBE_MAP) gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, 0) return cubemap
Example #5
Source File: simulator.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_draw(self): self.window.clear() gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() self.camera() gl.glEnable(self.background.target) gl.glEnable(gl.GL_BLEND) gl.glBindTexture(self.background.target, self.background.id) W = 10000. graphics.draw(4, gl.GL_QUADS, ('v2f', (-W, -W, W, -W, W, W, -W, W)), ('t2f', (0., 0., W * 5., 0., W * 5., W * 5., 0., W * 5.)) ) gl.glDisable(self.background.target) for lane in self.world.lanes: self.draw_lane_surface(lane) self.draw_lane_lines(lane) for obj in self.world.objects: self.draw_object(obj) for car in self.world.cars: self.draw_car(car.trajectory[-1], car.color) gl.glPopMatrix() self.label.text = self.task_name self.label.draw() self.iter +=1 if self.iter%10 == 0: print('Iterations: ', self.iter) if self.iter == self.max_iters: self.event_loop.exit()
Example #6
Source File: test_multitexture.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _bind_texture(self, i): gl.glActiveTexture((gl.GL_TEXTURE0, gl.GL_TEXTURE1, gl.GL_TEXTURE2)[i]) gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture[i].id) gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE) gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_ALPHA, gl.GL_REPLACE if i == 0 else gl.GL_ADD) 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)
Example #7
Source File: framebuffer.py From pineal with GNU Affero General Public License v3.0 | 5 votes |
def buffer_texture(width, height): id_ = gl.GLuint() gl.glGenTextures(1, byref(id_)) gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TEXTURE_BIT) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glEnable(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, id_) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, (gl.GLubyte * (width*height * 4))(), ) gl.glFlush() gl.glBindTexture(gl.GL_TEXTURE_2D, 0) gl.glPopAttrib() return id_
Example #8
Source File: example_wythoff_shader_animation.py From pywonderland with MIT License | 4 votes |
def __init__(self, width, height): """ :param width and height: size of the window in pixels. """ pyglet.window.Window.__init__(self, width, height, caption="Wythoff Explorer", resizable=True, visible=False, vsync=False) self._start_time = time.clock() self._last = self._now = self._start_time self._frame_count = 0 # count number of frames rendered so far self.shaderA = Shader(["./glsl_wythoff/wythoff.vert"], ["./glsl_wythoff/common.frag", "./glsl_wythoff/BufferA.frag"]) self.shaderB = Shader(["./glsl_wythoff/wythoff.vert"], ["./glsl_wythoff/common.frag", "./glsl_wythoff/main.frag"]) self.font_texture = create_image_texture(FONT_TEXTURE) self.noise_texture = create_image_texture(NOISE_TEXTURE) self.iChannel0 = pyglet.image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA32F_ARB) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBindTexture(self.iChannel0.target, self.iChannel0.id) gl.glActiveTexture(gl.GL_TEXTURE1) gl.glBindTexture(gl.GL_TEXTURE_2D, self.font_texture) gl.glActiveTexture(gl.GL_TEXTURE2) gl.glBindTexture(gl.GL_TEXTURE_2D, self.noise_texture) with FrameBuffer() as self.bufferA: self.bufferA.attach_texture(self.iChannel0) # initialize the shaders with self.shaderA: self.shaderA.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1]) self.shaderA.uniformf("iResolution", width, height, 0.0) self.shaderA.uniformf("iTime", 0.0) self.shaderA.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0) self.shaderA.uniformi("iChannel0", 0) self.shaderA.uniformi("iChannel1", 1) self.shaderA.uniformi("iChannel2", 2) self.shaderA.uniformf("iDate", *get_idate()) self.shaderA.uniformf("iTimeDelta", 0) with self.shaderB: self.shaderB.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1]) self.shaderB.uniformf("iResolution", width, height, 0.0) self.shaderB.uniformf("iTime", 0.0) self.shaderB.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0) self.shaderB.uniformi("iChannel0", 0) self.shaderB.uniformi("iChannel1", 1) self.shaderB.uniformi("iChannel2", 2) self.shaderB.uniformf("iDate", *get_idate()) self.shaderA.uniformf("iTimeDelta", 0)
Example #9
Source File: render.py From RLSchool with Apache License 2.0 | 4 votes |
def show_drone(self, position, rotation): """ Show the drone 3D model with corresponding translation and rotation. """ # Get the transform matrix for drone 3D model x, z, y = position transform = np.eye(4) transform[:3, 3] = [x, y, z] # NOTE: change the view size of drone 3D model transform[0, 0] = 2.5 transform[1, 1] = 2.5 transform[2, 2] = 2.5 # Match drone model space x-y-z to openGL x-z-y # TODO: read the config.json and match the propeller positions model_space_transform = rotation_transform_mat(-np.pi / 2, 'roll') transform = np.dot(transform, model_space_transform) yaw, pitch, roll = rotation if self.debug_mode: # NOTE: manually set values to debug rotation, # it's useful when input act is in form [c, c, c, c]. yaw = np.pi / 2 # pitch = np.pi / 2 # roll = np.pi / 2 transform = np.dot(transform, rotation_transform_mat(yaw, 'yaw')) transform = np.dot(transform, rotation_transform_mat(pitch, 'pitch')) transform = np.dot(transform, rotation_transform_mat(roll, 'roll')) # Add a new matrix to the model stack to transform the model gl.glPushMatrix() gl.glMultMatrixf(rendering.matrix_to_gl(transform)) # Enable the target texture if self.drone_texture is not None: gl.glEnable(self.drone_texture.target) gl.glBindTexture(self.drone_texture.target, self.drone_texture.id) # Draw the mesh with its transform applied self.drone_drawer.draw(mode=self.drone_vertex_list_mode) gl.glPopMatrix() # Disable texture after using if self.drone_texture is not None: gl.glDisable(self.drone_texture.target)