本文整理汇总了Python中OpenGL.GL.GL_UNSIGNED_BYTE属性的典型用法代码示例。如果您正苦于以下问题:Python GL.GL_UNSIGNED_BYTE属性的具体用法?Python GL.GL_UNSIGNED_BYTE怎么用?Python GL.GL_UNSIGNED_BYTE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.GL_UNSIGNED_BYTE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_font_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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()
示例2: drawFaceVertices
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例3: create_font_array
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例4: prepare_text_string
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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
示例5: prepare_text_instanced
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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
示例6: create_font_array
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例7: load_lcd_font
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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
示例8: render
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例9: _try_load_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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
示例10: set_up_texture_maps
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例11: drawFaceVertices
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)
示例12: _load
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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]
示例13: createEmptyTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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]
示例14: copyRenderBufferToSurface
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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()
示例15: makeFloorTex
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_UNSIGNED_BYTE [as 别名]
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)