本文整理汇总了Python中OpenGL.GL.glTexImage2D方法的典型用法代码示例。如果您正苦于以下问题:Python GL.glTexImage2D方法的具体用法?Python GL.glTexImage2D怎么用?Python GL.glTexImage2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.glTexImage2D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_font_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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: render
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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)
示例3: _try_load_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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 glTexImage2D [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 glTexImage2D [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: createEmptyTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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]
示例7: makeFloorTex
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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)
示例8: loadTextureFunc
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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
示例9: blockTexFunc
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [as 别名]
def blockTexFunc(self, terrainTexture, tex):
def _func():
s, t = tex
if not hasattr(terrainTexture, "data"):
return
w, h = terrainTexture.data.shape[:2]
pixelWidth = 512 if self.editor.level.materials.name in ("Pocket", "Alpha") else 256
s = s * w / pixelWidth
t = t * h / pixelWidth
texData = numpy.array(terrainTexture.data[t:t + h / 32, s:s + w / 32])
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w / 32, h / 32, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
texData)
return _func
示例10: assign
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [as 别名]
def assign(self, array):
gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, self.id_)
if array.dtype == np.uint8:
gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, self.internalFormat_, self.width_, self.height_, 0, self.format,
gl.GL_UNSIGNED_BYTE, array)
elif array.dtype == np.float32:
gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, self.internalFormat_, self.width_, self.height_, 0, self.format,
gl.GL_FLOAT, array)
else:
raise NotImplementedError("pixel type not implemented.")
gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, 0)
示例11: load_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [as 别名]
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
示例12: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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: genSixteenBlockTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [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)
示例14: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [as 别名]
def __init__(self, width, height, drawFunc):
tex = GL.glGenTextures(1)
GL.glBindTexture(GL.GL_TEXTURE_2D, tex)
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_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None)
self.enabled = False
self._texID = tex
if bool(FBO.glGenFramebuffers) and "Intel" not in GL.glGetString(GL.GL_VENDOR):
buf = FBO.glGenFramebuffers(1)
depthbuffer = FBO.glGenRenderbuffers(1)
FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf)
FBO.glBindRenderbuffer(FBO.GL_RENDERBUFFER, depthbuffer)
FBO.glRenderbufferStorage(FBO.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT, width, height)
FBO.glFramebufferRenderbuffer(FBO.GL_FRAMEBUFFER, FBO.GL_DEPTH_ATTACHMENT, FBO.GL_RENDERBUFFER, depthbuffer)
FBO.glFramebufferTexture2D(FBO.GL_FRAMEBUFFER, FBO.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, tex, 0)
status = FBO.glCheckFramebufferStatus(FBO.GL_FRAMEBUFFER)
if status != FBO.GL_FRAMEBUFFER_COMPLETE:
print "glCheckFramebufferStatus", status
self.enabled = False
return
FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf)
with gl.glPushAttrib(GL.GL_VIEWPORT_BIT):
GL.glViewport(0, 0, width, height)
drawFunc()
FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, 0)
FBO.glDeleteFramebuffers(1, [buf])
FBO.glDeleteRenderbuffers(1, [depthbuffer])
self.enabled = True
else:
GL.glReadBuffer(GL.GL_BACK)
GL.glPushAttrib(
GL.GL_VIEWPORT_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_TEST | GL.GL_STENCIL_BUFFER_BIT)
GL.glDisable(GL.GL_STENCIL_TEST)
GL.glViewport(0, 0, width, height)
GL.glScissor(0, 0, width, height)
with gl.glEnable(GL.GL_SCISSOR_TEST):
drawFunc()
GL.glBindTexture(GL.GL_TEXTURE_2D, tex)
GL.glReadBuffer(GL.GL_BACK)
GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height)
GL.glPopAttrib()
示例15: fillTexture2d
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import glTexImage2D [as 别名]
def fillTexture2d(data,tex = None, interp=True):
""" data.shape == (Ny,Nx)
file texture with GL_RED
data.shape == (Ny,Nx,3)
file texture with GL_RGB
if tex == None, returns a new created texture
"""
if tex is None:
tex = GL.glGenTextures(1)
GL.glBindTexture(GL.GL_TEXTURE_2D, tex)
GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT,1)
GL.glTexParameterf (GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
GL.glTexParameterf (GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR if interp else GL.GL_NEAREST)
GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE)
GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE)
# GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP)
# GL.glTexParameterf (GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP)
if data.ndim == 2:
Ny,Nx = data.shape
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, Nx, Ny,
0, GL.GL_RED, GL.GL_FLOAT, data.astype(np.float32))
elif data.ndim == 3 and data.shape[2]==3:
Ny,Nx = data.shape[:2]
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, Nx, Ny,
0, GL.GL_RGB, GL.GL_FLOAT, data.astype(np.float32))
elif data.ndim == 3 and data.shape[2]==4:
Ny,Nx = data.shape[:2]
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, Nx, Ny,
0, GL.GL_RGBA, GL.GL_FLOAT, data.astype(np.float32))
else:
raise Exception("data format not supported! \ndata.shape should be either (Ny,Nx) or (Ny,Nx,3)")
return tex