本文整理汇总了Python中pyglet.gl方法的典型用法代码示例。如果您正苦于以下问题:Python pyglet.gl方法的具体用法?Python pyglet.gl怎么用?Python pyglet.gl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet
的用法示例。
在下文中一共展示了pyglet.gl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw(self):
gl.glClearColor(0, 0, 0, 0)
self.clear()
gl.glViewport(0, 0, self.width, self.height)
now = time.clock() - self._start_time
now *= self._speed
with self.bufferA:
with self.shaderA:
self.shaderA.uniformf("iTime", now)
self.shaderA.uniformi("iFrame", self._frame_count)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
with self.bufferB:
with self.shaderB:
self.shaderB.uniformf("iTime", now)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
with self.shaderC:
self.shaderC.uniformf("iTime", now)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
self._frame_count += 1
示例2: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw(self):
gl.glClearColor(0, 0, 0, 0)
self.clear()
gl.glViewport(0, 0, self.width, self.height)
self._last = self._now
self._now = time.clock()
itime = self._now - self._start_time
idate = get_idate()
delta = self._now - self._last
with self.bufferA:
with self.shaderA:
self.shaderA.uniformf("iTime", itime)
self.shaderA.uniformf("iDate", *idate)
self.shaderA.uniformf("iTimeDelta", delta)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
with self.shaderB:
self.shaderB.uniformf("iTime", itime)
self.shaderB.uniformf("iDate", *idate)
self.shaderB.uniformf("iTimeDelta", delta)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
self._frame_count += 1
示例3: __init__
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def __init__(self, width, height, aa):
pyglet.window.Window.__init__(self,
width,
height,
caption="Loxodromic transformation",
resizable=True,
visible=False,
vsync=False)
self._start_time = time.clock()
self.shader = Shader(["./glsl/loxodrome.vert"], ["./glsl/loxodrome.frag"])
self.buffer = pyglet.image.get_buffer_manager().get_color_buffer()
texture = create_image_texture(WOOD_TEXTURE)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
with self.shader:
self.shader.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
self.shader.uniformf("iResolution", width, height, 0.0)
self.shader.uniformf("iTime", 0.0)
self.shader.uniformi("iTexture", 0)
self.shader.uniformi("AA", aa)
示例4: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw(self):
gl.glClearColor(0.0, 0.0, 0.0, 0.0)
self.clear()
if time.time() - self.start_time > 0.1:
gl.glViewport(0, 0, self.tex_width, self.tex_height)
with self.fbo:
with self.reaction_shader:
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
gl.glViewport(0, 0, self.width, self.height)
with self.render_shader:
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
self.frame_count += 1
if self.video_on and (self.frame_count % self.sample_rate == 0):
self.write_video_frame()
示例5: create_image_texture
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def create_image_texture(imgfile):
"""Create a 2D texture from an image file.
"""
image = pyglet.image.load(imgfile)
data = image.get_data("RGBA", image.width * 4)
tex = gl.GLuint()
gl.glGenTextures(1, ct.pointer(tex))
gl.glBindTexture(gl.GL_TEXTURE_2D, tex)
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.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.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA,
image.width, image.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data)
gl.glBindTexture(tex, 0)
return tex
示例6: __init__
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def __init__(self, size, target, usage):
self.size = size
self.target = target
self.usage = usage
self._context = pyglet.gl.current_context
id = GLuint()
glGenBuffers(1, id)
self.id = id.value
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
glBindBuffer(target, self.id)
glBufferData(target, self.size, None, self.usage)
glPopClientAttrib()
global _workaround_vbo_finish
if pyglet.gl.current_context._workaround_vbo_finish:
_workaround_vbo_finish = True
示例7: __call__
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def __call__(self, *args, **kwargs):
if self.func:
return self.func(*args, **kwargs)
from pyglet.gl import current_context
if not current_context:
raise Exception(
'Call to function "%s" before GL context created' % self.name)
address = wglGetProcAddress(self.name)
if cast(address, POINTER(c_int)): # check cast because address is func
self.func = cast(address, self.ftype)
decorate_function(self.func, self.name)
else:
self.func = missing_function(
self.name, self.requires, self.suggestions)
result = self.func(*args, **kwargs)
return result
示例8: on_resize
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_resize(self, width, height):
'''A default resize event handler.
This default handler updates the GL viewport to cover the entire
window and sets the ``GL_PROJECTION`` matrix to be orthogonal in
window space. The bottom-left corner is (0, 0) and the top-right
corner is the width and height of the window in pixels.
Override this event handler with your own to create another
projection, for example in perspective.
'''
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -1, 1)
gl.glMatrixMode(gl.GL_MODELVIEW)
示例9: __init__
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def __init__(self, screen, attrib_list):
self.screen = screen
self._display = screen.display._display
self._visual_info = glx.glXChooseVisual(self._display,
screen._x_screen_id, attrib_list)
if not self._visual_info:
raise gl.ContextException('No conforming visual exists')
for name, attr in self.attribute_ids.items():
value = c_int()
result = glx.glXGetConfig(self._display,
self._visual_info, attr, byref(value))
if result >= 0:
setattr(self, name, value.value)
self.sample_buffers = 0
self.samples = 0
示例10: _init_texture
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def _init_texture(self, player):
if not self.video_format:
return
width = self.video_format.width
height = self.video_format.height
if gl_info.have_extension('GL_ARB_texture_rectangle'):
texture = image.Texture.create_for_size(
gl.GL_TEXTURE_RECTANGLE_ARB, width, height,
internalformat=gl.GL_RGB)
else:
texture = image.Texture.create_for_size(
gl.GL_TEXTURE_2D, width, height, internalformat=gl.GL_RGB)
if texture.width != width or texture.height != height:
texture = texture.get_region(0, 0, width, height)
player._texture = texture
# Flip texture coords (good enough for simple apps).
t = list(player._texture.tex_coords)
player._texture.tex_coords = t[9:12] + t[6:9] + t[3:6] + t[:3]
示例11: get_best_config
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def get_best_config(self, template=None):
'''Get the best available GL config.
Any required attributes can be specified in `template`. If
no configuration matches the template, `NoSuchConfigException` will
be raised.
:Parameters:
`template` : `pyglet.gl.Config`
A configuration with desired attributes filled in.
:rtype: `pyglet.gl.Config`
:return: A configuration supported by the platform that best
fulfils the needs described by the template.
'''
if template is None:
template = gl.Config()
configs = self.get_matching_configs(template)
if not configs:
raise NoSuchConfigException()
return configs[0]
示例12: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw():
gl.glColorMask(True, True, True, True)
window.clear()
with rc.default_shader, rc.default_states:
with camera.right:
gl.glColorMask(False, True, True, True)
monkey.draw()
gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
with camera.left:
gl.glColorMask(True, False, False, True)
monkey.draw()
示例13: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw(self):
gl.glClearColor(0, 0, 0, 0)
self.clear()
gl.glViewport(0, 0, self.width, self.height)
with self.shader:
self.shader.uniformf("iTime", time.clock() - self._start_time)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
示例14: on_draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def on_draw(self):
gl.glClearColor(0, 0, 0, 0)
self.clear()
gl.glViewport(0, 0, self.width, self.height)
with self.shader:
self.shader.uniformf("iTime", time.clock() - self._start_time)
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
if self.video_on and (self.frame_count % self.sample_rate == 0):
self.write_video_frame()
self.frame_count += 1
示例15: create_texture_from_ndarray
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import gl [as 别名]
def create_texture_from_ndarray(array):
"""Create a 2D texture from a numpy ndarray.
"""
height, width = array.shape[:2]
texture = pyglet.image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height,
gl.GL_RGBA32F_ARB)
gl.glBindTexture(texture.target, texture.id)
gl.glTexImage2D(texture.target, texture.level, gl.GL_RGBA32F_ARB,
width, height, 0, gl.GL_RGBA, gl.GL_FLOAT, array.ctypes.data)
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.glBindTexture(texture.target, 0)
return texture