Exemplo n.º 1
0
    def paintEvent(self, event):
        self.makeCurrent()

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()

        self.setClearColor(self.Purple.darker())
        gl.glShadeModel(gl.GL_SMOOTH)
        gl.glEnable(gl.GL_DEPTH_TEST)
        #gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_MULTISAMPLE)
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (0.5, 5.0, 7.0, 1.0))

        self.setupViewport(self.width(), self.height())

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()
        gl.glTranslated(0.0, 0.0, -10.0)
        gl.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
        gl.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
        gl.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
        gl.glCallList(self.object)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPopMatrix()

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.end()
Exemplo n.º 2
0
    def drawBox(self):
        gl.glTranslatef(self.pos[0], self.pos[1], self.pos[2])

        x, y, z, r = self.rot.getAngleAxis()
        gl.glRotatef(r, x, y, z)

        gl.glCallList(self.listId)
Exemplo n.º 3
0
Arquivo: gl.py Projeto: saluk/pywright
 def _render(self,redo=False):
     og.glColor4f(*self.color)
     if not pygame.DISPLAY_LIST: 
         self.dlist = None
     if not pygame.DISPLAY_LIST or redo or not self.dlist or not og.glIsList(self.dlist):
         if pygame.DISPLAY_LIST:
             self.dlist = og.glGenLists(1)
             og.glNewList(self.dlist,og.GL_COMPILE)
             #print "create list",self
         sp,ep = self._rect
         og.glEnable(og.GL_TEXTURE_2D)
         self.texture.use()
         og.glBegin(og.GL_QUADS)
         og.glTexCoord2f(sp[0],ep[1])
         og.glVertex3f(0,-1,0)
         og.glTexCoord2f(ep[0],ep[1])
         og.glVertex3f(1,-1,0)
         og.glTexCoord2f(ep[0],sp[1])
         og.glVertex3f(1,0,0)
         og.glTexCoord2f(sp[0],sp[1])
         og.glVertex3f(0,0,0)
         og.glEnd()
         og.glDisable(og.GL_TEXTURE_2D)
         if pygame.DISPLAY_LIST:
             og.glEndList()
     if pygame.DISPLAY_LIST:
         og.glCallList(self.dlist)
 def render(self):
     """
         Render the scene using the sphere display list
     """
     if self.do_exit:
         print('renderer exiting ...')
         # glut event loop needs hard exit ...
         sys.exit(0)
     if self.bodies is None:
         time.sleep(1 / self.fps)
         return
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     x_size = GLUT.glutGet(GLUT.GLUT_WINDOW_WIDTH)
     y_size = GLUT.glutGet(GLUT.GLUT_WINDOW_HEIGHT)
     GLU.gluPerspective(60, float(x_size) / float(y_size), 0.05, 10)
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     GL.glTranslatef(-_CAMERA_POSITION[0], -_CAMERA_POSITION[1],
                     -_CAMERA_POSITION[2])
     self.mouse_interactor.apply_transformation()
     for body_index in range(self.bodies.shape[0]):
         body = self.bodies[body_index, :]
         GL.glPushMatrix()
         GL.glTranslatef(body[0], body[1], body[2])
         GL.glScalef(body[3], body[3], body[3])
         GL.glCallList(self.sphere)
         GL.glPopMatrix()
     GLUT.glutSwapBuffers()
Exemplo n.º 5
0
    def display(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # do zoom
        glu.gluLookAt(0.0, 0.0, self.zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        # do rotation
        for x_rot, y_rot in reversed(self.rotations):
            gl.glRotatef(math.sqrt(x_rot**2 + y_rot**2), y_rot, x_rot, 0)
        #gl.glRotate(x_rot, 0, 1, 0)
        #gl.glRotate(y_rot, 1, 0, 0)

        """
        one, two, three, four = (1, 1, 0), (1, -1, 0), (-1, -1, 0), (-1, 1, 0)
        draw_element(chemistry.elements[0], one)
        draw_single_bond(one, two)
        draw_element(chemistry.elements[0], two)
        draw_double_bond(two, three)
        draw_element(chemistry.elements[0], three)
        draw_triple_bond(three, four)
        draw_element(chemistry.elements[0], four)
        draw_quadruple_bond(four, one)
        """
        #self.draw_atoms(self.molecule)
        gl.glCallList(self.displist)

        #gl.glFlush()
        glut.glutSwapBuffers()
Exemplo n.º 6
0
    def drawObjects(self):
        if self.poly:
            if self.graph:
                self.gb.determineVisGraphPlanes(self.camera.phi,
                                                self.camera.theta)

            if self.animate:
                if self.axis is 'x':
                    GL.glRotate(self.rotation, 1, 0, 0)
                if self.axis is 'y':
                    GL.glRotate(self.rotation, 0, 0, 1)
                if self.axis is 'z':
                    GL.glRotate(self.rotation, 0, 1, 0)
                self.rotation += 1

            GL.glCallList(self.Neuron)

        else:
            if len(self.vertices_gl) > 0:
                GL.glPushMatrix()
                self.vertices_gl.bind()

                GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
                GL.glVertexPointer(3, GLUT.GL_FLOAT, 0, self.vertices_gl)

                self.colors_gl.bind()
                GL.glEnableClientState(GL.GL_COLOR_ARRAY)
                GL.glColorPointer(3, GLUT.GL_FLOAT, 0, self.colors_gl)

                GL.glDrawArrays(GL.GL_LINES, 0, len(self.vertices_gl))
                GL.glPopMatrix()
Exemplo n.º 7
0
Arquivo: box.py Projeto: myme/PyCube
    def drawBox(self):
        gl.glTranslatef(self.pos[0], self.pos[1], self.pos[2])

        x, y, z, r = self.rot.getAngleAxis()
        gl.glRotatef( r, x, y, z )

        gl.glCallList(self.listId)
Exemplo n.º 8
0
    def billboardLabel(self, objPos, character, offset, scale):

        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
        GL.glColor4f(self.textColour[0], self.textColour[1],
                     self.textColour[2], 1.0)

        GL.glEnable(GL.GL_TEXTURE_2D)

        GL.glPushMatrix()

        GL.glTranslate(objPos[0], objPos[1], objPos[2])

        modelview = (GL.GLfloat * 16)()
        mvm = GL.glGetFloatv(GL.GL_MODELVIEW_MATRIX, modelview)

        for i in (0, 1, 2):
            for j in (0, 1, 2):
                if i is j:
                    modelview[i * 4 + j] = 1
                else:
                    modelview[i * 4 + j] = 0

        GL.glLoadMatrixf(mvm)

        GL.glScalef(scale, scale, scale)
        GL.glTranslate(offset, 0, 0)

        GL.glCallList(self.fonts[character])

        GL.glPopMatrix()
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glDisable(GL.GL_BLEND)
Exemplo n.º 9
0
 def setObject(self, name, object, tx, ty, tz):
     gl.glPushName(name)
     gl.glPushMatrix()
     gl.glTranslate(tx, ty, tz)
     gl.glCallList(object.gl_list)
     gl.glPopMatrix()
     gl.glPopName()
Exemplo n.º 10
0
def add_object_seg(filename,
                   xyz,
                   unit,
                   up_string,
                   front_string,
                   center,
                   angle,
                   size,
                   segment_id,
                   obj_info,
                   layout_type=None):
    GL.glPushMatrix()
    x = xyz[0]
    y = xyz[1]
    z = xyz[2]
    # translate in view
    if layout_type is not None:
        GL.glTranslatef(center[0], center[1], center[2])
    else:
        GL.glTranslatef(center[0], center[1], center[2] - size[2] / 2)
    GL.glRotate(angle, 0, 1, 0)
    GL.glScalef(size[0] * 100 / x, size[1] * 100 / y, size[2] * 100 / z)
    # normalize directions, rotate object to front: front -> 0,0,1 | up -> 0,1,0
    alignment = align_directions(up_string, front_string)
    if not alignment:
        GL.glPopMatrix()
        return
    # obj = OBJ_NORMAL(filename, swapyz=False)
    obj = OBJ_SEG(obj_info['info'],
                  color=[segment_id / 255.0, 0.0, 0.0],
                  swapyz=False)
    GL.glCallList(obj.gl_list)
    GL.glPopMatrix()
Exemplo n.º 11
0
    def paintScene(self):
        '''Does the actuall object rendering calls.
        '''
        # rotate view
        GL.glPushMatrix()
        GL.glRotatef(self.xRot / 16.0, 1.0, 0.0, 0.0)
        GL.glRotatef(self.yRot / 16.0, 0.0, 1.0, 0.0)
        GL.glRotatef(self.zRot / 16.0, 0.0, 0.0, 1.0)

        # pan
        mtx = np.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX))
        A = mtx[0:3, 0:2]
        x = np.transpose(np.array([[self._xPan, self._yPan]]))
        b = np.dot(A, x)
        GL.glTranslatef(b[0], b[1], b[2])

        # zoom
        GL.glScale(self._vScale, self._vScale, self._vScale)

        # render all non-cacheable first
        if len(self._glList_nonCacheable):
            for desc in self._glList_nonCacheable:
                desc.run()

        # use cached list for mouse interactions
        try:
            GL.glCallList(self._glList_cache)
        except:
            log.node(traceback.format_exc())
            self._glError_cnt += 1

        # rotate view
        GL.glPopMatrix()
Exemplo n.º 12
0
    def to_OpenGL_2(self):        
        for y in range(self.yres - 1):
            for x in range(self.xres - 1):
#                print "z[%f][%f]=%f" % (self.y[y],self.x[x],self.buf[y][x])
                if self.buf[y+0][x+0].changed or self.buf[y+0][x+1].changed \
                        or self.buf[y+1][x+0].changed \
                        or self.buf[y+1][x+1].changed:
                    if self.buf[y][x].list == -1:
                        self.buf[y][x].list = GL.glGenLists(1)

                    GL.glNewList(self.buf[y][x].list, GL.GL_COMPILE)
                    GL.glBegin(GL.GL_QUADS)
                    n = self.normal(self.buf[y+0][x+0].z, self.buf[y+0][x+1].z,
                            self.buf[y+1][x+0].z)
                    GL.glNormal3f(n[0], n[1], n[2])
                    GL.glVertex3f(self.x[x+0], self.y[y+0],
                            self.buf[y+0][x+0].z)
                    GL.glVertex3f(self.x[x+1], self.y[y+0],
                            self.buf[y+0][x+1].z)
                    GL.glVertex3f(self.x[x+1], self.y[y+1],
                            self.buf[y+1][x+1].z)
                    GL.glVertex3f(self.x[x+0], self.y[y+1],
                            self.buf[y+1][x+0].z)
                    GL.glEnd()
                    GL.glEndList()
                
        for y in range(0, self.yres-1):
            for x in range(0, self.xres-1):
                self.buf[y][x].changed = False
                GL.glCallList(self.buf[y][x].list)
Exemplo n.º 13
0
    def drawAircraft(self):
        if self.flag_show_compnt :
            GL.glColor3fv([1.0, 0.0, 0.0])
            GL.glCallList(self.index+5)

        if self.flag_show_flap_TE_Device :
            GL.glCallList(self.index+6)
        
        if self.flag_show_flap_LE_Device :
            GL.glCallList(self.index+7)
        
        if self.flag_show_flap_spoiler :
            GL.glCallList(self.index+8)            
            
        if self.flag_show_spars :
            GL.glCallList(self.index+9)
        
        if self.flag_show_wing1_up :  
            self.draw(self.data.pList_wing_up, self.data.pList_wing_up_normals, [0.0, 0.5, 0.8,self.alpha_rgb], 1, self.selectionList.wingUpIsEmpty())
            
        if self.flag_show_wing1_lo :
            self.draw(self.data.pList_wing_lo, self.data.pList_wing_lo_normals, [0.0, 0.5, 0.8,self.alpha_rgb], 2, self.selectionList.wingLoIsEmpty())
        
        if self.flag_show_wing2_up :
            self.draw(self.data.pList_wing_up_reflect, self.data.pList_wing_up_reflect_normals, [0.75164, 0.60648, 0.22648,1.0], 3, self.selectionList.wingUpRIsEmpty())
            
        if self.flag_show_wing2_lo :
            self.draw(self.data.pList_wing_lo_reflect, self.data.pList_wing_lo_reflect_normals, [0.75164, 0.60648, 0.22648,1.0], 4, self.selectionList.wingLoRIsEmpty())
        
        if self.flag_show_fuselage :
            self.draw(self.data.pList_fuselage, self.data.pList_fuselage_normals, [0.0, 0.5, 0.8,self.alpha_rgb], 0, self.selectionList.fuseIsEmpty())        
Exemplo n.º 14
0
 def to_OpenGL(self, visible_filter=None, show_directions=False):
     if not GL_enabled:
         return
     if not visible_filter is None:
         for item in self.next():
             # ignore invisble things like the normal of a ContourModel
             if hasattr(item, "to_OpenGL"):
                 do_paint, color = visible_filter(item)
                 if do_paint:
                     item.to_OpenGL(color, show_directions=show_directions)
     elif not show_directions in self._opengl_display_cache:
         # compile an OpenGL display list
         # Rendering a display list takes less than 5% of the time for a
         # complete rebuild.
         list_index = GL.glGenLists(1)
         if list_index > 0:
             self._opengl_display_cache[show_directions] = list_index
             # somehow "GL_COMPILE_AND_EXECUTE" fails - we render it later
             GL.glNewList(list_index, GL.GL_COMPILE)
         for item in self.next():
             # ignore invisble things like the normal of a ContourModel
             if hasattr(item, "to_OpenGL"):
                 item.to_OpenGL(show_directions=show_directions)
         if list_index > 0:
             GL.glEndList()
             GL.glCallList(list_index)
     else:
         # render a previously compiled display list
         GL.glCallList(self._opengl_display_cache[show_directions])
Exemplo n.º 15
0
    def paintGL(self):
        """
        OpenGL Lifecycle method. Do not change name. 
        """
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # Centers on the model
        gl.glTranslate(self.x_pos, self.y_pos, self.zoom)

        # Rotates model around its center
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glTranslate(self.object_center.x, self.object_center.y,
                       self.object_center.z)

        gl.glRotated(self.x_rot / 16.0, 1.0, 0.0, 0.0)
        gl.glRotated(self.y_rot / 16.0, 0.0, 1.0, 0.0)
        gl.glRotated(self.z_rot / 16.0, 0.0, 0.0, 1.0)

        gl.glTranslate(-self.object_center.x, -self.object_center.y,
                       -self.object_center.z)

        if self.object is not None:
            gl.glCallList(self.object)
        if self.sound_source is not None:
            gl.glPointSize(10)
            gl.glBegin(gl.GL_POINTS)
            gl.glColor3f(1.0, 0, 0)
            gl.glVertex3fv(self.sound_source.vec)
            gl.glEnd()
        if self.rays is not None:
            gl.glCallList(self.rays)

        gl.glPopMatrix()
Exemplo n.º 16
0
 def draw( self ):
     GL.glPushMatrix()
     
     GL.glTranslatef( *self.__real_position )
     GL.glCallList( self.__gllist )
     
     GL.glPopMatrix()
Exemplo n.º 17
0
def load_and_draw_model(filename):
    ''' Loads a model from an .obj file using objloader.py.
      Assumes there is a .mtl material file with the same name. '''
    GL.glEnable(GL.GL_LIGHTING)
    GL.glEnable(GL.GL_LIGHT0)
    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glEnable(GL.GL_COLOR_MATERIAL)
    GL.glShadeModel(GL.GL_SMOOTH)
    GL.glClear(GL.GL_DEPTH_BUFFER_BIT)


    # set model color
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0,0,0,0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [0.5,0.75,1.0,0.0])
    GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [0.7, 0.6, 0.6, 0.0])
    GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 0.25*128.0)

    # load from a file
    import objloader
    obj = objloader.OBJ(filename,swapyz=True)
    size = 0.01
    angle = [-0,0,0]
    GL.glScalef(size, size, size)
    GL.glRotatef(angle[0], 1, 0, 0)
    GL.glRotatef(angle[1], 0, 1, 0)
    GL.glRotatef(angle[2], 0, 0, 1)
    GL.glCallList(obj.gl_list)
Exemplo n.º 18
0
    def to_OpenGL_2(self):
        for y in range(self.yres - 1):
            for x in range(self.xres - 1):
                if self.buf[y+0][x+0].changed or self.buf[y+0][x+1].changed \
                        or self.buf[y+1][x+0].changed \
                        or self.buf[y+1][x+1].changed:
                    if self.buf[y][x].list == -1:
                        self.buf[y][x].list = GL.glGenLists(1)

                    GL.glNewList(self.buf[y][x].list, GL.GL_COMPILE)
                    GL.glBegin(GL.GL_QUADS)
                    n = self.normal(self.buf[y + 0][x + 0].z,
                                    self.buf[y + 0][x + 1].z,
                                    self.buf[y + 1][x + 0].z)
                    GL.glNormal3f(n[0], n[1], n[2])
                    GL.glVertex3f(self.x[x + 0], self.y[y + 0],
                                  self.buf[y + 0][x + 0].z)
                    GL.glVertex3f(self.x[x + 1], self.y[y + 0],
                                  self.buf[y + 0][x + 1].z)
                    GL.glVertex3f(self.x[x + 1], self.y[y + 1],
                                  self.buf[y + 1][x + 1].z)
                    GL.glVertex3f(self.x[x + 0], self.y[y + 1],
                                  self.buf[y + 1][x + 0].z)
                    GL.glEnd()
                    GL.glEndList()

        for y in range(0, self.yres - 1):
            for x in range(0, self.xres - 1):
                self.buf[y][x].changed = False
                GL.glCallList(self.buf[y][x].list)
Exemplo n.º 19
0
 def display(self):
     self.rotation_angle += self.rotation_angle_speed
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_BLEND)
     #gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
     if self.orbit == None:
         x,y,z=self.position
     else:
         #print'Next'
         x,y,z=self.orbit[self.orbit_index]
         if self.orbit_index < len(self.orbit)-1:
             self.orbit_index+=1
         else:
             self.orbit_index=0
     gl.glPushMatrix()
     gl.glTranslatef(x,y,z)               
     gl.glRotatef(self.rotation_angle,0,0,1)
     #gl.glColor4f(1,0,0,0.5)
     gl.glCallList(self.list_index)
     gl.glPopMatrix()
     #gl.glTranslatef(100,0.,0.)               
     gl.glPushMatrix()
     gl.glTranslatef(x,y,z)               
     #gl.glColor4f(1,1,0,0.4)
     gl.glRotatef(2*self.rotation_angle,0,0,1)
     gl.glCallList(self.list_index)
     gl.glPopMatrix()
Exemplo n.º 20
0
    def paintScene(self):
        '''Does the actuall object rendering calls.
        '''
        # rotate view
        GL.glPushMatrix()
        GL.glRotatef(self.xRot / 16.0, 1.0, 0.0, 0.0)
        GL.glRotatef(self.yRot / 16.0, 0.0, 1.0, 0.0)
        GL.glRotatef(self.zRot / 16.0, 0.0, 0.0, 1.0)

        # pan
        mtx = np.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX))
        A = mtx[0:3, 0:2]
        x = np.transpose(np.array([[self._xPan, self._yPan]]))
        b = np.dot(A, x)
        GL.glTranslatef(b[0], b[1], b[2])

        # zoom
        GL.glScale(self._vScale, self._vScale, self._vScale)

        # render all non-cacheable first
        if len(self._glList_nonCacheable):
            for desc in self._glList_nonCacheable:
                desc.run()

        # use cached list for mouse interactions
        try:
            GL.glCallList(self._glList_cache)
        except:
            log.node(traceback.format_exc())
            self._glError_cnt += 1

        # rotate view
        GL.glPopMatrix()
Exemplo n.º 21
0
    def display(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # do zoom
        glu.gluLookAt(0.0, 0.0, self.zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        # do rotation
        for x_rot, y_rot in reversed(self.rotations):
            gl.glRotatef(math.sqrt(x_rot**2 + y_rot**2), y_rot, x_rot, 0)
        #gl.glRotate(x_rot, 0, 1, 0)
        #gl.glRotate(y_rot, 1, 0, 0)
        """
        one, two, three, four = (1, 1, 0), (1, -1, 0), (-1, -1, 0), (-1, 1, 0)
        draw_element(chemistry.elements[0], one)
        draw_single_bond(one, two)
        draw_element(chemistry.elements[0], two)
        draw_double_bond(two, three)
        draw_element(chemistry.elements[0], three)
        draw_triple_bond(three, four)
        draw_element(chemistry.elements[0], four)
        draw_quadruple_bond(four, one)
        """
        #self.draw_atoms(self.molecule)
        gl.glCallList(self.displist)

        #gl.glFlush()
        glut.glutSwapBuffers()
Exemplo n.º 22
0
 def to_OpenGL(self, visible_filter=None, show_directions=False):
     if not GL_enabled:
         return
     if not visible_filter is None:
         for item in self.next():
             # ignore invisble things like the normal of a ContourModel
             if hasattr(item, "to_OpenGL"):
                 do_paint, color = visible_filter(item)
                 if do_paint:
                     item.to_OpenGL(color, show_directions=show_directions)
     elif not show_directions in self._opengl_display_cache:
         # compile an OpenGL display list
         # Rendering a display list takes less than 5% of the time for a
         # complete rebuild.
         list_index = GL.glGenLists(1)
         if list_index > 0:
             self._opengl_display_cache[show_directions] = list_index
             # somehow "GL_COMPILE_AND_EXECUTE" fails - we render it later
             GL.glNewList(list_index, GL.GL_COMPILE)
         for item in self.next():
             # ignore invisble things like the normal of a ContourModel
             if hasattr(item, "to_OpenGL"):
                 item.to_OpenGL(show_directions=show_directions)
         if list_index > 0:
             GL.glEndList()
             GL.glCallList(list_index)
     else:
         # render a previously compiled display list
         GL.glCallList(self._opengl_display_cache[show_directions])
Exemplo n.º 23
0
    def render(self):
        # make or render display list
        if self.display_list_index is None:
            self.display_list_index = gl.glGenLists(1)
            gl.glNewList(self.display_list_index, gl.GL_COMPILE)

            gl.glDisable(gl.GL_LIGHTING)

            # render lines
            for i in range(0, self.num_lines + 1):
                ypos = i * (self.bright_linewidth + self.dark_linewidth)

                # render bright line
                gl.glColor3f(*self.bright_color)
                gl.glRectf(0, ypos, self.width, ypos + self.bright_linewidth)

                # render dark line
                gl.glColor3f(*self.dark_color)
                gl.glRectf(0, ypos + self.bright_linewidth, self.width, ypos + self.bright_linewidth + self.dark_linewidth)

            gl.glEnable(gl.GL_LIGHTING)
            gl.glEndList()
            gl.glCallList(self.display_list_index)

        else:
            gl.glCallList(self.display_list_index)
Exemplo n.º 24
0
 def draw_scene(self):
     #inspect all self.objects, and execute only those that have visibility=True, inspect all lights and execute those ones activated. Execute the ambient light
     #camera
     #lights
     for light_index in self.lights:
         #print "Drawing light", light_index
         light=self.lights[light_index]
         if light.activated:
             _gl.glCallList(light.get_gl_list())
             _gl.glEnable(light.light_number)
     for object_index in self.objects:
         #print "Drawing object:", object_index
         object=self.objects[object_index]
         if object.visibility:
             _gl.glPushMatrix()
             if object.scale != None:
                 _gl.glEnable(_gl.GL_NORMALIZE)
             _gl.glMultMatrixf(object.trans_rot_matrix.T)
             if object.scale != None:
                 _gl.glScale(object.scale[0],object.scale[1],object.scale[2])
             if object.material_specular_color != None:
                 _gl.glMaterialfv(_gl.GL_FRONT,_gl.GL_SPECULAR, object.material_specular_color)
             if object.material_shininess != None:
                 _gl.glMaterialf(_gl.GL_FRONT,_gl.GL_SHININESS, object.material_shininess)
             if object.material_ambient_color != None:
                 _gl.glMaterialfv(_gl.GL_FRONT,_gl.GL_AMBIENT, object.material_ambient_color)
             if object.material_diffuse_color != None:
                 _gl.glMaterialfv(_gl.GL_FRONT,_gl.GL_DIFFUSE, object.material_diffuse_color)
             _gl.glCallList(object.get_gl_list())
             if object.scale != None:
                 _gl.glDisable(_gl.GL_NORMALIZE)
             _gl.glPopMatrix()
Exemplo n.º 25
0
 def pick_actors(self):
     """Set the list of actors inside the pick_window."""
     self.camera.loadProjection(pick=self.pick_window)
     self.camera.loadModelView()
     stackdepth = 1
     npickable = len(self.actors)
     selbuf = GL.glSelectBuffer(npickable*(3+stackdepth))
     GL.glRenderMode(GL.GL_SELECT)
     GL.glInitNames()
     for i,a in enumerate(self.actors):
         GL.glPushName(i)
         GL.glCallList(a.list)
         GL.glPopName()
     libGL.glRenderMode(GL.GL_RENDER)
     # Read the selection buffer
     store_closest = self.selection_filter == 'single' or \
                     self.selection_filter == 'closest'
     self.picked = []
     if selbuf[0] > 0:
         buf = asarray(selbuf).reshape(-1,3+selbuf[0])
         buf = buf[buf[:,0] > 0]
         self.picked = buf[:,3]
         if store_closest:
             w = buf[:,1].argmin()
             self.closest_pick = (self.picked[w], buf[w,1])
Exemplo n.º 26
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glEnable(GLWidget.GL_MULTISAMPLE)
        GL.glTranslatef( -0.25, -0.10, 0.0)
        GL.glScalef(0.75, 1.15, 0.0)
        GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0)
        GL.glCallList(self.list_)
        GL.glPopMatrix()

        GL.glPushMatrix()
        GL.glDisable(GLWidget.GL_MULTISAMPLE)
        GL.glTranslatef(0.25, -0.10, 0.0)
        GL.glScalef(0.75, 1.15, 0.0)
        GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0)
        GL.glCallList(self.list_)
        GL.glPopMatrix()

        GLWidget.rot += 0.2

        self.qglColor(QtCore.Qt.black)
        self.renderText(-0.35, 0.4, 0.0, "Multisampling enabled")
        self.renderText(0.15, 0.4, 0.0, "Multisampling disabled")
Exemplo n.º 27
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glEnable(GLWidget.GL_MULTISAMPLE)
        GL.glTranslatef(-0.25, -0.10, 0.0)
        GL.glScalef(0.75, 1.15, 0.0)
        GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0)
        GL.glCallList(self.list_)
        GL.glPopMatrix()

        GL.glPushMatrix()
        GL.glDisable(GLWidget.GL_MULTISAMPLE)
        GL.glTranslatef(0.25, -0.10, 0.0)
        GL.glScalef(0.75, 1.15, 0.0)
        GL.glRotatef(GLWidget.rot, 0.0, 0.0, 1.0)
        GL.glCallList(self.list_)
        GL.glPopMatrix()

        GLWidget.rot += 0.2

        self.qglColor(QtCore.Qt.black)
        self.renderText(-0.35, 0.4, 0.0, "Multisampling enabled")
        self.renderText(0.15, 0.4, 0.0, "Multisampling disabled")
Exemplo n.º 28
0
def __Draw_Scene():
    global TOGGLE_FULLSCREEN,TOGGLE_LIGHTING,TOGGLE_3D,TOGGLE_WIREFRAME,TOGGLE_BONES,TOGGLE_ORTHO
    global __viewMatrix

    __GL.glMultMatrixf(__viewMatrix._getMtx())

    __GL.glDisable(__GL.GL_LIGHTING) #disable for the grid
    if TOGGLE_GRID<4:
        global __TOP_GRID,__SIDE_GRID,__FRONT_GRID,__QUAD_FLOOR
        __GL.glCallList([__TOP_GRID,__SIDE_GRID,__FRONT_GRID,__QUAD_FLOOR][TOGGLE_GRID])

    '''
    if TOGGLE_LIGHTING: __GL.glEnable(__GL.GL_LIGHTING)
    __GL.glCallList(__GL.__MODEL_DATA) #finally got display lists working =D

    if TOGGLE_LIGHTING: __GL.glDisable(__GL.GL_LIGHTING) #disable for the grid and bones
    if TOGGLE_BONES:
        if TOGGLE_BONES==2: __GL.glClear( __GL.GL_DEPTH_BUFFER_BIT ) #overlay the bones (X-Ray)
        __GL.glCallList(__BONE_DATA)
        for Name,Objects in Libs[4]: #de-scaled bone joints
            for ID in Objects:
                ObjectName,Viewport,LRS,Sub_Data,Parent_ID=Libs[5][ID]
                SDType,SDName,SDData1,SDData2=Sub_Data
                if SDType=="_Rig":
                    for bone in SDData2:
                        PLRS,CLRS = (SDData2[bone[4]][2] if type(bone[4])==int else [0,0,0,0,0,0,1,1,1]),bone[2]
                        __GL.glTranslate((CLRS[0]*CLRS[6]),(CLRS[1]*CLRS[7]),(CLRS[2]*CLRS[8]))
                        #glutSolidSphere(0.03/__viewMatrix._scale, 25, 25)
                        __GL.glTranslate(-(CLRS[0]*CLRS[6]),-(CLRS[1]*CLRS[7]),-(CLRS[2]*CLRS[8]))
    '''
    pass
Exemplo n.º 29
0
def draw_list(gl_list,
              pos=None,
              angle=0.0,
              rotation_list=None,
              scale_list=None,
              color_list=None):
    """
    Draw an opengl list.

    :param gl_list: OpenGL list
    :param pos: Position
    :param angle: Angle
    :param rotation_list: Rotation list
    :param scale_list: Scale list
    :param color_list: Color list
    :type pos: list, None
    :type angle: float, int
    :type rotation_list: list, None
    :type scale_list: list, None
    :type color_list: list, None
    """
    if pos is None:
        pos = [0.0, 0.0, 0.0]
    _gl.glPushMatrix()
    _gl.glTranslate(pos[0], pos[1], pos[2])
    if scale_list is not None:
        _gl.glScale(scale_list[0], scale_list[1], scale_list[2])
    if rotation_list is not None:
        _gl.glRotatef(angle, rotation_list[0], rotation_list[1],
                      rotation_list[2])
    if color_list is not None:
        _gl.glColor4fv(color_list)
    _gl.glCallList(gl_list)
    _gl.glPopMatrix()
Exemplo n.º 30
0
    def pick_actors(self,store_closest=False):
        """Set the list of actors inside the pick_window."""
        self.camera.loadProjection(pick=self.pick_window)
        self.camera.loadMatrix()
        stackdepth = 1
        npickable = len(self.actors)
        selbuf = GL.glSelectBuffer(npickable*(3+stackdepth))
        GL.glRenderMode(GL.GL_SELECT)
        GL.glInitNames()
        for i,a in enumerate(self.actors):
            GL.glPushName(i)
            GL.glCallList(a.list)
            GL.glPopName()
##         buf = GL.glRenderMode(GL.GL_RENDER)
##         self.picked = [ r[2][0] for r in buf]
##         if store_closest and len(buf) > 0:
##             d = asarray([ r[0] for r in buf ])
##             dmin = d.min()
##             w = where(d == dmin)[0][0]
##             self.closest_pick = (self.picked[w], dmin)
        libGL.glRenderMode(GL.GL_RENDER)
        # Read the selection buffer
        self.picked = []
        if selbuf[0] > 0:
            buf = asarray(selbuf).reshape(-1,3+selbuf[0])
            buf = buf[buf[:,0] > 0]
            self.picked = buf[:,3]
            if store_closest and len(buf) > 0:
                w = buf[:,1].argmin()
                self.closest_pick = (self.picked[w], buf[w,1])
Exemplo n.º 31
0
 def selectData(self, object, ipsData, start):
     gl.glPushMatrix()
     gl.glTranslate(ipsData[start]['x'], ipsData[start]['y'],
                    self.person_offset)
     gl.glRotate(180, 0.0, 0.0, 1.0)
     gl.glCallList(object.gl_list)
     gl.glPopMatrix()
Exemplo n.º 32
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()

        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, 50.0)
        GL.glLight(GL.GL_LIGHT0, GL.GL_AMBIENT, [0.3, 0.3, 0.3, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_DIFFUSE, [0.9, 0.9, 0.9, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_POSITION, [10.0, 0.0, 10.0, 0.0])
        GL.glEnable(GL.GL_LIGHTING)
        GL.glEnable(GL.GL_LIGHT0)

        GL.glEnable(GL.GL_NORMALIZE)
        
        GL.glTranslated(0.0, 0.0, -10.0)
        GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
        GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
        GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
        GL.glScale(self.scaleFactor,self.scaleFactor,self.scaleFactor)

        if self.object:
            GL.glCallList(self.object)
Exemplo n.º 33
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()

        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, 50.0)
        GL.glLight(GL.GL_LIGHT0, GL.GL_AMBIENT, [0.3, 0.3, 0.3, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_DIFFUSE, [0.9, 0.9, 0.9, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        GL.glLight(GL.GL_LIGHT0, GL.GL_POSITION, [10.0, 0.0, 10.0, 0.0])
        GL.glEnable(GL.GL_LIGHTING)
        GL.glEnable(GL.GL_LIGHT0)

        GL.glEnable(GL.GL_NORMALIZE)
        
        GL.glTranslated(0.0, 0.0, -10.0)
        GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
        GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
        GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
        GL.glScale(self.scaleFactor,self.scaleFactor,self.scaleFactor)

        if self.object:
            GL.glCallList(self.object)
Exemplo n.º 34
0
 def determineVisGraphPlanes(self, phi, theta):
     '''
     Front 0
     Back 1
     Top 2
     Bottom 3
     Left 4
     Right 5
     '''
     planes = [0, 1, 2, 3, 4, 5]
     if phi >= -90 and phi < 90:
         planes.remove(0)
     if phi >= 90 or phi < -90:
         planes.remove(1)
     if phi >= -180 and phi < 0:
         planes.remove(4)
     if phi >= 0 and phi < 180:
         planes.remove(5)
     if theta >= 0:
         planes.remove(2)
     else:
         planes.remove(3)
     for i in planes:
         GL.glCallList(self.Graph[i])
     self.drawAxisLabels(planes)
Exemplo n.º 35
0
def add_object(filename,
               xyz,
               unit,
               up_string,
               front_string,
               center,
               angle,
               size,
               obj_color,
               obj_info,
               layout_type=None):  # x_min,y_min,z_min,x_max,y_max,z_max
    GL.glPushMatrix()
    # after unit conversion...
    x = xyz[0]
    y = xyz[1]
    z = xyz[2]
    # print center, size
    # translate in view
    if layout_type is not None:
        GL.glTranslatef(center[0], center[1], center[2])
    else:
        GL.glTranslatef(center[0], center[1], center[2] - size[2] / 2)
    GL.glRotate(angle, 0, 1, 0)
    GL.glScalef(size[0] * 100 / x, size[1] * 100 / y,
                size[2] * 100 / z)  # x,y,z y is up
    # normalize directions, rotate object to front: front -> 0,0,1 | up -> 0,1,0
    alignment = align_directions(up_string, front_string)
    if not alignment:
        GL.glPopMatrix()
        return
    # obj = OBJ_NORMAL(filename, swapyz=False)
    obj = OBJ(obj_info['info'], obj_color=obj_color, swapyz=False)
    GL.glCallList(obj.gl_list)
    GL.glPopMatrix()
Exemplo n.º 36
0
    def OpenGLPaint(self, colorDrivenMaterial=None, useCallLists=True):
        if self.visible:
            # TODO: add support for updateOnlyFrom GrandparentJoints flag
#             localTransform = grandParentTransformMat
#             #set orientation
#             if not self.updateOnlyFromGrandparentJoints:
#                 localTransform *= self.joint.
#                 q = self.joint.orientation

            # set point size if required
            if self.displayAsPoints:
                GL.glPointSize(self.pointSize)

            # set up model material
            if colorDrivenMaterial is not None:
                GL.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, self.shininess)
                if colorDrivenMaterial:
                    GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE)
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, [0.0, 0.0, 0.0, 1.0])
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
                    GL.glColor4fv(self.ambientColor)
                else:
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, self.ambientColor)
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, self.diffuseColor)
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, self.emissionColor)
                    GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, self.specularColor)

            if self.textureID is not None:
                GL.glBindTexture(GL.GL_TEXTURE_2D, self.textureID)  # bind our texture to our shape

            if useCallLists:  # use call lists of original model, much faster for displaying
                # change openGL matrix to match model orientation and position
                GL.glPushMatrix()
                # matrix transformations steps: (applied in reverse order)
                # 1: move model initial joint (rotation) center to origin
                # 2: scale model
                # 3: rotate model to new orientation
                # 4: move model to parent joint position
#                 GL.glTranslatef(self.joint.location[0],self.joint.location[1],self.joint.location[2])
#                 GL.glMultMatrixf(numpy.array(q.toMat4()))
#                 scale = self.scale*self.joint.scale    #scale is combination of model scale and parent joint scale
#                 GL.glScalef(scale,scale,scale)
#                 GL.glTranslatef(-self.initialRotationCenter[0],-self.initialRotationCenter[1],-self.initialRotationCenter[2])

                if self.displayList is not None:
                    GL.glCallList(self.displayList)

                # go back to default matrix
                GL.glPopMatrix()
            else:  # don't use call lists, display recalculated vertexes
                # TODO: test how scaling works when vertexes are recalculated
                # TODO: Test how joint translation works
                GL.glBegin(GL.GL_TRIANGLES)
                for i in xrange(len(self.TriangleVertexIndexList)):
                    GL.glNormal3fv(self.NormVectors[i])
                    GL.glVertex3fv(self.VertexList[self.TriangleVertexIndexList[i, 0]])
                    GL.glVertex3fv(self.VertexList[self.TriangleVertexIndexList[i, 1]])
                    GL.glVertex3fv(self.VertexList[self.TriangleVertexIndexList[i, 2]])
                GL.glEnd()
Exemplo n.º 37
0
 def paintGL(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glLoadIdentity()
     gl.glTranslatef(self.translateX, self.translateY, self.zoom)
     gl.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     gl.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     gl.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     gl.glCallList(self.object)
Exemplo n.º 38
0
 def render(self):
     ''' virtual method
     must be implemented by derivated class to do the render of the mesh.
     as each importer can store data on its own way, this setup makes 
     the implementation more flexible, allowing for using GL coding
     mechanisms that would speed up the render of different file formats.'''    
     if self.glList:
         GL.glCallList(self.glList)
Exemplo n.º 39
0
 def paintGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glLoadIdentity()
     GL.glTranslated(0.0, 0.0, -10.0)
     GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     GL.glCallList(self.object)
Exemplo n.º 40
0
    def draw(self):
        if self._displayList is None:
           self._displayList = GL.glGenLists(1)

        if self.invalidList:
            self.compileList()

        GL.glCallList(self._displayList)
Exemplo n.º 41
0
    def draw(self):
        if self._displayList is None:
            self._displayList = GL.glGenLists(1)

        if self.invalidList:
            self.compileList()

        GL.glCallList(self._displayList)
Exemplo n.º 42
0
 def paintGL(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glLoadIdentity()
     gl.glTranslatef(self.x_pos, self.y_pos, self.z_pos)
     gl.glRotated(self.xRot, 1.0, 0.0, 0.0)
     gl.glRotated(self.yRot, 0.0, 1.0, 0.0)
     gl.glRotated(self.zRot, 0.0, 0.0, 1.0)
     gl.glCallList(self.object)
Exemplo n.º 43
0
 def paintGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glLoadIdentity()
     GL.glTranslated(0.0, 0.0, -10.0)
     GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     GL.glCallList(self.object)
Exemplo n.º 44
0
 def selectData(self, object_s, x, y, start):
     gl.glPushMatrix()
     gl.glTranslate(x[start], y[start], 0.0)
     gl.glRotate(90, 0.0, 0.0, 1.0)
     gl.glRotate(90, 1.0, 0.0, 0.0)
     gl.glScale(7.0, 7.0, 7.0)
     gl.glCallList(object_s.gl_list)
     gl.glPopMatrix()
Exemplo n.º 45
0
    def paintGL(self):
        """Redraw"""
        GL.glDepthFunc(GL.GL_LEQUAL)
        GL.glDepthMask(GL.GL_TRUE)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glClipPlane(GL.GL_CLIP_PLANE0,
                       (0, 0, -1, self._get_slice_height() + 0.15))
        GL.glLoadIdentity()
        GL.glScaled(self.zoom / 100, self.zoom / 100, self.zoom / 100)
        self.set_light_positions()
        GL.glTranslated(self.x_pan, self.y_pan, 0.1)
        GL.glRotated(self.x_rot, 1.0, 0.0, 0.0)
        GL.glRotated(self.y_rot, 0.0, 1.0, 0.0)
        GL.glRotated(self.z_rot, 0.0, 0.0, 1.0)
        #GL.glUseProgram(0)
        if 'slices' in self.layers:
            GL.glEnable(GL.GL_CLIP_PLANE0)
        else:
            GL.glDisable(GL.GL_CLIP_PLANE0)
        for layer in sorted(self.layers):
            if layer == 'wireframe':
                GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
            elif layer == 'clip':
                pass
            elif layer == 'slices':
                pass
            else:
                GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
                if layer != 'platform':
                    GL.glPolygonOffset(1, 1)

            self.log.info("Painting: %s" % layer)
            if self.objects[layer] is not None:
                GL.glCallList(self.objects[layer])

        #This is how we draw perimiters baby!
        if 'slices' in self.layers:
            layernum = self.slice_slider.value()
            zpos = self._get_slice_height()
            if (self.project is not None and self.project.layers is not None
                    and len(self.project.layers) >= self.slice_slider.value()):
                self.qglColor(self.perimeter_color)
                GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)

                for poly in self.project.perimeters[layernum][1].polys:
                    if poly.exterior is None:
                        self.log.info("Interior poly.")
                        for interior in poly.interiors:
                            self.log.debug("Interior is %s", interior)
                        path = None
                    else:
                        self.log.info("Exterior poly.")
                        path = poly.exterior

                    if path:
                        self.draw_perimeter(
                            self.project.perimeters[layernum][0], path.coords,
                            .5, .1)
Exemplo n.º 46
0
    def onRender(self):
        gl.glDepthMask(gl.GL_TRUE)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45, self.width / self.height, 0.01, 80.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        gl.glTranslated(0.0, 0.0, -self.camPosZ)  # apply camera zooming
        gl.glRotated(self.angleX, 1.0, 0.0, 0.0)  # apply camera rotation
        gl.glRotated(self.angleY, 0.0, 1.0, 0.0)

        # draw fountain
        if self.renderEnv:
            gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE,
                         gl.GL_MODULATE)
            gl.glCallList(self.DISPLAY_LIST_OBJECT)

            gl.glMatrixMode(gl.GL_TEXTURE)

            # scroll water texture
            angle = self.totalTime * 2.0 * math.pi / 12000.0
            sinA = math.sin(angle) * 0.2
            cosA = math.cos(angle) * 0.2

            gl.glRotatef(angle, 0.0, 0.0, 1.0)
            gl.glTranslatef(sinA, cosA, 1.0)
            gl.glScalef(1.0 + sinA * 0.2, 1.0 + cosA * 0.2, 1.0)

        # draw bounding box(F2 key)
        drawBoundingBox(self.group, 1.0, 0.0, 0.0)

        # draw fountain water
        if self.renderEnv:
            gl.glCallList(self.DISPLAY_LIST_WATER)
            gl.glLoadIdentity()

        # draw particles
        self.system.render()

        # draw texts(F1 key)
        if not notext and self.text != 0:
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluOrtho2D(0, self.width, 0, self.height)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glColor3d(1.0, 1.0, 1.0)
            if self.text == 2:
                self.drawText(self.nbParticles, 4.0, 40.0)
            self.drawText(self.fps, 4.0, 8.0)

        # refresh
        sdl2.SDL_GL_SwapWindow(self.window)
Exemplo n.º 47
0
 def render(self):
     """Rendering asteroids on the screen"""
     gl.glPushMatrix()
     gl.glTranslatef(self.position[0], self.position[1], self.position[2])
     gl.glRotatef(self.rot_x, 1, 0, 0)
     gl.glRotatef(self.rot_y, 0, 1, 0)
     gl.glRotatef(self.rot_z, 0, 0, 1)
     gl.glCallList(self.obj.list_id)
     gl.glPopMatrix()
Exemplo n.º 48
0
    def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        #replace current matrix with identity matrix
        GL.glLoadIdentity()

        for algae in self.algaeList:
            GL.glTranslated(algae.posX, algae.posY, -10.0)
            #calls the list saved in object variable
            GL.glCallList(algae.object)
Exemplo n.º 49
0
 def paintGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     GL.glLoadIdentity()
     GL.glTranslated(self.xMove, self.yMove, -100.0)
     GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     if not self.glect is None:
         GL.glCallList(self.glect)
Exemplo n.º 50
0
 def display(self):
     if self.trans:
         GL.glEnable (GL.GL_BLEND)
         GL.glDepthMask (GL.GL_FALSE)
         GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
     GL.glCallList(self.list)
     if self.trans:
         GL.glDepthMask (GL.GL_TRUE)
         GL.glDisable (GL.GL_BLEND)
Exemplo n.º 51
0
    def display(self):

        #gl.glPushMatrix()

        print self.list_index

        #gl.glLoadIdentity()

        gl.glCallList(self.list_index)
Exemplo n.º 52
0
 def draw_shape(self, shape, dx, dy, dz, rotation):
     """Helper to translate, rotate and draw the shape."""
     GL.glPushMatrix()
     GL.glTranslated(dx, dy, dz)
     GL.glRotated(rotation[0], 1.0, 0.0, 0.0)
     GL.glRotated(rotation[1], 0.0, 1.0, 0.0)
     GL.glRotated(rotation[2], 0.0, 0.0, 1.0)
     GL.glCallList(shape)
     GL.glPopMatrix()
Exemplo n.º 53
0
 def draw(self,pick):
     if pick:
         GL.glColor3f(*self.color)
     GL.glPushMatrix()
     GL.glTranslatef(self.posx,self.posy,self.posz)
     GL.glRotatef(self.rotx,1.0,0.0,0.0)
     GL.glRotatef(self.roty,0.0,1.0,0.0)
     GL.glRotatef(self.rotz,0.0,0.0,1.0)
     #glScalef(self.sclx,self.scly,self.sclz)
     GL.glCallList(self.list)
     GL.glPopMatrix()
Exemplo n.º 54
0
    def drawGrid(self):
        if self.gridList == None:
            # display list used for the grid
            self.gridList = GL.glGenLists(1)

            if self.gridList == 0 or self.gridList == None:
                raise RuntimeError( """Unable to generate a new display-list, context may not support display lists""")

            self.updateGrid()

        GL.glCallList(self.gridList)
Exemplo n.º 55
0
 def paintGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     # GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     GL.glTranslatef(-self.sizW/2.0, -self.sizH/2.0, -900.0)
     # GL.glTranslatef(0, 0, -500.0)
     GL.glRotatef(15.0, 1,0,0)
     # GL.glRotatef(15.0, 0,1,0)
     # GL.glClearColor(0,0,0,0)
     # GL.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_LINE )
     GL.glBindTexture(GL.GL_TEXTURE_2D, self.textures[0])
     GL.glCallList(self.listObj)