本文整理汇总了Python中OpenGL.GL.GL_RGBA属性的典型用法代码示例。如果您正苦于以下问题:Python GL.GL_RGBA属性的具体用法?Python GL.GL_RGBA怎么用?Python GL.GL_RGBA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.GL_RGBA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_fbo_color_rgba32f
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
def read_fbo_color_rgba32f(fbo):
"""
Read the color attachment from a FBO, assuming it is GL_RGBA_32F.
# Ref: https://github.com/julienr/vertex_visibility/blob/master/depth.py
"""
h, w = fbo.color_buffer.shape[:2]
x, y = 0, 0
im = gl.glReadPixels(x, y, w, h, gl.GL_RGBA, gl.GL_FLOAT)
im = np.frombuffer(im, np.float32)
im.shape = h, w, 4
im = im[::-1, :]
return im
#-------------------------------------------------------------------------------
# Ref: https://github.com/vispy/vispy/blob/master/examples/demo/gloo/offscreen.py
示例2: refresh_font_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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()
示例3: _try_load_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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
示例4: set_up_texture_maps
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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)
示例5: _load
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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]
示例6: copyRenderBufferToSurface
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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()
示例7: draw_depth
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
def draw_depth(self):
program = gloo.Program(_depth_vertex_code, _depth_fragment_code)
program.bind(self.vertex_buffer)
program['u_mv'] = _compute_model_view(self.mat_model, self.mat_view)
program['u_mvp'] = _compute_model_view_proj(self.mat_model, self.mat_view, self.mat_proj)
# Texture where we render the scene
render_tex = gloo.Texture2D(shape=self.shape + (4,), format=gl.GL_RGBA,
internalformat=gl.GL_RGBA32F)
# Frame buffer object
fbo = gloo.FrameBuffer(render_tex, gloo.RenderBuffer(self.shape, format='depth'))
with fbo:
gloo.set_state(depth_test=True)
gloo.set_state(cull_face=True)
gloo.set_cull_face('back') # Back-facing polygons will be culled
gloo.set_clear_color((0.0, 0.0, 0.0, 0.0))
gloo.clear(color=True, depth=True)
gloo.set_viewport(0, 0, *self.size)
program.draw('triangles', self.index_buffer)
# Retrieve the contents of the FBO texture
self.depth = self.read_fbo_color_rgba32f(fbo)
self.depth = self.depth[:, :, 0] # Depth is saved in the first channel
fbo.delete()
render_tex.delete()
program.delete()
示例8: makeFloorTex
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [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)
示例9: loadTextureFunc
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
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
示例10: gl_draw_all
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
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 Exception:
#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()
示例11: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
def __init__(self, width, height, internalFormat=gl.GL_RGBA, format=gl.GL_RGBA):
self.id_ = gl.glGenTextures(1)
self.internalFormat_ = internalFormat # gl.GL_RGB_FLOAT, gl.GL_RGB_UNSIGNED, ...
self.format = format # GL_RG. GL_RG_INTEGER, ...
self.width_ = width
self.height_ = height
gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, self.id_)
gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER)
gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER)
gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, 0)
示例12: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
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
示例13: gl_draw_all
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
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()
示例14: get_points_in_selection_box
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
def get_points_in_selection_box(self, **kwargs):
'''Returns pixel IDs of all points in the current selection box.
KEYWORD ARGS:
`indices` (ndarray of ints):
An alternate set of N-D image pixels to display.
Pixels are identified by performing a background rendering loop wherein
each pixel is rendered with a unique color. Then, glReadPixels is used
to read colors of pixels in the current selection box.
'''
import OpenGL.GL as gl
indices = kwargs.get('indices', None)
point_size_temp = self.point_size
self.point_size = kwargs.get('point_size', 1)
xsize = self._selection_box[2] - self._selection_box[0] + 1
ysize = self._selection_box[3] - self._selection_box[1] + 1
ids = np.zeros(xsize * ysize, int)
self.create_display_lists(0, indices=indices)
self.render_rgb_indexed_colors()
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
pixels = gl.glReadPixelsub(self._selection_box[0],
self._selection_box[1],
xsize, ysize, gl.GL_RGBA)
pixels = np.frombuffer(pixels, dtype=np.uint8).reshape((ysize, xsize, 4))
for i in range(4):
component = pixels[:, :, i].reshape((xsize * ysize,)) \
& self._rgba_masks[i]
shift = (sum(self._rgba_bits[0:i]) - self._low_bits[i])
if shift > 0:
ids += component.astype(int) << shift
else:
ids += component.astype(int) >> (-shift)
points = ids[ids > 0]
self.point_size = point_size_temp
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
self._refresh_display_lists = True
return points
示例15: genSixteenBlockTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_RGBA [as 别名]
def genSixteenBlockTexture():
has12 = GL.glGetString(GL.GL_VERSION) >= "1.2"
if has12:
maxLevel = 2
mode = GL.GL_LINEAR_MIPMAP_NEAREST
else:
maxLevel = 1
mode = GL.GL_LINEAR
def makeSixteenBlockTex():
darkColor = (0x30, 0x30, 0x30, 0xff)
lightColor = (0x80, 0x80, 0x80, 0xff)
w, h, = 256, 256
teximage = numpy.zeros((w, h, 4), dtype='uint8')
teximage[:] = 0xff
teximage[:, ::16] = lightColor
teximage[::16, :] = lightColor
teximage[:2] = darkColor
teximage[-1:] = darkColor
teximage[:, -1:] = darkColor
teximage[:, :2] = darkColor
# GL.glTexParameter(GL.GL_TEXTURE_2D,
# GL.GL_TEXTURE_MIN_FILTER,
# GL.GL_NEAREST_MIPMAP_NEAREST),
GL.glTexParameter(GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAX_LEVEL,
maxLevel - 1)
for lev in range(maxLevel):
step = 1 << lev
if lev:
teximage[::16] = 0xff
teximage[:, ::16] = 0xff
teximage[:2] = darkColor
teximage[-1:] = darkColor
teximage[:, -1:] = darkColor
teximage[:, :2] = darkColor
GL.glTexImage2D(GL.GL_TEXTURE_2D, lev, GL.GL_RGBA8,
w / step, h / step, 0,
GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
teximage[::step, ::step].ravel())
return Texture(makeSixteenBlockTex, mode)