コード例 #1
0
ファイル: view.py プロジェクト: eriknelson/gam3
    def paint(self):
        """
        For all of the known terrain, render whatever faces are exposed.
        """
        if self._texture is None:
            self._texture = self._createTexture()

        glBindTexture(GL_TEXTURE_2D, self._texture)
        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_TEXTURE_COORD_ARRAY)
        for surface in self._vbos:
            vbo = surface.update
            length = surface.important
            vbo.bind()
            glVertexPointer(3, GL_FLOAT, 4 * 5, vbo)
            glTexCoordPointer(2, GL_FLOAT, 4 * 5, vbo + (4 * 3))
            glDrawArrays(GL_TRIANGLES, 0, length)
            vbo.unbind()
        glDisableClientState(GL_VERTEX_ARRAY)
        glDisableClientState(GL_TEXTURE_COORD_ARRAY)
        glBindTexture(GL_TEXTURE_2D, 0)
コード例 #2
0
ファイル: buffers.py プロジェクト: suddi/3DSlantRelief
 def bind_texcoords(self, size, var_type, stride=0):
     self.bind()
     glTexCoordPointer(size, var_type, stride, None)
コード例 #3
0
ファイル: drawers.py プロジェクト: ematvey/NanoEngineer-1
def drawHeightfield(color, w, h, textureReady, opacity,
                    SOLID=False, pickCheckOnly=False, hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texuture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """        

    from OpenGL.GL import glTexEnvf
    from OpenGL.GL import GL_TEXTURE_ENV
    from OpenGL.GL import GL_TEXTURE_ENV_MODE
    from OpenGL.GL import GL_MODULATE
    from OpenGL.GL import glVertexPointer
    from OpenGL.GL import glNormalPointer
    from OpenGL.GL import glTexCoordPointer
    from OpenGL.GL import glDrawArrays
    from OpenGL.GL import glEnableClientState
    from OpenGL.GL import GL_VERTEX_ARRAY
    from OpenGL.GL import GL_NORMAL_ARRAY
    from OpenGL.GL import GL_TEXTURE_COORD_ARRAY
        
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    ### glColor4fv(list(color) + [opacity])
    ### glColor3fv(list(color))
    glColor3f(1.0, 1.0, 1.0)
    
    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    
    glDisable(GL_CULL_FACE) 
    
    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)  
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))
        
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)
    
    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE) 

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    
    return
コード例 #4
0
ファイル: meshviewer.py プロジェクト: nonlinear1/meshlite
    def draw_mesh(m, lighting_on):

        # Supply vertices
        glEnableClientState(GL_VERTEX_ARRAY)
        m.vbo['v'].bind()
        glVertexPointer(3, GL_FLOAT, 0, m.vbo['v'])
        m.vbo['v'].unbind()

        # Supply normals
        if 'vn' in m.vbo.keys():
            glEnableClientState(GL_NORMAL_ARRAY)
            m.vbo['vn'].bind()
            glNormalPointer(GL_FLOAT, 0, m.vbo['vn'])
            m.vbo['vn'].unbind()
        else:
            glDisableClientState(GL_NORMAL_ARRAY)

        # Supply colors
        if 'vc' in m.vbo.keys():
            glEnableClientState(GL_COLOR_ARRAY)
            m.vbo['vc'].bind()
            glColorPointer(3, GL_FLOAT, 0, m.vbo['vc'])
            m.vbo['vc'].unbind()
        else:
            glDisableClientState(GL_COLOR_ARRAY)

        if ('vt' in m.vbo.keys()) and hasattr(m, 'textureID'):
            glEnable(GL_TEXTURE_2D)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
            glBindTexture(GL_TEXTURE_2D, m.textureID)

            glEnableClientState(GL_TEXTURE_COORD_ARRAY)
            m.vbo['vt'].bind()
            glTexCoordPointer(2, GL_FLOAT, 0, m.vbo['vt'])
            m.vbo['vt'].unbind()
        else:
            glDisable(GL_TEXTURE_2D)
            glDisableClientState(GL_TEXTURE_COORD_ARRAY)

        # Draw
        if len(m.f) > 0:
            # ie if it is triangulated
            if lighting_on:
                glEnable(GL_LIGHTING)
            else:
                glDisable(GL_LIGHTING)
            glDrawElementsui(GL_TRIANGLES, np.arange(m.f.size,
                                                     dtype=np.uint32))
        else:
            # not triangulated, so disable lighting
            glDisable(GL_LIGHTING)
            glPointSize(2)
            glDrawElementsui(GL_POINTS, np.arange(len(m.v), dtype=np.uint32))
        if hasattr(m, 'v_to_text'):

            glEnable(GL_TEXTURE_2D)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                            GL_LINEAR_MIPMAP_LINEAR)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)

            # glEnable(GL_TEXTURE_GEN_S)
            # glEnable(GL_TEXTURE_GEN_T)
            # glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)
            # glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)

            bgcolor = np.array(glGetDoublev(GL_COLOR_CLEAR_VALUE))
            fgcolor = 1. - bgcolor

            from .lines import Lines
            sc = float(np.max(np.max(m.v, axis=0) - np.min(m.v, axis=0))) / 10.

            cur_mtx = np.linalg.pinv(glGetFloatv(GL_MODELVIEW_MATRIX).T)
            xdir = cur_mtx[:3, 0]
            ydir = cur_mtx[:3, 1]

            glEnable(GL_LINE_SMOOTH)
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

            for vidx, text in m.v_to_text.items():
                pos0 = m.v[vidx].copy()
                pos1 = m.v[vidx].copy()
                if hasattr(m, 'vn'):
                    pos1 += m.vn[vidx] * sc
                glLineWidth(5.0)
                ln = Lines(v=np.vstack((pos0, pos1)), e=np.array([[0, 1]]))
                glEnable(GL_LIGHTING)
                glColor3f(1. - 0.8, 1. - 0.8, 1. - 1.00)
                MeshViewerSingle.draw_lines(ln)

                glDisable(GL_LIGHTING)

                texture_id = get_textureid_with_text(text, bgcolor, fgcolor)
                glBindTexture(GL_TEXTURE_2D, texture_id)

                glPushMatrix()
                glTranslatef(pos1[0], pos1[1], pos1[2])

                dx = xdir * .10
                dy = ydir * .10
                if False:
                    glBegin(GL_QUADS)

                    glTexCoord2f(1., 0.)
                    glVertex3f(*(+dx + dy))

                    glTexCoord2f(1., 1.)
                    glVertex3f(*(+dx - dy))

                    glTexCoord2f(0., 1.)
                    glVertex3f(*(-dx - dy))

                    glTexCoord2f(0., 0.)
                    glVertex3f(*(-dx + dy))

                    # gluSphere(quadratic,0.05,32,32)
                    glEnd()
                else:
                    glBegin(GL_POLYGON)

                    for r in np.arange(0, np.pi * 2., .01):
                        glTexCoord2f(np.cos(r) / 2. + .5, np.sin(r) / 2. + .5)
                        glVertex3f(*(dx * np.cos(r) + -dy * np.sin(r)))

                    glEnd()
                glPopMatrix()
コード例 #5
0
ファイル: drawers.py プロジェクト: pmetzger/nanoengineer
def drawHeightfield(color, w, h, textureReady, opacity,
                    SOLID = False, pickCheckOnly = False, hf = None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """        

    if not hf:
        # Return if heightfield is not provided
        return
    
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    # Don't use opacity, otherwise the heighfield polygons should be sorted
    # - something to implement later...
    ## glColor3v(list(color))
    
    if textureReady:
        # For texturing, use white color (to be modulated by the texture)
        glColor3f(1,1,1)
    else:
        glColor3fv(list(color))
        
    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    
    glDisable(GL_CULL_FACE) 
    
    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)  
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))
        
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)
    
    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE) 

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)
    
    return
コード例 #6
0
ファイル: drawers.py プロジェクト: vcsrc/nanoengineer
def drawHeightfield(color,
                    w,
                    h,
                    textureReady,
                    opacity,
                    SOLID=False,
                    pickCheckOnly=False,
                    hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """

    if not hf:
        # Return if heightfield is not provided
        return

    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    # Don't use opacity, otherwise the heighfield polygons should be sorted
    # - something to implement later...
    ## glColor3v(list(color))

    if textureReady:
        # For texturing, use white color (to be modulated by the texture)
        glColor3f(1, 1, 1)
    else:
        glColor3fv(list(color))

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    glDisable(GL_CULL_FACE)

    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))

    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE)

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)

    return
コード例 #7
0
def drawHeightfield(color,
                    w,
                    h,
                    textureReady,
                    opacity,
                    SOLID=False,
                    pickCheckOnly=False,
                    hf=None):
    """
    Draw a heighfield using vertex and normal arrays. Optionally, it could be
    texuture mapped.

    @pickCheckOnly This is used to draw the geometry only, used for OpenGL pick
      selection purpose.
    """

    from OpenGL.GL import glTexEnvf
    from OpenGL.GL import GL_TEXTURE_ENV
    from OpenGL.GL import GL_TEXTURE_ENV_MODE
    from OpenGL.GL import GL_MODULATE
    from OpenGL.GL import glVertexPointer
    from OpenGL.GL import glNormalPointer
    from OpenGL.GL import glTexCoordPointer
    from OpenGL.GL import glDrawArrays
    from OpenGL.GL import glEnableClientState
    from OpenGL.GL import GL_VERTEX_ARRAY
    from OpenGL.GL import GL_NORMAL_ARRAY
    from OpenGL.GL import GL_TEXTURE_COORD_ARRAY

    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)

    ### glColor4fv(list(color) + [opacity])
    ### glColor3fv(list(color))
    glColor3f(1.0, 1.0, 1.0)

    glPushMatrix()
    glScalef(w, h, 1.0)

    if SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    else:
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    glDisable(GL_CULL_FACE)

    if not pickCheckOnly:
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        if textureReady:
            glEnable(GL_TEXTURE_2D)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)

    for tstrip_vert, tstrip_norm, tstrip_tex in hf:
        glVertexPointer(3, GL_FLOAT, 0, tstrip_vert)
        glNormalPointer(GL_FLOAT, 0, tstrip_norm)
        glTexCoordPointer(2, GL_FLOAT, 0, tstrip_tex)
        glDrawArrays(GL_TRIANGLE_STRIP, 0, len(tstrip_vert))

    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)
    glDisableClientState(GL_TEXTURE_COORD_ARRAY)

    glDisable(GL_COLOR_MATERIAL)

    if not pickCheckOnly:
        if textureReady:
            glDisable(GL_TEXTURE_2D)

        glDepthMask(GL_TRUE)

    glEnable(GL_CULL_FACE)
    if not SOLID:
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPopMatrix()
    glEnable(GL_LIGHTING)

    return