コード例 #1
0
    def on_draw(self):
        # Clear the window with current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Switch to orthographic view for background drawing
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        gluOrtho2D(0.0, 1.0, 0.0, 1.0)
        
        glMatrixMode(GL_MODELVIEW)
        glBindTexture(GL_TEXTURE_2D, toTextures[1])    # Background texture

        # We will specify texture coordinates
        glDisable(GL_TEXTURE_GEN_S)
        glDisable(GL_TEXTURE_GEN_T)
        
        # No depth buffer writes for background
        glDepthMask(GL_FALSE)

        # Background image
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(0.0, 0.0)
    
        glTexCoord2f(1.0, 0.0)
        glVertex2f(1.0, 0.0)
    
        glTexCoord2f(1.0, 1.0)
        glVertex2f(1.0, 1.0)
        
        glTexCoord2f(0.0, 1.0)
        glVertex2f(0.0, 1.0)
        glEnd()

        # Back to 3D land
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)

        # Turn texgen and depth writing back on
        glEnable(GL_TEXTURE_GEN_S)
        glEnable(GL_TEXTURE_GEN_T)
        glDepthMask(GL_TRUE)

        # May need to swtich to stripe texture
        if iRenderMode != 3:
            glBindTexture(GL_TEXTURE_2D, toTextures[0])

        # Save the matrix state and do the rotations
        glPushMatrix()
        glTranslatef(0.0, 0.0, -2.0)
        glRotatef(xRot, 1.0, 0.0, 0.0)
        glRotatef(yRot, 0.0, 1.0, 0.0)

        # Draw the tours
        gltDrawTorus(0.35, 0.15, 61, 37)
                    
        # Restore the matrix state
        glPopMatrix()
コード例 #2
0
def DrawInhabitants(nShadow):
    if nShadow == 0:
        glColor4f(1.0, 1.0, 1.0, 1.0)
    else:
        glColor4f(0.0, 0.0, 0.0, 0.6) # Shadow color

    # Draw the randomly located spheres
    glBindTexture(GL_TEXTURE_2D, textureObjects[SPHERE_TEXTURE])
    for sphere in spheres:
        glPushMatrix()
        
        sphere.ApplyActorTransform()
        glutSolidSphere(0.3, 21, 11)
        
        glPopMatrix()
        
    glPushMatrix()
    glTranslatef(0.0, 0.1, -2.5)
    
    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 21, 11)
    glPopMatrix()
    
    if nShadow == 0:
        # Torus alone will be specular
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)
        
    glRotatef(yRot, 0.0, 1.0, 0.0)
    glBindTexture(GL_TEXTURE_2D, textureObjects[TORUS_TEXTURE])
    gltDrawTorus(0.35, 0.15, 61, 37)
    glMaterialfv(GL_FRONT, GL_SPECULAR, fNoLight)
    glPopMatrix()
コード例 #3
0
    def on_draw(self):
        # Clear the window with current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Switch to orthographic view for background drawing
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        gluOrtho2D(0.0, 1.0, 0.0, 1.0)

        glMatrixMode(GL_MODELVIEW)
        glBindTexture(GL_TEXTURE_2D, toTextures[1])  # Background texture

        # We will specify texture coordinates
        glDisable(GL_TEXTURE_GEN_S)
        glDisable(GL_TEXTURE_GEN_T)

        # No depth buffer writes for background
        glDepthMask(GL_FALSE)

        # Background image
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(0.0, 0.0)

        glTexCoord2f(1.0, 0.0)
        glVertex2f(1.0, 0.0)

        glTexCoord2f(1.0, 1.0)
        glVertex2f(1.0, 1.0)

        glTexCoord2f(0.0, 1.0)
        glVertex2f(0.0, 1.0)
        glEnd()

        # Back to 3D land
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)

        # Turn texgen and depth writing back on
        glEnable(GL_TEXTURE_GEN_S)
        glEnable(GL_TEXTURE_GEN_T)
        glDepthMask(GL_TRUE)

        # May need to swtich to stripe texture
        if iRenderMode != 3:
            glBindTexture(GL_TEXTURE_2D, toTextures[0])

        # Save the matrix state and do the rotations
        glPushMatrix()
        glTranslatef(0.0, 0.0, -2.0)
        glRotatef(xRot, 1.0, 0.0, 0.0)
        glRotatef(yRot, 0.0, 1.0, 0.0)

        # Draw the tours
        gltDrawTorus(0.35, 0.15, 61, 37)

        # Restore the matrix state
        glPopMatrix()
コード例 #4
0
def DrawInhabitants(nShadow):
    if nShadow == 0:
        glColor4f(1.0, 1.0, 1.0, 1.0)
    else:
        glColor4f(0.0, 0.0, 0.0, 0.6)  # Shadow color

    # Draw the randomly located spheres
    glBindTexture(GL_TEXTURE_2D, textureObjects[SPHERE_TEXTURE])
    for sphere in spheres:
        glPushMatrix()

        sphere.ApplyActorTransform()
        glutSolidSphere(0.3, 21, 11)

        glPopMatrix()

    glPushMatrix()
    glTranslatef(0.0, 0.1, -2.5)

    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 21, 11)
    glPopMatrix()

    if nShadow == 0:
        # Torus alone will be specular
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)

    glRotatef(yRot, 0.0, 1.0, 0.0)
    glBindTexture(GL_TEXTURE_2D, textureObjects[TORUS_TEXTURE])
    gltDrawTorus(0.35, 0.15, 61, 37)
    glMaterialfv(GL_FRONT, GL_SPECULAR, fNoLight)
    glPopMatrix()
コード例 #5
0
 def on_draw(self):
     # Clear the window with the current clearing color
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     
     transformationMatrix = M3DMatrix44f()
     # Build a rotation matrix
     m3dRotationMatrix44(transformationMatrix, m3dDegToRad(yRot), 0.0, 1.0, 0.0)
     transformationMatrix[12] = 0.0
     transformationMatrix[13] = 0.0
     transformationMatrix[14] = -2.5
         
     glLoadMatrixf(transformationMatrix)
     gltDrawTorus(0.35, 0.15, 40, 20)
コード例 #6
0
def DrawWorld():
    glColor3f(1.0, 0.0, 0.0)
    glPushMatrix()
    glTranslatef(0.0, 0.5, -3.5)

    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 17, 9)
    glPopMatrix()

    glRotatef(yRot, 0.0, 1.0, 0.0)
    gltDrawTorus(0.35, 0.15, 61, 37)

    glPopMatrix()
コード例 #7
0
def DrawWorld():
    glColor3f(1.0, 0.0, 0.0)
    glPushMatrix()
    glTranslatef(0.0, 0.5, -3.5)

    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 17, 9)
    glPopMatrix()

    
    glRotatef(yRot, 0.0, 1.0, 0.0)
    gltDrawTorus(0.35, 0.15, 61, 37)

    glPopMatrix()
コード例 #8
0
def DrawInhabitants(nShadow):
    global yRot
    if nShadow == 0:
        pass #yRot += 0.5
    else:
        glColor3f(0.0, 0.0, 0.0)

    
    # Draw the randomly located spheres
    if nShadow == 0:
        glColor3f(0.0, 1.0, 0.0)

    for sphere in spheres:
        glPushMatrix()
        
        sphere.ApplyActorTransform()
        glutSolidSphere(0.3, 17, 9)
        
        glPopMatrix()
        
    glPushMatrix()
    # -y is up in pyglet
    glTranslatef(0.0, 0.1, -2.5)
    
    if nShadow == 0:
        glColor3f(0.0, 0.0, 1.0)
    
    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 17, 9)
    glPopMatrix()
    
    if nShadow == 0:
        # Torus alone will be specular
        glColor3f(1.0, 0.0, 0.0)
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)
        
    glRotatef(yRot, 0.0, 1.0, 0.0)
    gltDrawTorus(0.35, 0.15, 61, 37)
    glMaterialfv(GL_FRONT, GL_SPECULAR, fNoLight)
    glPopMatrix()
コード例 #9
0
def DrawInhabitants(nShadow):
    global yRot
    if nShadow == 0:
        pass #yRot += 0.5
    else:
        glColor3f(0.0, 0.0, 0.0)

    
    # Draw the randomly located spheres
    if nShadow == 0:
        glColor3f(0.0, 1.0, 0.0)

    for sphere in spheres:
        glPushMatrix()
        
        sphere.ApplyActorTransform()
        glutSolidSphere(0.3, 17, 9)
        
        glPopMatrix()
        
    glPushMatrix()
    # -y is up in pyglet
    glTranslatef(0.0, 0.1, -2.5)
    
    if nShadow == 0:
        glColor3f(0.0, 0.0, 1.0)
    
    glPushMatrix()
    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 17, 9)
    glPopMatrix()
    
    if nShadow == 0:
        # Torus alone will be specular
        glColor3f(1.0, 0.0, 0.0)
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)
        
    glRotatef(yRot, 0.0, 1.0, 0.0)
    gltDrawTorus(0.35, 0.15, 61, 37)
    glMaterialfv(GL_FRONT, GL_SPECULAR, fNoLight)
    glPopMatrix()
コード例 #10
0
def DrawGLScene():
    # Clear the window with the current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    glPushMatrix()

    frameCamera.ApplyCameraTransform()

    # Draw the ground
    DrawGround()

    # Draw the randomly located spheres
    for sphere in spheres:
        glPushMatrix()

        sphere.ApplyActorTransform()
        glutSolidSphere(0.1, 13, 26)

        glPopMatrix()

    glPushMatrix()

    glTranslatef(0.0, 0.0, -2.5)

    glPushMatrix()

    glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
    glTranslatef(1.0, 0.0, 0.0)
    glutSolidSphere(0.1, 13, 26)

    glPopMatrix()

    glRotatef(yRot, 0.0, 1.0, 0.0)
    gltDrawTorus(0.35, 0.15, 40, 20)

    glPopMatrix()

    glPopMatrix()

    glutSwapBuffers()
コード例 #11
0
    def on_draw(self):
        # Clear the window with the current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glPushMatrix()
        
        frameCamera.ApplyCameraTransform()
        
        # Draw the ground
        DrawGround()
        
        # Draw the randomly located spheres
        for sphere in spheres:
            glPushMatrix()
            
            sphere.ApplyActorTransform()
            glutSolidSphere(0.1, 13, 26)
            
            glPopMatrix()

        glPushMatrix()
        
        glTranslatef(0.0, 0.0, -2.5)

        glPushMatrix()
        
        glRotatef(-yRot * 2.0, 0.0, 1.0, 0.0)
        glTranslatef(1.0, 0.0, 0.0)
        glutSolidSphere(0.1, 13, 26)
            
        glPopMatrix()

        glRotatef(yRot, 0.0, 1.0, 0.0)
        gltDrawTorus(0.35, 0.15, 40, 20)
            
        glPopMatrix()
        
        glPopMatrix()
コード例 #12
0
def InitGL(Width, Height):
        global mShadowMatrix 
        
        # pyglet reverses y axis
        vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0),
                                     (10.0, -0.4, 0.0),
                                     (5.0,-0.4, -5.0)
                                    )
        
        # Grayish background
        glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3])
        
        # Clear stencil buffer with zero, increment by one whenever anybody
        # draws into it. When stencil function is enabled, only write where
        # stencil value is zero. This prevents the transparent shadow from drawing
        # over itself
        glStencilOp(GL_INCR, GL_INCR, GL_INCR)
        glClearStencil(0)
        glStencilFunc(GL_EQUAL, 0x0, 0x01)

        # Cull backs of polygons
        glCullFace(GL_BACK)
        glFrontFace(GL_CCW)
        glEnable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_MULTISAMPLE_ARB)
        
        # Setup light parameters
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight)
        glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight)
        glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        
        # TODO: this doesn't seem to be enough to make this work on my computer?
        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)


        # Calculate shadow matrix
        pPlane = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2])
        mShadowMatrix = m3dMakePlanarShadowMatrix(pPlane, fLightPos)
        # Mostly use material tracking
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)
        glMateriali(GL_FRONT, GL_SHININESS, 128)
      
        # Randomly place sphere inhabitants
        for sphere in spheres:
            # Pick a random location between -20 and 20 at .1 increments
            sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)

        # Set up texture maps
        glEnable(GL_TEXTURE_2D)
        glGenTextures(NUM_TEXTURES, textureObjects)
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
        
        for iLoop in range(0, NUM_TEXTURES):        
            glBindTexture(GL_TEXTURE_2D, textureObjects[iLoop])
            
            # Load this texture map
            img = Image.open(szTextureFiles[iLoop]).convert("RGB")
            raw_image = img.tobytes()
            gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, img.width, img.height, GL_RGB, GL_UNSIGNED_BYTE, raw_image)
            
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)

        # Create display lists
        firstlist = glGenLists(3)
        groundList = GLuint(firstlist)
        sphereList = GLuint(firstlist + 1)
        torusList = GLuint(firstlist + 2)
        print (firstlist)
        # Create sphere display list
        glNewList(sphereList, GL_COMPILE)
        glutSolidSphere(0.1, 40, 20)
        glEndList()

        # Create torus display list
        glNewList(torusList, GL_COMPILE)
        gltDrawTorus(0.35, 0.15, 61, 37)
        glEndList()
        
        # Create the ground display list
        glNewList(groundList, GL_COMPILE)
        DrawGround()
        glEndList()
コード例 #13
0
    def __init__(self, *args, **kwargs):
        global groundList, sphereList, torusList
        window.Window.__init__(self, *args, **kwargs)
        
        # pyglet reverses y axis
        vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0),
                                     (10.0, -0.4, 0.0),
                                     (5.0,-0.4, -5.0)
                                    )
        
        # Grayish background
        glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3])
        
        # Clear stencil buffer with zero, increment by one whenever anybody
        # draws into it. When stencil function is enabled, only write where
        # stencil value is zero. This prevents the transparent shadow from drawing
        # over itself
        glStencilOp(GL_INCR, GL_INCR, GL_INCR)
        glClearStencil(0)
        glStencilFunc(GL_EQUAL, 0x0, 0x01)

        # Cull backs of polygons
        glCullFace(GL_BACK)
        glFrontFace(GL_CCW)
        glEnable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_MULTISAMPLE_ARB)
        
        # Setup light parameters
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight)
        glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight)
        glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        
        # TODO: this doesn't seem to be enough to make this work on my computer?
        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)


        # Calculate shadow matrix
        pPlane = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2])
        mShadowMatrix = m3dMakePlanarShadowMatrix(pPlane, fLightPos)
        # Mostly use material tracking
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight)
        glMateriali(GL_FRONT, GL_SHININESS, 128)
      
        # Randomly place sphere inhabitants
        for sphere in spheres:
            # Pick a random location between -20 and 20 at .1 increments
            sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)

        # Set up texture maps
        glEnable(GL_TEXTURE_2D)
        glGenTextures(NUM_TEXTURES, textureObjects)
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
        
        for iLoop in range(0, NUM_TEXTURES):        
            glBindTexture(GL_TEXTURE_2D, textureObjects[iLoop])
            
            # Load this texture map
            img = pyglet.image.load(szTextureFiles[iLoop])
            
            gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, img.width, img.height, GL_RGB, GL_UNSIGNED_BYTE, img.get_data('RGB', img.pitch))
            
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)

        # Create display lists
        firstlist = glGenLists(3)
        groundList = GLuint(firstlist)
        sphereList = GLuint(firstlist + 1)
        torusList = GLuint(firstlist + 2)
        print firstlist
        # Create sphere display list
        glNewList(sphereList, GL_COMPILE)
        glutSolidSphere(0.1, 40, 20)
        glEndList()

        # Create torus display list
        glNewList(torusList, GL_COMPILE)
        gltDrawTorus(0.35, 0.15, 61, 37)
        glEndList()
        
        # Create the ground display list
        glNewList(groundList, GL_COMPILE)
        DrawGround()
        glEndList()