当前位置: 首页>>代码示例>>Python>>正文


Python gl.glBindTexture方法代码示例

本文整理汇总了Python中pyglet.gl.glBindTexture方法的典型用法代码示例。如果您正苦于以下问题:Python gl.glBindTexture方法的具体用法?Python gl.glBindTexture怎么用?Python gl.glBindTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.gl的用法示例。


在下文中一共展示了gl.glBindTexture方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [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

示例2: create_image_texture

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [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

示例3: create_texture_from_ndarray

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [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

示例4: create_cubemap_texture

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
def create_cubemap_texture(imgfiles):
    """Create a cubemap texture from image files.
    """
    if len(imgfiles) != 6:
        raise ValueError("exactly six images are required for a cubemap texture")

    # generate a new texture
    cubemap = gl.GLuint()
    gl.glGenTextures(1, ct.pointer(cubemap))

    # bind it to `GL_TEXTURE_CUBE_MAP` and set the filter and wrap mode
    gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, cubemap)
    gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, gl.GL_TEXTURE_WRAP_R, gl.GL_CLAMP_TO_EDGE)

    faces = [Image.open(img) for img in imgfiles]
    # set the faces of the cubemap texture
    for i, face in enumerate(faces):
        width, height = face.size
        try:
            data = face.tobytes("raw", "RGBX", 0, -1)
        except TypeError:
            data = face.tobytes("raw", "RGBA", 0, -1)

        gl.glTexImage2D(gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.GL_RGBA,
                        width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, data)

    gl.glGenerateMipmap(gl.GL_TEXTURE_CUBE_MAP)
    gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, 0)
    return cubemap 
开发者ID:neozhaoliang,项目名称:pywonderland,代码行数:35,代码来源:texture.py

示例5: on_draw

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
def on_draw(self):
        self.window.clear()
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        self.camera()
        gl.glEnable(self.background.target)
        gl.glEnable(gl.GL_BLEND)
        gl.glBindTexture(self.background.target, self.background.id)
        W = 10000.
        graphics.draw(4, gl.GL_QUADS,
                      ('v2f', (-W, -W, W, -W, W, W, -W, W)),
                      ('t2f', (0., 0., W * 5., 0., W * 5., W * 5., 0., W * 5.))
                      )
        gl.glDisable(self.background.target)
        for lane in self.world.lanes:
            self.draw_lane_surface(lane)
            self.draw_lane_lines(lane)
        for obj in self.world.objects:
            self.draw_object(obj)
        for car in self.world.cars:
            self.draw_car(car.trajectory[-1], car.color)
        gl.glPopMatrix()

        self.label.text = self.task_name
        self.label.draw()
        self.iter +=1
        if self.iter%10 == 0:
            print('Iterations: ', self.iter)
        if self.iter == self.max_iters:
            self.event_loop.exit() 
开发者ID:BerkeleyLearnVerify,项目名称:VerifAI,代码行数:33,代码来源:simulator.py

示例6: _bind_texture

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
def _bind_texture(self, i):
        gl.glActiveTexture((gl.GL_TEXTURE0, gl.GL_TEXTURE1, gl.GL_TEXTURE2)[i])
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture[i].id)
        gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
        gl.glTexEnvf(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_ALPHA, gl.GL_REPLACE if i == 0 else gl.GL_ADD)
        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) 
开发者ID:pyglet,项目名称:pyglet,代码行数:10,代码来源:test_multitexture.py

示例7: buffer_texture

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
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_ 
开发者ID:edne,项目名称:pineal,代码行数:31,代码来源:framebuffer.py

示例8: __init__

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
def __init__(self, width, height):
        """
        :param width and height: size of the window in pixels.
        """
        pyglet.window.Window.__init__(self,
                                      width,
                                      height,
                                      caption="Wythoff Explorer",
                                      resizable=True,
                                      visible=False,
                                      vsync=False)
        self._start_time = time.clock()
        self._last = self._now = self._start_time
        self._frame_count = 0  # count number of frames rendered so far
        self.shaderA = Shader(["./glsl_wythoff/wythoff.vert"],
                              ["./glsl_wythoff/common.frag",
                               "./glsl_wythoff/BufferA.frag"])

        self.shaderB = Shader(["./glsl_wythoff/wythoff.vert"],
                              ["./glsl_wythoff/common.frag",
                               "./glsl_wythoff/main.frag"])

        self.font_texture = create_image_texture(FONT_TEXTURE)
        self.noise_texture = create_image_texture(NOISE_TEXTURE)
        self.iChannel0 = pyglet.image.Texture.create_for_size(gl.GL_TEXTURE_2D, width, height,
                                                              gl.GL_RGBA32F_ARB)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.iChannel0.target, self.iChannel0.id)
        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.font_texture)
        gl.glActiveTexture(gl.GL_TEXTURE2)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.noise_texture)

        with FrameBuffer() as self.bufferA:
            self.bufferA.attach_texture(self.iChannel0)

        # initialize the shaders
        with self.shaderA:
            self.shaderA.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderA.uniformf("iResolution", width, height, 0.0)
            self.shaderA.uniformf("iTime", 0.0)
            self.shaderA.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderA.uniformi("iChannel0", 0)
            self.shaderA.uniformi("iChannel1", 1)
            self.shaderA.uniformi("iChannel2", 2)
            self.shaderA.uniformf("iDate", *get_idate())
            self.shaderA.uniformf("iTimeDelta", 0)

        with self.shaderB:
            self.shaderB.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderB.uniformf("iResolution", width, height, 0.0)
            self.shaderB.uniformf("iTime", 0.0)
            self.shaderB.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderB.uniformi("iChannel0", 0)
            self.shaderB.uniformi("iChannel1", 1)
            self.shaderB.uniformi("iChannel2", 2)
            self.shaderB.uniformf("iDate", *get_idate())
            self.shaderA.uniformf("iTimeDelta", 0) 
开发者ID:neozhaoliang,项目名称:pywonderland,代码行数:60,代码来源:example_wythoff_shader_animation.py

示例9: show_drone

# 需要导入模块: from pyglet import gl [as 别名]
# 或者: from pyglet.gl import glBindTexture [as 别名]
def show_drone(self, position, rotation):
        """
        Show the drone 3D model with corresponding translation and rotation.
        """
        # Get the transform matrix for drone 3D model
        x, z, y = position
        transform = np.eye(4)
        transform[:3, 3] = [x, y, z]

        # NOTE: change the view size of drone 3D model
        transform[0, 0] = 2.5
        transform[1, 1] = 2.5
        transform[2, 2] = 2.5

        # Match drone model space x-y-z to openGL x-z-y
        # TODO: read the config.json and match the propeller positions
        model_space_transform = rotation_transform_mat(-np.pi / 2, 'roll')
        transform = np.dot(transform, model_space_transform)

        yaw, pitch, roll = rotation
        if self.debug_mode:
            # NOTE: manually set values to debug rotation,
            # it's useful when input act is in form [c, c, c, c].
            yaw = np.pi / 2
            # pitch = np.pi / 2
            # roll = np.pi / 2
        transform = np.dot(transform, rotation_transform_mat(yaw, 'yaw'))
        transform = np.dot(transform, rotation_transform_mat(pitch, 'pitch'))
        transform = np.dot(transform, rotation_transform_mat(roll, 'roll'))

        # Add a new matrix to the model stack to transform the model
        gl.glPushMatrix()
        gl.glMultMatrixf(rendering.matrix_to_gl(transform))

        # Enable the target texture
        if self.drone_texture is not None:
            gl.glEnable(self.drone_texture.target)
            gl.glBindTexture(self.drone_texture.target, self.drone_texture.id)

        # Draw the mesh with its transform applied
        self.drone_drawer.draw(mode=self.drone_vertex_list_mode)
        gl.glPopMatrix()

        # Disable texture after using
        if self.drone_texture is not None:
            gl.glDisable(self.drone_texture.target) 
开发者ID:PaddlePaddle,项目名称:RLSchool,代码行数:48,代码来源:render.py


注:本文中的pyglet.gl.glBindTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。