Python OpenGL.GL.glDrawElements() Examples

The following are 5 code examples of OpenGL.GL.glDrawElements(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module OpenGL.GL , or try the search function .
Example #1
Source File: tracked_devices_actor.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def display_gl(self, modelview, projection, pose):
        if not self.model_is_loaded:
            self._try_load_model()
            return
        if not self.texture_is_loaded:
            self._try_load_texture()
            return
        controller_X_room = pose.mDeviceToAbsoluteTracking
        controller_X_room = matrixForOpenVrMatrix(controller_X_room)
        modelview0 = controller_X_room * modelview
        # Repack before use, just in case
        modelview0 = numpy.asarray(numpy.matrix(modelview0, dtype=numpy.float32))
        GL.glUniformMatrix4fv(4, 1, False, modelview0)
        normal_matrix = numpy.asarray(controller_X_room)
        GL.glUniformMatrix4fv(8, 1, False, normal_matrix)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.diffuse_texture)
        GL.glBindVertexArray(self.vao)
        GL.glDrawElements(GL.GL_TRIANGLES, len(self.indexPositions), GL.GL_UNSIGNED_INT, None)
        GL.glBindVertexArray(0) 
Example #2
Source File: hellovr_glfw.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def render_companion_window(self):
        GL.glDisable(GL.GL_DEPTH_TEST)
        GL.glViewport(0, 0, self.companion_width, self.companion_height)
        GL.glBindVertexArray(self.companion_window_vao)
        GL.glUseProgram(self.companion_window_program)
        # render left eye (first half of index array)
        i_size = sizeof(c_uint16)
        count = int(self.companion_window_index_size / 2)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.left_eye_desc.resolve_texture_id)
        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.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
        GL.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(0 * i_size, c_void_p))
        # render right eye (second half of index array)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.right_eye_desc.resolve_texture_id)
        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.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
        GL.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(count * i_size, c_void_p))
        GL.glBindVertexArray(0)
        GL.glUseProgram(0) 
Example #3
Source File: test_opengl2.py    From spimagine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintGL(self):
        self.makeCurrent()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        self.program.bind()

        self.program.enableAttributeArray("position")
        self.vbo.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("position"), 2, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo)


        self.program.enableAttributeArray("color")
        self.vbo_cols.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("color"), 3, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo_cols)

        self.vbo_index.bind()

        #gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.data))

        gl.glDrawElements(gl.GL_TRIANGLES, len(self.index), gl.GL_UNSIGNED_INT, None)

        print(self.context().format().majorVersion())
        print(self.context().format().minorVersion())


        print(gl.glGetString(gl.GL_VERSION)); 
Example #4
Source File: hellovr_glfw.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw(self):
        GL.glBindVertexArray(self.vertex_array)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)
        GL.glDrawElements(GL.GL_TRIANGLES, self.vertex_count, GL.GL_UNSIGNED_SHORT, None)
        GL.glBindVertexArray(0) 
Example #5
Source File: rendering.py    From renpy-shader with MIT License 4 votes vote down vote up
def renderBoneTransform(self, transform, context):
        bone = transform.bone
        mesh = bone.mesh

        if not bone.image or not mesh:
            #No image or mesh attached
            return

        if not bone.visible or transform.transparency >= 1.0:
            #Nothing to draw
            return

        tex = self.skinTextures.textures[bone.image.name]
        texInfluence = self.skinTextures.textures.get(self.getInfluenceName(bone.image.name))
        if not texInfluence:
            texInfluence = self.skinTextures.textures[self.BLACK_TEXTURE]

        self.shader.uniformi(shader.TEX0, 0)
        tex.texture.bind(0)

        self.shader.uniformi(shader.TEX1, 1)
        texInfluence.texture.bind(1)

        self.shader.uniformMatrix4f(shader.PROJECTION, self.getProjection())

        self.bindAttributeArray(self.shader, "inVertex", mesh.vertices, 2)
        self.bindAttributeArray(self.shader, "inUv", mesh.uvs, 2)
        self.bindAttributeArray(self.shader, "inBoneWeights", mesh.boneWeights, 4)
        self.bindAttributeArray(self.shader, "inBoneIndices", mesh.boneIndices, 4)

        self.shader.uniformf("wireFrame", 0)
        self.shader.uniformf("boneAlpha", max(1.0 - transform.transparency, 0))
        gl.glDrawElements(gl.GL_TRIANGLES, len(mesh.indices), gl.GL_UNSIGNED_INT, mesh.indices)

        if bone.wireFrame:
            self.shader.uniformf("wireFrame", 1)
            self.shader.uniformf("boneAlpha", 1.0)
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
            gl.glDrawElements(gl.GL_TRIANGLES, len(mesh.indices), gl.GL_UNSIGNED_INT, mesh.indices)
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)

        self.unbindAttributeArray(self.shader, "inVertex")
        self.unbindAttributeArray(self.shader, "inUv")
        self.unbindAttributeArray(self.shader, "inBoneWeights")
        self.unbindAttributeArray(self.shader, "inBoneIndices")