本文整理汇总了Python中OpenGL.GL.GL_TEXTURE_2D属性的典型用法代码示例。如果您正苦于以下问题:Python GL.GL_TEXTURE_2D属性的具体用法?Python GL.GL_TEXTURE_2D怎么用?Python GL.GL_TEXTURE_2D使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类OpenGL.GL
的用法示例。
在下文中一共展示了GL.GL_TEXTURE_2D属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initgl
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def initgl(self):
"""Initialize OpenGL for use in the window."""
import OpenGL.GL as gl
import OpenGL.GLU as glu
self.load_textures()
gl.glEnable(gl.GL_TEXTURE_2D)
gl.glClearColor(*self.clear_color)
gl.glClearDepth(1.0)
gl.glDepthFunc(gl.GL_LESS)
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glShadeModel(gl.GL_SMOOTH)
gl.glMatrixMode(gl.GL_PROJECTION)
# Reset The projection matrix
gl.glLoadIdentity()
# Calculate aspect ratio of the window
(width, height) = self.canvas.GetClientSize()
glu.gluPerspective(45.0, float(width) / float(height), 0.1, 100.0)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (0.5, 0.5, 0.5, 1.0))
gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (0.0, 0.0, 2.0, 1.0))
gl.glEnable(gl.GL_LIGHT0)
示例2: drawSelf
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def drawSelf(self):
if self._tex is None:
filename = os.path.join("toolicons", "compass.png")
self._tex = loadPNGTexture(filename)
self._tex.bind()
size = 0.001 * config.settings.compassSize.get()
with gl.glPushMatrix(GL.GL_MODELVIEW):
GL.glLoadIdentity()
yaw, pitch = self.yawPitch
if config.settings.viewMode.get() == "Chunk":
yaw = -180
GL.glTranslatef(1. - (size + self.x), size + self.y, 0.0) # position on upper right corner
GL.glRotatef(180 - yaw, 0., 0., 1.) # adjust to north
GL.glColor3f(1., 1., 1.)
with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2 * size, 2 * size))
GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256))
with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D):
GL.glDrawArrays(GL.GL_QUADS, 0, 4)
示例3: __init__
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def __init__(self, textureFunc=None, minFilter=None, magFilter=None):
minFilter = minFilter or self.defaultFilter
magFilter = magFilter or self.defaultFilter
if textureFunc is None:
textureFunc = lambda: None
self.textureFunc = textureFunc
self._texID = GL.glGenTextures(1)
def _delete(r):
Texture.allTextures.remove(r)
self.allTextures.append(weakref.ref(self, _delete))
self.bind()
GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter)
GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter)
self.textureFunc()
示例4: gl_draw
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def gl_draw(self):
if self.schematic.chunkCount > len(self.renderer.chunkRenderers):
self.gl_draw_thumb()
else:
if self.fbo is None:
w, h = self.fboSize
self.fbo = FramebufferTexture(w, h, self.gl_draw_tex)
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)
GL.glColor(1.0, 1.0, 1.0, 1.0)
GL.glVertexPointer(2, GL.GL_FLOAT, 0, array([-1, -1,
- 1, 1,
1, 1,
1, -1, ], dtype='float32'))
GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, array([0, 0, 0, 256, 256, 256, 256, 0], dtype='float32'))
e = (GL.GL_TEXTURE_2D,)
if not self.drawBackground:
e += (GL.GL_ALPHA_TEST,)
with gl.glEnable(*e):
self.fbo.bind()
GL.glDrawArrays(GL.GL_QUADS, 0, 4)
GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
示例5: render
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [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)
示例6: render_companion_window
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def render_companion_window(self):
GL.glDisable(GL.GL_DEPTH_TEST)
GL.glViewport(0, 0, self.companion_width, self.companion_height)
GL.glBindVertexArray(self.companion_window_vao)
GL.glUseProgram(self.companion_window_program)
# render left eye (first half of index array)
i_size = sizeof(c_uint16)
count = int(self.companion_window_index_size / 2)
GL.glBindTexture(GL.GL_TEXTURE_2D, self.left_eye_desc.resolve_texture_id)
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.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(0 * i_size, c_void_p))
# render right eye (second half of index array)
GL.glBindTexture(GL.GL_TEXTURE_2D, self.right_eye_desc.resolve_texture_id)
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.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(count * i_size, c_void_p))
GL.glBindVertexArray(0)
GL.glUseProgram(0)
示例7: set_up_texture_maps
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [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)
示例8: createEmptyTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [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]
示例9: createFrameBuffer
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def createFrameBuffer(self, texture, depthBuffer):
bufferId = (gl.GLuint * 1)()
gl.glGenFramebuffers(1, bufferId);
gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, bufferId[0])
gl.glFramebufferTexture2D(gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT0, gl.GL_TEXTURE_2D, texture, 0)
if depthBuffer:
gl.glFramebufferRenderbuffer(gl.GL_FRAMEBUFFER, gl.GL_DEPTH_ATTACHMENT, gl.GL_RENDERBUFFER, depthBuffer);
gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)
return bufferId[0]
示例10: bind
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def bind(self):
GL.glBindTexture(GL.GL_TEXTURE_2D, self._texID)
示例11: _init_texture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def _init_texture(self):
"""Initializes the texture storage."""
self._texture = GL.glGenTextures(1)
GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture)
GL.glTexParameteri(
GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)
GL.glTexParameteri(
GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)
示例12: draw
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def draw(self):
GL.glBindVertexArray(self.vertex_array)
GL.glActiveTexture(GL.GL_TEXTURE0)
GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)
GL.glDrawElements(GL.GL_TRIANGLES, self.vertex_count, GL.GL_UNSIGNED_SHORT, None)
GL.glBindVertexArray(0)
示例13: render_scene
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def render_scene(self, eye):
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
GL.glEnable(GL.GL_DEPTH_TEST)
if self.show_cubes:
GL.glUseProgram(self.scene_program)
GL.glUniformMatrix4fv(
self.scene_matrix_location, 1, False,
self.get_current_view_projection_matrix(eye))
GL.glBindVertexArray(self.scene_vao)
GL.glBindTexture(GL.GL_TEXTURE_2D, self.i_texture)
GL.glDrawArrays(GL.GL_TRIANGLES, 0, int(self.vert_count))
GL.glBindVertexArray(0)
b_is_input_available = self.hmd.isInputAvailable()
if b_is_input_available:
# draw the controller axis lines
GL.glUseProgram(self.controller_transform_program)
GL.glUniformMatrix4fv(self.controller_matrix_location, 1, False, self.get_current_view_projection_matrix(eye))
GL.glBindVertexArray(self.controller_vao)
GL.glDrawArrays(GL.GL_LINES, 0, self.controller_vertex_count)
GL.glBindVertexArray(0)
# ----- Render Model rendering -----
GL.glUseProgram(self.render_model_program)
for hand in self.hand:
if not hand.show_controller:
continue
if hand.render_model is None:
continue
mvp = hand.pose @ self.get_current_view_projection_matrix(eye)
GL.glUniformMatrix4fv(self.render_model_matrix_location, 1, False, mvp)
hand.render_model.draw()
GL.glUseProgram(0)
示例14: genSixteenBlockTexture
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [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)
示例15: loadTextures
# 需要导入模块: from OpenGL import GL [as 别名]
# 或者: from OpenGL.GL import GL_TEXTURE_2D [as 别名]
def loadTextures(self):
self.terrainTextures = {}
def makeTerrainTexture(mats):
w, h = 1, 1
teximage = numpy.zeros((w, h, 4), dtype='uint8')
teximage[:] = 127, 127, 127, 255
GL.glTexImage2D(
GL.GL_TEXTURE_2D,
0,
GL.GL_RGBA8,
w,
h,
0,
GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE,
teximage
)
textures = (
(pymclevel.classicMaterials, 'terrain-classic.png'),
(pymclevel.indevMaterials, 'terrain-classic.png'),
(pymclevel.alphaMaterials, ResourcePackHandler.Instance().get_selected_resource_pack().terrain_path()),
(pymclevel.pocketMaterials, 'terrain-pocket.png')
)
for mats, matFile in textures:
try:
if mats.name == 'Alpha':
tex = mceutils.loadAlphaTerrainTexture()
else:
tex = mceutils.loadPNGTexture(matFile)
self.terrainTextures[mats.name] = tex
except Exception, e:
logging.warning(
'Unable to load terrain from {0}, using flat colors.'
'Error was: {1!r}'.format(matFile, e)
)
self.terrainTextures[mats.name] = glutils.Texture(
functools.partial(makeTerrainTexture, mats)
)
mats.terrainTexture = self.terrainTextures[mats.name]