Python OpenGL.GL.GL_UNSIGNED_BYTE Examples
The following are 30
code examples of OpenGL.GL.GL_UNSIGNED_BYTE().
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
OpenGL.GL
, or try the search function
.
Example #1
Source File: opengl.py From pyimgui with BSD 3-Clause "New" or "Revised" License | 7 votes |
def refresh_font_texture(self): # save texture state last_texture = gl.glGetIntegerv(gl.GL_TEXTURE_BINDING_2D) width, height, pixels = self.io.fonts.get_tex_data_as_rgba32() if self._font_texture is not None: gl.glDeleteTextures([self._font_texture]) self._font_texture = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._font_texture) 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, pixels) self.io.fonts.texture_id = self._font_texture gl.glBindTexture(gl.GL_TEXTURE_2D, last_texture) self.io.fonts.clear_tex_data()
Example #2
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def prepare_text_instanced(self, text_array, textblock_size, origin_lat=None, origin_lon=None, text_color=None, char_size=16.0, vertex_offset=(0.0, 0.0)): ret = RenderObject(gl.GL_TRIANGLES, vertex_count=6) w, h = char_size, char_size * self.char_ar x, y = vertex_offset v, t = self.char(x, y, w, h) vertices = v texcoords = t ret.bind_attrib(self.attrib_vertex, 2, np.array(vertices, dtype=np.float32)) ret.bind_attrib(self.attrib_texcoords, 3, np.array(texcoords, dtype=np.float32)) ret.bind_attrib(self.attrib_texdepth, 1, text_array, instance_divisor=1, datatype=gl.GL_UNSIGNED_BYTE) divisor = textblock_size[0] * textblock_size[1] if origin_lat is not None: ret.bind_attrib(self.attrib_lat, 1, origin_lat, instance_divisor=divisor) if origin_lon is not None: ret.bind_attrib(self.attrib_lon, 1, origin_lon, instance_divisor=divisor) if text_color is not None: ret.bind_attrib(self.attrib_color, 4, text_color, datatype=gl.GL_UNSIGNED_BYTE, normalize=True, instance_divisor=divisor) ret.block_size = textblock_size ret.char_size = char_size return ret
Example #3
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def prepare_text_string(self, text_string, char_size=16.0, text_color=(0.0, 1.0, 0.0), vertex_offset=(0.0, 0.0)): ret = RenderObject(gl.GL_TRIANGLES, vertex_count=6 * len(text_string)) vertices, texcoords = [], [] w, h = char_size, char_size * self.char_ar x, y = vertex_offset for i, c in enumerate(text_string): v, t = self.char(x + i * w, y, w, h, ord(c)) vertices += v texcoords += t ret.bind_attrib(self.attrib_vertex, 2, np.array(vertices, dtype=np.float32)) ret.bind_attrib(self.attrib_texcoords, 3, np.array(texcoords, dtype=np.float32)) ret.bind_attrib(self.attrib_color, 3, np.array(text_color, dtype=np.uint8), datatype=gl.GL_UNSIGNED_BYTE, normalize=True, instance_divisor=1) ret.char_size = char_size ret.block_size = (len(text_string), 1) return ret
Example #4
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def create_font_array(self): # Load the first image to get font size img = QImage(os.path.join(settings.gfx_path, 'font/32.png')) imgsize = (img.width(), img.height()) self.char_ar = float(imgsize[1]) / imgsize[0] # Set-up the texture array self.tex_id = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.tex_id) gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], 127 - 30, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER) # We're using the ASCII range 32-126; space, uppercase, lower case, numbers, brackets, punctuation marks for i in range(30, 127): img = QImage(os.path.join(settings.gfx_path, 'font/%d.png' % i)).convertToFormat(QImage.Format_ARGB32) ptr = c_void_p(int(img.constBits())) gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i - 30, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)
Example #5
Source File: renderer.py From MCEdit-Unified with ISC License | 6 votes |
def drawFaceVertices(self, buf): if not len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(1) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(2.0) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(1.0) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
Example #6
Source File: renderer.py From MCEdit-Unified with ISC License | 6 votes |
def drawFaceVertices(self, buf): if not len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glDepthMask(False) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(2.0) GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) GL.glPolygonOffset(DepthOffset.TerrainWire, DepthOffset.TerrainWire) with gl.glEnable(GL.GL_POLYGON_OFFSET_FILL, GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glDepthMask(True)
Example #7
Source File: renderer.py From GDMC with ISC License | 6 votes |
def drawFaceVertices(self, buf): if 0 == len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glDepthMask(False) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(2.0) GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) GL.glPolygonOffset(DepthOffset.TerrainWire, DepthOffset.TerrainWire) with gl.glEnable(GL.GL_POLYGON_OFFSET_FILL, GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glDepthMask(True)
Example #8
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def create_font_array(self, path): # Load the first image to get font size img = QImage(path + '32.png') imgsize = (img.width(), img.height()) self.char_ar = float(imgsize[1]) / imgsize[0] # Set-up the texture array self.tex_id = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.tex_id) gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], 127 - 32, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER) # We're using the ASCII range 32-126; space, uppercase, lower case, numbers, brackets, punctuation marks for i in range(32, 127): img = QImage(path + '%d.png' % i).convertToFormat(QImage.Format_ARGB32) ptr = c_void_p(int(img.constBits())) gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i - 32, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)
Example #9
Source File: renderer.py From GDMC with ISC License | 6 votes |
def drawFaceVertices(self, buf): if 0 == len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(1) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(2.0) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(1.0) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
Example #10
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def prepare_text_string(self, text_string, char_size=16.0, text_color=(0.0, 1.0, 0.0), vertex_offset=(0.0, 0.0)): ret = RenderObject(gl.GL_TRIANGLES, vertex_count=6 * len(text_string)) vertices, texcoords = [], [] w, h = char_size, char_size * self.char_ar x, y = vertex_offset for i, c in enumerate(text_string): v, t = self.char(x + i * w, y, w, h, ord(c)) vertices += v texcoords += t ret.bind_attrib(self.attrib_vertex, 2, np.array(vertices, dtype=np.float32)) ret.bind_attrib(self.attrib_texcoords, 3, np.array(texcoords, dtype=np.float32)) ret.bind_attrib(self.attrib_color, 3, np.array(text_color, dtype=np.uint8), datatype=gl.GL_UNSIGNED_BYTE, normalize=True, instance_divisor=1) ret.char_size = char_size ret.block_size = (len(text_string), 1) return ret
Example #11
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 6 votes |
def prepare_text_instanced(self, text_array, textblock_size, origin_lat=None, origin_lon=None, text_color=None, char_size=16.0, vertex_offset=(0.0, 0.0)): ret = RenderObject(gl.GL_TRIANGLES, vertex_count=6) w, h = char_size, char_size * self.char_ar x, y = vertex_offset v, t = self.char(x, y, w, h) vertices = v texcoords = t ret.bind_attrib(self.attrib_vertex, 2, np.array(vertices, dtype=np.float32)) ret.bind_attrib(self.attrib_texcoords, 3, np.array(texcoords, dtype=np.float32)) ret.bind_attrib(self.attrib_texdepth, 1, text_array, instance_divisor=1, datatype=gl.GL_UNSIGNED_BYTE) divisor = textblock_size[0] * textblock_size[1] if origin_lat is not None: ret.bind_attrib(self.attrib_lat, 1, origin_lat, instance_divisor=divisor) if origin_lon is not None: ret.bind_attrib(self.attrib_lon, 1, origin_lon, instance_divisor=divisor) if text_color is not None: ret.bind_attrib(self.attrib_color, 4, text_color, datatype=gl.GL_UNSIGNED_BYTE, normalize=True, instance_divisor=divisor) ret.block_size = textblock_size ret.char_size = char_size return ret
Example #12
Source File: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def set_up_texture_maps(self): ts = pkg_resources.resource_stream('samples', 'cube_texture.png') image = Image.open(ts).convert('RGBA') width, height = image.size image_data = numpy.array(list(image.getdata()), numpy.uint8) self.i_texture = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, self.i_texture) GL.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, image_data, ) GL.glGenerateMipmap(GL.GL_TEXTURE_2D) 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.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR) f_largest = GL.glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, f_largest) GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
Example #13
Source File: tracked_devices_actor.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _try_load_texture(self): # Surface texture try: texture_map = openvr.VRRenderModels().loadTexture_Async(self.model.diffuseTextureId) except openvr.error_code.RenderModelError_Loading: return self.texture_map = texture_map self.diffuse_texture = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, self.diffuse_texture) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, self.texture_map.unWidth, self.texture_map.unHeight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.texture_map.rubTextureMapData) GL.glGenerateMipmap(GL.GL_TEXTURE_2D) 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.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR) fLargest = GL.glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT) GL.glTexParameterf(GL.GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) self.texture_is_loaded = True
Example #14
Source File: blipdriver.py From bluesky with GNU General Public License v3.0 | 6 votes |
def load_lcd_font(): files = sorted(glob('mcp_font/*.png')) img = QImage(files[0]) imgsize = (img.width(), img.height()) # Set-up the texture array tex_id = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, tex_id) gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], len(files), 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER) gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER) for i, fname in enumerate(files): img = QImage(fname).convertToFormat(QImage.Format_ARGB32) ptr = c_void_p(int(img.constBits())) gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr) return tex_id
Example #15
Source File: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, width, height): self.render_framebuffer_id = GL.glGenFramebuffers(1) GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.render_framebuffer_id) # self.depth_buffer_id = GL.glGenRenderbuffers(1) GL.glBindRenderbuffer(GL.GL_RENDERBUFFER, self.depth_buffer_id) GL.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, 4, GL.GL_DEPTH_COMPONENT, width, height) GL.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, self.depth_buffer_id) # self.render_texture_id = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D_MULTISAMPLE, self.render_texture_id) GL.glTexImage2DMultisample(GL.GL_TEXTURE_2D_MULTISAMPLE, 4, GL.GL_RGBA8, width, height, True) GL.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D_MULTISAMPLE, self.render_texture_id, 0) # self.resolve_framebuffer_id = GL.glGenFramebuffers(1) GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.resolve_framebuffer_id) # self.resolve_texture_id = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, self.resolve_texture_id) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_LEVEL, 0) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) GL.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, self.resolve_texture_id, 0) status = GL.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER) assert status == GL.GL_FRAMEBUFFER_COMPLETE
Example #16
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 5 votes |
def bind_color(self, data, storagetype=gl.GL_STATIC_DRAW, instance_divisor=0): # One colour for everything in a size 3/4 array? or an existing or new buffer if np.size(data) in [3, 4]: # Add full alpha if none is given self.single_colour = np.append(data, 255) if len(data) == 3 else data else: self.colorbuf = self.bind_attrib(self.attrib_color, 4, data, storagetype, instance_divisor, datatype=gl.GL_UNSIGNED_BYTE, normalize=True)
Example #17
Source File: platforms.py From gqn-dataset-renderer with MIT License | 5 votes |
def make_current(self): from OpenGL import GL as gl from OpenGL.osmesa import OSMesaMakeCurrent assert(OSMesaMakeCurrent( self._context, self._buffer, gl.GL_UNSIGNED_BYTE, self.viewport_width, self.viewport_height ))
Example #18
Source File: fullscreen_quad.py From dm_control with Apache License 2.0 | 5 votes |
def render(self, pixmap, viewport_shape): """Renders the pixmap on a fullscreen quad. Args: pixmap: A 3D numpy array of bytes (np.uint8), with dimensions (width, height, 3). viewport_shape: A tuple of two elements, (width, height). """ GL.glClear(GL.GL_COLOR_BUFFER_BIT) GL.glViewport(0, 0, *viewport_shape) GL.glUseProgram(self._shader) GL.glActiveTexture(GL.GL_TEXTURE0) GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture) GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, pixmap.shape[1], pixmap.shape[0], 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, pixmap) GL.glUniform1i(self._var_texture_sampler, 0) GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4)
Example #19
Source File: framebuffer.py From renpy-shader with MIT License | 5 votes |
def createEmptyTexture(self, width, height): textureId = (gl.GLuint * 1)() gl.glGenTextures(1, textureId) gl.glBindTexture(gl.GL_TEXTURE_2D, textureId[0]) 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.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) #None means reserve texture memory, but texels are undefined gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA8, width, height, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) return textureId[0]
Example #20
Source File: osmesa.py From pyrender with MIT License | 5 votes |
def make_current(self): from OpenGL import GL as gl from OpenGL.osmesa import OSMesaMakeCurrent assert(OSMesaMakeCurrent( self._context, self._buffer, gl.GL_UNSIGNED_BYTE, self.viewport_width, self.viewport_height ))
Example #21
Source File: renderer.py From MCEdit-Unified with ISC License | 5 votes |
def drawFaceVertices(self, buf): if not len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4)
Example #22
Source File: renderer.py From MCEdit-Unified with ISC License | 5 votes |
def drawFaceVertices(self, buf): if not len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glDepthMask(False) GL.glDisable(GL.GL_CULL_FACE) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glEnable(GL.GL_CULL_FACE) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(1.0) GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(2.0) with gl.glEnable(GL.GL_DEPTH_TEST): GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4) GL.glLineWidth(1.0) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) GL.glDepthMask(True)
Example #23
Source File: renderer.py From MCEdit-Unified with ISC License | 5 votes |
def makeFloorTex(): color0 = (0xff, 0xff, 0xff, 0x22) color1 = (0xff, 0xff, 0xff, 0x44) img = numpy.array([color0, color1, color1, color0], dtype='uint8') GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 2, 2, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, img)
Example #24
Source File: mceutils.py From MCEdit-Unified with ISC License | 5 votes |
def loadTextureFunc(w, h, ndata): GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ndata) return w, h
Example #25
Source File: widget.py From MCEdit-Unified with ISC License | 5 votes |
def gl_draw_all(self, root, offset): if not self.visible: return #from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
Example #26
Source File: glhelpers.py From bluesky with GNU General Public License v3.0 | 5 votes |
def load_texture(fname): img = QImage(fname) ptr = c_void_p(int(img.constBits())) tex_id = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, tex_id) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA8, img.width(), img.height(), 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr) gl.glGenerateMipmap(gl.GL_TEXTURE_2D) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) return tex_id
Example #27
Source File: texture.py From renpy-shader with MIT License | 5 votes |
def _load(self, surface): self.free() self.width = surface.get_width() self.height = surface.get_height() self.textureId = 0 textureId = (gl.GLuint * 1)() surface.lock() BYTEP = ctypes.POINTER(ctypes.c_ubyte) ptr = ctypes.cast(surface._pixels_address, BYTEP) gl.glGenTextures(1, textureId) gl.glEnable(gl.GL_TEXTURE_2D) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glPixelStorei(gl.GL_UNPACK_ROW_LENGTH, surface.get_pitch() // surface.get_bytesize()) gl.glBindTexture(gl.GL_TEXTURE_2D, textureId[0]) 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.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, self.width, self.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, ptr) gl.glBindTexture(gl.GL_TEXTURE_2D, 0); gl.glPixelStorei(gl.GL_UNPACK_ROW_LENGTH, 0) surface.unlock() self.textureId = textureId[0]
Example #28
Source File: controller.py From renpy-shader with MIT License | 5 votes |
def copyRenderBufferToSurface(self, surface): surface.lock() gl.glPixelStorei(gl.GL_PACK_ROW_LENGTH, surface.get_pitch() // surface.get_bytesize()) gl.glBindTexture(gl.GL_TEXTURE_2D, self.frameBuffer.texture) gl.glGetTexImage(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, surface._pixels_address) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) gl.glPixelStorei(gl.GL_PACK_ROW_LENGTH, 0) surface.unlock()
Example #29
Source File: opengl.py From pyimgui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def refresh_font_texture(self): # save texture state # last_texture = gl.glGetIntegerv(gl.GL_TEXTURE_BINDING_2D) width, height, pixels = self.io.fonts.get_tex_data_as_alpha8() if self._font_texture is not None: gl.glDeleteTextures([self._font_texture]) self._font_texture = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._font_texture) 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_ALPHA, width, height, 0, gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE, pixels) self.io.fonts.texture_id = self._font_texture # gl.glBindTexture(gl.GL_TEXTURE_2D, last_texture) self.io.fonts.clear_tex_data()
Example #30
Source File: renderer.py From GDMC with ISC License | 5 votes |
def drawFaceVertices(self, buf): if 0 == len(buf): return stride = elementByteLength GL.glVertexPointer(3, GL.GL_FLOAT, stride, (buf.ravel())) GL.glTexCoordPointer(2, GL.GL_FLOAT, stride, (buf.ravel()[3:])) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, stride, (buf.view(dtype=numpy.uint8).ravel()[20:])) GL.glDrawArrays(GL.GL_QUADS, 0, len(buf) * 4)