本文整理汇总了Python中pyglet.gl.glBindTexture函数的典型用法代码示例。如果您正苦于以下问题:Python glBindTexture函数的具体用法?Python glBindTexture怎么用?Python glBindTexture使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了glBindTexture函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, width, height, background=[255,255,255]):
self.width = width
self.height = height
self.triangles = []
self.batch = Batch()
self.bg_colour = background
has_fbo = gl.gl_info.have_extension('GL_EXT_framebuffer_object')
#setup a framebuffer
self.fb = gl.GLuint()
gl.glGenFramebuffersEXT(1, ctypes.byref(self.fb))
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, self.fb)
#allocate a texture for the fb to render to
tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA)
gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, tex.id, 0)
status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)
self.bg = self.batch.add( 6,
gl.GL_TRIANGLES,None,
("v2i/static", (0,0,0,height,width,height,width,height,width,0,0,0)),
("c3B/static",background*6)
)
示例2: create_texture
def create_texture(self, cls, rectangle=False, force_rectangle=False):
'''Create a texture containing this image.
If the image's dimensions are not powers of 2, a TextureRegion of
a larger Texture will be returned that matches the dimensions of this
image.
:Parameters:
`cls` : class (subclass of Texture)
Class to construct.
`rectangle` : bool
``True`` if a rectangle can be created; see
`AbstractImage.get_texture`.
:rtype: cls or cls.region_class
'''
_is_pow2 = lambda v: (v & (v - 1)) == 0
target = gl.GL_TEXTURE_2D
if rectangle and not (_is_pow2(self.width) and _is_pow2(self.height)):
if gl.gl_info.have_extension('GL_ARB_texture_rectangle'):
target = gl.GL_TEXTURE_RECTANGLE_ARB
elif gl.gl_info.have_extension('GL_NV_texture_rectangle'):
target = gl.GL_TEXTURE_RECTANGLE_NV
texture = cls.create_for_size(target, self.width, self.height)
subimage = False
if texture.width != self.width or texture.height != self.height:
texture = texture.get_region(0, 0, self.width, self.height)
subimage = True
internalformat = self._get_internalformat(self.format)
gl.glBindTexture(texture.target, texture.id)
gl.glTexParameteri(texture.target, gl.GL_TEXTURE_WRAP_S,
gl.GL_CLAMP_TO_EDGE)
gl.glTexParameteri(texture.target, gl.GL_TEXTURE_WRAP_T,
gl.GL_CLAMP_TO_EDGE)
gl.glTexParameteri(texture.target, gl.GL_TEXTURE_MAG_FILTER,
gl.GL_LINEAR)
gl.glTexParameteri(texture.target, gl.GL_TEXTURE_MIN_FILTER,
gl.GL_LINEAR)
if subimage:
width = texture.owner.width
height = texture.owner.height
blank = (ctypes.c_ubyte * (width * height * 4))()
gl.glTexImage2D(texture.target, texture.level,
internalformat,
width, height,
1,
gl.GL_RGBA, gl.GL_UNSIGNED_BYTE,
blank)
internalformat = None
self.blit_to_texture(texture.target, texture.level,
0, 0, 0, internalformat)
return texture
示例3: buffer_texture
def buffer_texture(width, height):
id_ = gl.GLuint()
gl.glGenTextures(1, byref(id_))
gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TEXTURE_BIT)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glEnable(gl.GL_TEXTURE_2D)
gl.glBindTexture(gl.GL_TEXTURE_2D, id_)
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,
(gl.GLubyte * (width*height * 4))(),
)
gl.glFlush()
gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
gl.glPopAttrib()
return id_
示例4: draw
def draw(self):
if self._dirty:
self._context = Context()
self._parts = []
self.free()
self.render()
self.build_vbo()
self._dirty = False
# set
gl.glEnable(self._texture.target)
gl.glBindTexture(self._texture.target, self._texture.id)
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.glPushMatrix()
self.transform()
# cuadric.begin()
self._vertex_list.draw(gl.GL_TRIANGLES)
# cuadric.end()
# unset
gl.glPopMatrix()
gl.glPopAttrib()
gl.glDisable(self._texture.target)
示例5: set_state
def set_state(self):
gl.glBindTexture( gl.GL_TEXTURE_CUBE_MAP, self.tex_object )
gl.glTexGeni( gl.GL_S, gl.GL_TEXTURE_GEN_MODE, gl.GL_REFLECTION_MAP )
gl.glTexGeni( gl.GL_T, gl.GL_TEXTURE_GEN_MODE, gl.GL_REFLECTION_MAP )
gl.glTexGeni( gl.GL_R, gl.GL_TEXTURE_GEN_MODE, gl.GL_REFLECTION_MAP )
gl.glEnable( gl.GL_TEXTURE_CUBE_MAP )
gl.glTexEnvi( gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_DECAL )
示例6: upload
def upload(self):
'''
Upload atlas data into video memory.
'''
glEnable( GL_TEXTURE_2D )
if self.texid is None:
self.texid = GLuint(0)
glGenTextures(1,ctypes.byref(self.texid))
glBindTexture( GL_TEXTURE_2D, self.texid )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_CLAMP )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_CLAMP )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR )
if self.depth == 1:
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA,
self.width, self.height, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, self.data.ctypes )
elif self.depth == 3:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
self.width, self.height, 0,
GL_RGB, GL_UNSIGNED_BYTE, self.data.ctypes )
else:
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
self.width, self.height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, self.data.ctypes )
glBindTexture( GL_TEXTURE_2D, 0 )
示例7: set_state
def set_state(self):
gl.glPushMatrix()
gl.glMultMatrixf(rendering.matrix_to_gl(self.transform))
if self.texture:
gl.glEnable(self.texture.target)
gl.glBindTexture(self.texture.target, self.texture.id)
示例8: texture_from_data
def texture_from_data(internalformat, size, data_format, data_type, data):
'''Create texture from a data buffer (whatever can be passed as pointer to ctypes)
internalformat - GL_RGBA8 or GL_RGB8 recommended
size - a 1-, 2- or 3-tuple describing the image sizes
data_format - see 'format' parameter of glDrawPixels
data_type - see 'type' parameter of glDrawPixels
data - pointer to memory'''
size = list(size)
dimensions = len(size)
binding = getattr(gl, 'GL_TEXTURE_BINDING_{0:d}D'.format(dimensions))
target = getattr(gl,'GL_TEXTURE_{0:d}D'.format(dimensions))
texImage = getattr(gl,'glTexImage{0:d}D'.format(dimensions))
oldbind = ctypes.c_uint(0)
gl.glGetIntegerv(binding, ctypes.cast(ctypes.byref(oldbind), ctypes.POINTER(ctypes.c_int)))
texid = ctypes.c_uint(0)
gl.glEnable(target)
gl.glGenTextures(1, ctypes.byref(texid))
gl.glBindTexture(target, texid)
gl.glTexParameteri(target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
gl.glTexParameteri(target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
args = [target, 0, internalformat] + size + [0, data_format, data_type, data]
texImage(*args)
gl.glBindTexture(target, oldbind)
return texid
示例9: get_blocky_image
def get_blocky_image(name):
import pyglet.gl as gl
image = pyglet.resource.image(name)
gl.glBindTexture(image.target, image.id)
gl.glTexParameteri(image.target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
gl.glTexParameteri(image.target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
return image
示例10: from_atlas
def from_atlas(cls, name, firstgid, file, tile_width, tile_height):
image = pyglet.image.load(file)
rows = image.height // tile_height
columns = image.width // tile_width
image_grid = pyglet.image.ImageGrid(image, rows, columns)
atlas = pyglet.image.TextureGrid(image_grid)
id = firstgid
ts = cls(name, {})
ts.firstgid = firstgid
for j in range(rows-1, -1, -1):
for i in range(columns):
tile_image = image.get_region(atlas[j, i].x,
atlas[j, i].y,
atlas[j, i].width,
atlas[j, i].height)
# Set texture clamping to avoid mis-rendering subpixel edges
gl.glBindTexture(tile_image.texture.target, id)
gl.glTexParameteri(tile_image.texture.target,
gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
gl.glTexParameteri(tile_image.texture.target,
gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
ts[id] = Tile(id, {}, tile_image)
id += 1
return ts
示例11: set_data
def set_data(self, arr):
arr = np.asarray(arr)
self.src_format, self.dst_format = fmts_from_shape(arr.shape,
self._texture_dim)
# Float is default type
if arr.dtype == np.uint8:
arr = np.ascontiguousarray(arr)
self.src_type = gl.GL_UNSIGNED_BYTE
elif arr.dtype == np.float32:
arr = np.ascontiguousarray(arr)
self.src_type = gl.GL_FLOAT
else:
arr = np.astype(np.float32)
self.src_type = gl.GL_FLOAT
self._arr = arr
if self._id:
gl.glDeleteTextures(1, gl.byref(self._id))
id = gl.GLuint()
gl.glGenTextures(1, gl.byref(id))
self._id = id
gl.glPixelStorei (gl.GL_UNPACK_ALIGNMENT, 1)
gl.glPixelStorei (gl.GL_PACK_ALIGNMENT, 1)
gl.glBindTexture (self.target, self._id)
gl.glTexParameterf (self.target,
gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
gl.glTexParameterf (self.target,
gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
gl.glTexParameterf (self.target, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
gl.glTexParameterf (self.target, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
self._setup_tex()
self.update()
示例12: poll
def poll(dt):
out = next(itr, False)
if out is False:
if args.pause:
label.text = "Done. ('q' to quit)"
else:
pyglet.app.exit()
elif out is not None:
name, buf = out
real_dt = time.time() - last_time[0]
last_time[0] = time.time()
if buf.dtype == np.uint8:
fmt = gl.GL_UNSIGNED_BYTE
elif buf.dtype == np.uint16:
fmt = gl.GL_UNSIGNED_SHORT
else:
label.text = 'Unsupported format: ' + buf.dtype
return
h, w, ch = buf.shape
gl.glEnable(tex.target)
gl.glBindTexture(tex.target, tex.id)
gl.glTexImage2D(tex.target, 0, gl.GL_RGB8, w, h, 0, gl.GL_RGBA,
fmt, buf.tostring())
gl.glDisable(tex.target)
label.text = '%s (%g fps)' % (name, 1./real_dt)
else:
label.text += '.'
示例13: __init__
def __init__(self, width, height, scale=2):
"""
width, height:
size of the window in pixels.
scale:
the size of the texture is (width//scale) x (height//scale).
"""
pyglet.window.Window.__init__(self, width, height, caption='GrayScott Simulation',
visible=False, vsync=False)
self.reaction_shader = Shader('./glsl/default.vert', './glsl/reaction.frag')
self.render_shader = Shader('./glsl/default.vert', './glsl/render.frag')
self.pattern = DEFAULT_PATTERN
self.palette = DEFAULT_PALETTE
self.tex_width = width // scale
self.tex_height = height // scale
self.uv_texture = create_uv_texture(width//scale, height//scale)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(self.uv_texture.target, self.uv_texture.id)
# use an invisible buffer to do the computation.
with FrameBuffer() as self.fbo:
self.fbo.attach_texture(self.uv_texture)
# why do we need this? the reason is in the 'on_mouse_drag' function.
self.mouse_down = False
# put all patterns in a list for iterating over them.
self._species = list(SPECIES.keys())
# set the uniforms and attributes in the two shaders.
self.init_reaction_shader()
self.init_render_shader()
示例14: _drawLUTtoScreen
def _drawLUTtoScreen(self):
"""(private) Used to set the LUT in Bits++ mode.
Should not be needed by user if attached to a ``psychopy.visual.Window()``
since this will automatically draw the LUT as part of the screen refresh.
"""
#push the projection matrix and set to orthorgaphic
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPushMatrix()
GL.glLoadIdentity()
GL.glOrtho( 0, self.win.size[0],self.win.size[1], 0, 0, 1 ) #this also sets the 0,0 to be top-left
#but return to modelview for rendering
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
#draw the pixels
GL.glActiveTextureARB(GL.GL_TEXTURE0_ARB)
GL.glEnable(GL.GL_TEXTURE_2D)
GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
GL.glActiveTextureARB(GL.GL_TEXTURE1_ARB)
GL.glEnable(GL.GL_TEXTURE_2D)
GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
GL.glRasterPos2i(0,1)
GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
GL.glDrawPixels(len(self._HEADandLUT),1,
GL.GL_RGB,GL.GL_UNSIGNED_BYTE,
self._HEADandLUTstr)
#GL.glDrawPixels(524,1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, self._HEADandLUTstr)
#return to 3D mode (go and pop the projection matrix)
GL.glMatrixMode( GL.GL_PROJECTION )
GL.glPopMatrix()
GL.glMatrixMode( GL.GL_MODELVIEW )
示例15: draw
def draw(self):
'''
Draw the windows.
'''
self.program.use()
data = list(self.root.get_data(0, 0))
data = (gl.GLfloat * len(data))(*data)
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.buffer)
gl.glBufferData(gl.GL_ARRAY_BUFFER, sizeof(data), data, gl.GL_DYNAMIC_DRAW)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture)
if self.textmanager.dirty:
# only upload the texture to the GPU if it has actually changed
gl.glTexImage2D(gl.GL_TEXTURE_2D,
0, # level
gl.GL_R8,
self.textmanager.width,
self.textmanager.height,
0,
gl.GL_RED,
gl.GL_UNSIGNED_BYTE,
ctypes.create_string_buffer(self.textmanager.img.tobytes()))
self.textmanager.dirty = False
self.program.uniform1i(b"tex", 0) # set to 0 because the texture is bound to GL_TEXTURE0
self.program.vertex_attrib_pointer(self.buffer, b"position", 4)
# self.program.vertex_attrib_pointer(self.buffer, b"texcoord", 2, stride=4 * sizeof(gl.GLfloat), offset=2 * sizeof(gl.GLfloat))
gl.glDrawArrays(gl.GL_QUADS, 0, len(data) // 4)