def gluUnProject4(baseFunction,
                  winX,
                  winY,
                  winZ,
                  clipW,
                  model=None,
                  proj=None,
                  view=None,
                  near=0.0,
                  far=1.0):
    """Convenience wrapper for gluUnProject
    
    Automatically fills in the model, projection and viewing matrices
    if not provided.
    
    returns (objX,objY,objZ) doubles
    """
    if model is None:
        model = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
    if proj is None:
        proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
    if view is None:
        view = GL.glGetIntegerv(GL.GL_VIEWPORT)
    objX = _simple.GLdouble(0.0)
    objY = _simple.GLdouble(0.0)
    objZ = _simple.GLdouble(0.0)
    objW = _simple.GLdouble(0.0)
    result = baseFunction(winX, winY, winZ, model, proj, view,
                          ctypes.byref(objX), ctypes.byref(objY),
                          ctypes.byref(objZ), ctypes.byref(objW))
    if not result:
        raise ValueError("""Projection failed!""")
    return objX.value, objY.value, objZ.value, objW.value
Beispiel #2
0
def gluGetTessProperty(baseFunction, tess, which, data=None):
    """Retrieve single double for a tessellator property"""
    if data is None:
        data = _simple.GLdouble(0.0)
        baseFunction(tess, which, data)
        return data.value
    else:
        return baseFunction(tess, which, data)
def gluProject(baseFunction,
               objX,
               objY,
               objZ,
               model=None,
               proj=None,
               view=None):
    """Convenience wrapper for gluProject
    
    Automatically fills in the model, projection and viewing matrices
    if not provided.
    
    returns (winX,winY,winZ) doubles
    """
    if model is None:
        model = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
    if proj is None:
        proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
    if view is None:
        view = GL.glGetIntegerv(GL.GL_VIEWPORT)
    winX = _simple.GLdouble(0.0)
    winY = _simple.GLdouble(0.0)
    winZ = _simple.GLdouble(0.0)
    result = baseFunction(
        objX,
        objY,
        objZ,
        model,
        proj,
        view,
        winX,
        winY,
        winZ,
    )
    # On Ubuntu 9.10 we see a None come out of baseFunction,
    # despite it having a return-type specified of GLint!
    if result is not None and result != _simple.GLU_TRUE:
        raise ValueError("""Projection failed!""")
    return winX.value, winY.value, winZ.value
def gluProject(baseFunction,
               objX,
               objY,
               objZ,
               model=None,
               proj=None,
               view=None):
    """Convenience wrapper for gluProject
	
	Automatically fills in the model, projection and viewing matrices
	if not provided.
	
	returns (winX,winY,winZ) doubles
	"""
    if model is None:
        model = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
    if proj is None:
        proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
    if view is None:
        view = GL.glGetIntegerv(GL.GL_VIEWPORT)
    winX = simple.GLdouble(0.0)
    winY = simple.GLdouble(0.0)
    winZ = simple.GLdouble(0.0)
    result = baseFunction(
        objX,
        objY,
        objZ,
        model,
        proj,
        view,
        winX,
        winY,
        winZ,
    )
    if not result:
        raise ValueError("""Projection failed!""")
    return winX.value, winY.value, winZ.value
 def test_nurbs_raw(self):
     """Test nurbs rendering using raw API calls"""
     from OpenGL.raw import GLU as GLU_raw
     knots = (GLfloat * 8)(0, 0, 0, 0, 1, 1, 1, 1)
     ctlpoints = (GLfloat * (3 * 4 * 4))(
         -3., -3., -3., -3., -1., -3., -3., 1., -3., -3., 3., -3., -1., -3.,
         -3., -1., -1., 3., -1., 1., 3., -1., 3., -3., 1., -3., -3., 1.,
         -1., 3., 1., 1., 3., 1., 3., -3., 3., -3., -3., 3., -1., -3., 3.,
         1., -3., 3., 3., -3.)
     theNurb = GLU_raw.gluNewNurbsRenderer()
     GLU_raw.gluBeginSurface(theNurb)
     GLU_raw.gluNurbsSurface(theNurb, 8, ctypes.byref(knots), 8,
                             ctypes.byref(knots), 4 * 3, 3,
                             ctypes.byref(ctlpoints), 4, 4,
                             GL_MAP2_VERTEX_3)
     GLU_raw.gluEndSurface(theNurb)
 def test_nurbs_raw_arrays(self):
     """Test nurbs rendering using raw API calls with arrays"""
     from OpenGL.raw import GLU as GLU_raw
     knots = np.array((0, 0, 0, 0, 1, 1, 1, 1), "f")
     ctlpoints = np.array(
         [[[-3., -3., -3.], [-3., -1., -3.], [-3., 1., -3.],
           [-3., 3., -3.]],
          [[-1., -3., -3.], [-1., -1., 3.], [-1., 1., 3.],
           [-1., 3., -3.]],
          [[1., -3., -3.], [1., -1., 3.], [1., 1., 3.], [1., 3., -3.]],
          [[3., -3., -3.], [3., -1., -3.], [3., 1., -3.], [3., 3., -3.]]
          ], "f")
     theNurb = GLU_raw.gluNewNurbsRenderer()
     GLU_raw.gluBeginSurface(theNurb)
     GLU_raw.gluNurbsSurface(theNurb, 8, knots, 8, knots, 4 * 3, 3,
                             ctlpoints, 4, 4, GL_MAP2_VERTEX_3)
     GLU_raw.gluEndSurface(theNurb)
Beispiel #7
0
 def gluTessBeginPolygon(self, data):
     """Note the object pointer to return it as a Python object"""
     return _simple.gluTessBeginPolygon(
         self, ctypes.c_void_p(self.noteObject(data)))
Beispiel #8
0
 def gluTessBeginPolygon( self, data ):
     """Note the object pointer to return it as a Python object"""
     return _simple.gluTessBeginPolygon(
         self, ctypes.c_void_p(self.noteObject( data ))
     )
Beispiel #9
0
def main():
    glutInit(sys.argv)
    glutCreateWindow("molehill")
    glMaterialfv(GL_FRONT, GL_SPECULAR, variables.mat_specular)
    glMaterialfv(GL_FRONT, GL_SHININESS, variables.mat_shininess)
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_AUTO_NORMAL)
    glEnable(GL_NORMALIZE)
    variables.nurb = GLU_raw.gluNewNurbsRenderer()
    GLU_raw.gluNurbsProperty(variables.nurb, GLU_SAMPLING_TOLERANCE, 25.0)
    GLU_raw.gluNurbsProperty(variables.nurb, GLU_DISPLAY_MODE, GLU_FILL)

    # Build control points for NURBS mole hills. 
    for u in range(4):
        for v in range(4):
            # Red. 
            variables.pts1[u][v][0] = 2.0 * u
            variables.pts1[u][v][1] = 2.0 * v
            if (u == 1 or u == 2) and (v == 1 or v == 2):
                # Stretch up middle. 
                variables.pts1[u][v][2] = 6.0
            else:
                variables.pts1[u][v][2] = 0.0

            # Green. 
            variables.pts2[u][v][0] = 2.0 * (u - 3.0)
            variables.pts2[u][v][1] = 2.0 * (v - 3.0)
            if (u == 1 or u == 2) and (v == 1 or v == 2):
                if u == 1 and v == 1:
                    # Pull hard on single middle square. 
                    variables.pts2[u][v][2] = 15.0
                else:
                    # Push down on other middle squares. 
                    variables.pts2[u][v][2] = -2.0
            else:
                variables.pts2[u][v][2] = 0.0

            # Blue. 
            variables.pts3[u][v][0] = 2.0 * (u - 3.0)
            variables.pts3[u][v][1] = 2.0 * v
            if (u == 1 or u == 2) and (v == 1 or v == 2):
                if u == 1 and v == 2:
                    # Pull up on single middple square. 
                    variables.pts3[u][v][2] = 11.0
                else:
                    # Pull up slightly on other middle squares. 
                    variables.pts3[u][v][2] = 2.0
            else:
                variables.pts3[u][v][2] = 0.0

            # Yellow. 
            variables.pts4[u][v][0] = 2.0 * u
            variables.pts4[u][v][1] = 2.0 * (v - 3.0)
            if (u == 1 or u == 2 or u == 3) and (v == 1 or v == 2):
                if v == 1:
                    # Push down front middle and right squares. 
                    variables.pts4[u][v][2] = -2.0
                else:
                    # Pull up back middle and right squares. 
                    variables.pts4[u][v][2] = 5.0
            else:
                variables.pts4[u][v][2] = 0.0

    # Stretch up red's far right corner.
    variables.pts1[3][3][2] = 6
    # Pull down green's near left corner a little.
    variables.pts2[0][0][2] = -2
    # Turn up meeting of four corners.
    variables.pts1[0][0][2] = 1
    variables.pts2[3][3][2] = 1
    variables.pts3[3][0][2] = 1
    variables.pts4[0][3][2] = 1

    glMatrixMode(GL_PROJECTION)

    gluPerspective(55.0, 1.0, 2.0, 24.0)
    glMatrixMode(GL_MODELVIEW)
    glTranslatef(0.0, 0.0, -15.0)
    glRotatef(330.0, 1.0, 0.0, 0.0)

    glNewList(1, GL_COMPILE)
    # Render red hill.
    glMaterialfv(GL_FRONT, GL_DIFFUSE, variables.mat_red_diffuse)
    GLU_raw.gluBeginSurface(variables.nurb)
    GLU_raw.gluNurbsSurface(variables.nurb, 8, variables.knots, 8, variables.knots,
                            4 * 3, 3, variables.pts1,
                            4, 4, GL_MAP2_VERTEX_3)
    GLU_raw.gluEndSurface(variables.nurb)

    # Render green hill.
    glMaterialfv(GL_FRONT, GL_DIFFUSE, variables.mat_green_diffuse)
    GLU_raw.gluBeginSurface(variables.nurb)
    GLU_raw.gluNurbsSurface(variables.nurb, 8, variables.knots, 8, variables.knots,
                            4 * 3, 3, variables.pts2,
                            4, 4, GL_MAP2_VERTEX_3)
    GLU_raw.gluEndSurface(variables.nurb)

    # Render blue hill.
    glMaterialfv(GL_FRONT, GL_DIFFUSE, variables.mat_blue_diffuse)
    GLU_raw.gluBeginSurface(variables.nurb)
    GLU_raw.gluNurbsSurface(variables.nurb, 8, variables.knots, 8, variables.knots,
                            4 * 3, 3, variables.pts3,
                            4, 4, GL_MAP2_VERTEX_3)
    GLU_raw.gluEndSurface(variables.nurb)

    # Render yellow hill.
    glMaterialfv(GL_FRONT, GL_DIFFUSE, variables.mat_yellow_diffuse)
    GLU_raw.gluBeginSurface(variables.nurb)
    GLU_raw.gluNurbsSurface(variables.nurb, 8, variables.knots, 8, variables.knots,
                            4 * 3, 3, variables.pts4,
                            4, 4, GL_MAP2_VERTEX_3)
    GLU_raw.gluEndSurface(variables.nurb)

    glEndList()

    glutDisplayFunc(display)
    glutMainLoop()