當前位置: 首頁>>代碼示例>>Python>>正文


Python pyglet.gl方法代碼示例

本文整理匯總了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 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:24,代碼來源:example_wythoff_shader_animation.py

示例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 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:25,代碼來源:example_wythoff_shader_animation.py

示例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) 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:24,代碼來源:loxodrome.py

示例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() 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:19,代碼來源:main.py

示例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 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:18,代碼來源:texture.py

示例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 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:19,代碼來源:vertexbuffer.py

示例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 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:19,代碼來源:lib_wgl.py

示例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) 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:18,代碼來源:__init__.py

示例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 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:18,代碼來源:__init__.py

示例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] 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:22,代碼來源:avbin.py

示例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] 
開發者ID:shrimpboyho,項目名稱:flappy-bird-py,代碼行數:23,代碼來源:__init__.py

示例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() 
開發者ID:ratcave,項目名稱:ratcave,代碼行數:16,代碼來源:tutorial6.py

示例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) 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:9,代碼來源:fractal3d.py

示例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 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:14,代碼來源:Mobius_in_H3space.py

示例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 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:15,代碼來源:texture.py


注:本文中的pyglet.gl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。