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


Python Texture.bind方法代碼示例

本文整理匯總了Python中texture.Texture.bind方法的典型用法代碼示例。如果您正苦於以下問題:Python Texture.bind方法的具體用法?Python Texture.bind怎麽用?Python Texture.bind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在texture.Texture的用法示例。


在下文中一共展示了Texture.bind方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SimpleScreen

# 需要導入模塊: from texture import Texture [as 別名]
# 或者: from texture.Texture import bind [as 別名]
class SimpleScreen(Screen):
  """A screen with a single textured quad displaying a background image"""

  def __init__(self, ui, textureFile):
    super(SimpleScreen, self).__init__(ui)
    self._texture = Texture(textureFile)

  def draw(self):
    """Draw the menu background"""
    # Clear the screen
    glClearColor(0, 0, 0, 1)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    glEnable(GL_TEXTURE_2D)

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    self._texture.bind()
    glBegin(GL_QUADS)
    if True:
      glColor4f(1, 1, 1, 1)
      glTexCoord2f(0.0, 0.0); glVertex2f(-8.0, -6.0)
      glTexCoord2f(1.0, 0.0); glVertex2f( 8.0, -6.0)
      glTexCoord2f(1.0, 1.0); glVertex2f( 8.0,  6.0)
      glTexCoord2f(0.0, 1.0); glVertex2f(-8.0,  6.0)
    glEnd()
開發者ID:aarmea,項目名稱:mumei,代碼行數:29,代碼來源:screen.py

示例2: PointCloud

# 需要導入模塊: from texture import Texture [as 別名]
# 或者: from texture.Texture import bind [as 別名]
class PointCloud(GLArray):
    def __init__(self, vertex_data=None, color_data=None):
        GLArray.__init__(self, vertex_data, color_data)
        self._sprite_texture = None

    def sprite(self, filename):
        print " -- initializing point sprite {}".format(filename)

        self._sprite_texture = Texture(filename)

    def _pre_draw(self):
        GLArray._pre_draw(self)

        if self._sprite_texture == None:
            return

        glDepthMask(GL_FALSE)

        glEnable(GL_POINT_SMOOTH)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        self._sprite_texture.bind()

        glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)
        glEnable(GL_POINT_SPRITE)

        glPointSize(15.0)

    def _post_draw(self):
        GLArray._post_draw(self)

        if self._sprite_texture == None:
            return

        self._sprite_texture.unbind()

        glDisable(GL_BLEND)
        glDisable(GL_POINT_SPRITE)

    def center(self):
        try:
            return self._center
        except:
            self._center = [0.0, 0.0, 0.0]
            for i in range(3):
                self._center[i] = sum(v[i] for v in self._vertex_data) / len(self._vertex_data)
            return self._center
開發者ID:chebee7i,項目名稱:vroom,代碼行數:50,代碼來源:point_cloud.py

示例3: GlutWindow

# 需要導入模塊: from texture import Texture [as 別名]
# 或者: from texture.Texture import bind [as 別名]
class GlutWindow(WindowCallback):

    def __init__(self, screen_size: tuple, screen_pos: tuple=(0, 0),
                 game_mode: bool=False, title: str='Default Title', **params):
        width, height = screen_size
        self.screen_size = screen_size
        self.screen_pos = screen_pos
        self.width = width
        self.height = height
        self.z_near = 1.0
        self.z_far = 100.0
        self.fov = 60.0
        self.game_mode = game_mode
        self.title = title

        self._vbo = None
        self._vao = None
        self._ibo = None
        self._program = None
        self._texture = None
        self._vertices = None
        self._indexes = None
        self._camera = None
        self._pipeline = None
        self._scale = 0.0
        self._dir_light_color = 1.0, 1.0, 1.0
        self._dir_light_ambient_intensity = 0.5
        self._projection = ProjParams(
            self.width, self.height, self.z_near, self.z_far, self.fov)

        self._log = params.get("log", print)
        self._clear_color = params.get("clearcolor", (0, 0, 0, 0))
        self._vertex_attributes = {"Position": -1, "TexCoord": -1}

        self._init_glut()
        self._init_gl()
        self._create_vertex_buffer()
        self._create_index_buffer()

        self._effect = LightingTechnique("shaders/vs.glsl", "shaders/fs_lighting.glsl")
        self._effect.init()
        self._effect.enable()
        self._effect.set_texture_unit(0)

        self._texture = Texture(GL_TEXTURE_2D, "resources/test.png")
        if not self._texture.load():
            raise ValueError("cannot load texture")

    def _init_glut(self):
        """
        Basic GLUT initialization and callbacks binding
        """
        glutInit(sys.argv[1:])
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_3_2_CORE_PROFILE)
        glutInitWindowSize(self.width, self.height)
        if self.game_mode:
            glutGameModeString("{}x{}@32".format(self.width, self.height))
            glutEnterGameMode()
        else:
            glutCreateWindow(self.title.encode())
            glutInitWindowPosition(*self.screen_pos)
        # callbacks binding
        glutDisplayFunc(self.on_display)
        glutIdleFunc(self.on_display)
        glutPassiveMotionFunc(self.on_mouse)
        glutSpecialFunc(self.on_keyboard)

    def _init_gl(self):
        """
        OpenGL initialization
        """
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        glClearColor(*self._clear_color)
        # seems strange because should be GL_BACK... maybe something with camera?
        glCullFace(GL_FRONT)
        glFrontFace(GL_CW)
        glEnable(GL_CULL_FACE)

    def _create_vertex_buffer(self):
        """
        Creates vertex array and vertex buffer and fills last one with data.
        """
        self._vertices = np.array([
            -1.0, -1.0, 0.5773, 0.0, 0.0,
            0.0, -1.0, -1.15475, 0.5, 0.0,
            1.0, -1.0, 0.5773, 1.0, 0.0,
            0.0, 1.0, 0.0, 0.5, 1.0
        ], dtype=np.float32)

        self._vao = glGenVertexArrays(1)
        glBindVertexArray(self._vao)
        self._vbo = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self._vbo)
        glBufferData(GL_ARRAY_BUFFER, self._vertices.nbytes, self._vertices, GL_STATIC_DRAW)

    def _create_index_buffer(self):
        """
        Creates index buffer.
        """
#.........這裏部分代碼省略.........
開發者ID:devforfu,項目名稱:pyogldev,代碼行數:103,代碼來源:glutwindow.py


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