def Display (): global angle gl.glMatrixMode(gl.GL_MODELVIEW) #Borramos la escena gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) #Dibuja taza gl.glPushMatrix() gl.glColor3f (1.0, 1.0, 1.0) gl.glTranslatef(0.0,0.0,-1.0) gl.glRotatef(angle,0.0,1.0,0.0) glut.glutSolidTeapot(0.3) gl.glPopMatrix() #Dibuja Cubo gl.glPushMatrix() gl.glColor3f (0.0, 1.0, 0.0) gl.glTranslatef(0.0,0.0,-4.0) gl.glRotatef(angle,0.0,1.0,0.0) #gl.glRotatef(angle,0.0,1.0,0.0) gl.glTranslatef(1.0,0.0,0.0) glut.glutSolidCube(0.1) gl.glPopMatrix() glut.glutSwapBuffers() gl.glFlush()
def draw_teapot(): if fill.value: gl.glEnable (gl.GL_LIGHTING) gl.glEnable (gl.GL_DEPTH_TEST) gl.glColor3f(color[0],color[1],color[2]) gl.glPolygonOffset (1, 1) gl.glEnable (gl.GL_POLYGON_OFFSET_FILL) if shape.value == 0: glut.glutSolidCube(1) elif shape.value == 1: glut.glutSolidTorus(0.25, 0.50, 32, 32) else: glut.glutSolidTeapot(.75) gl.glDisable (gl.GL_LIGHTING) gl.glDisable (gl.GL_POLYGON_OFFSET_FILL) gl.glEnable (gl.GL_LINE_SMOOTH) gl.glEnable (gl.GL_BLEND) gl.glDepthMask (gl.GL_FALSE) gl.glColor4f(0,0,0,.5) if shape.value == 0: glut.glutWireCube(1) elif shape.value == 1: glut.glutWireTorus(0.25, 0.50, 32, 32) else: glut.glutWireTeapot(.75) gl.glDepthMask (gl.GL_TRUE)
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): if not self.visible: return is_click = (p1 is not None) if p1 is None: p1 = len(self) if p1 <= p0: return # draw nothing GL.glShadeModel(GL.GL_SMOOTH) GL.glPushMatrix() GL.glMultMatrixf(self.transform) GL.glColor4f(*self.colour) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) primType = self.primitiveType.lower() if primType == 'sphere': radius = self.attrs.get('radius', 100.) slices = self.attrs.get('slices', 10) stacks = self.attrs.get('stacks', 10) if self.attrs.get('wire',None): GLUT.glutWireSphere(radius, slices, stacks) else: GLUT.glutSolidSphere(radius, slices, stacks) elif primType == 'cube': size = self.attrs.get('size', 100.) if self.attrs.get('wire',None): GLUT.glutWireCube(size) else: GLUT.glutSolidCube(size) GL.glPopMatrix()
def _render_geom(self, geom): """ Render either a ode.GeomBox or ode.GeomSphere object. """ #allowed = [ode.GeomSphere, ode.GeomCylinder] allowed = [ode.GeomBox, ode.GeomSphere, ode.GeomCylinder] ok = False for klass in allowed: ok = ok or isinstance(geom, klass) if (not ok): return ogl.glPushMatrix() ogl.glMultMatrixd(self._extract_matrix(geom)) ogl.glMaterialfv(ogl.GL_FRONT, ogl.GL_SPECULAR, (0.0, 0.0, 0.0)) if (isinstance(geom, ode.GeomBox)): sx, sy, sz = geom.getLengths() ogl.glScale(sx, sy, sz) oglut.glutSolidCube(1) elif (isinstance(geom, ode.GeomSphere)): r = geom.getRadius() oglut.glutSolidSphere(r, 20, 20) elif (isinstance(geom, ode.GeomCylinder)): r, h = geom.getParams() oglut.glutSolidCylinder(r, h, 20, 20) ogl.glPopMatrix()
def draw_teapot(): if fill.value: gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_DEPTH_TEST) gl.glColor3f(color[0], color[1], color[2]) gl.glPolygonOffset(1, 1) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) if shape.value == 0: glut.glutSolidCube(1) elif shape.value == 1: glut.glutSolidTorus(0.25, 0.50, 32, 32) else: glut.glutSolidTeapot(.75) gl.glDisable(gl.GL_LIGHTING) gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) gl.glColor4f(0, 0, 0, .5) if shape.value == 0: glut.glutWireCube(1) elif shape.value == 1: glut.glutWireTorus(0.25, 0.50, 32, 32) else: glut.glutWireTeapot(.75) gl.glDepthMask(gl.GL_TRUE)
def Display(): global angle gl.glMatrixMode(gl.GL_MODELVIEW) #Borramos la escena gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) #Dibuja taza gl.glPushMatrix() gl.glColor3f(1.0, 1.0, 1.0) gl.glTranslatef(0.0, 0.0, -1.0) gl.glRotatef(angle, 0.0, 1.0, 0.0) glut.glutSolidTeapot(0.3) gl.glPopMatrix() #Dibuja Cubo gl.glPushMatrix() gl.glColor3f(0.0, 1.0, 0.0) gl.glTranslatef(0.0, 0.0, -4.0) gl.glRotatef(angle, 0.0, 1.0, 0.0) #gl.glRotatef(angle,0.0,1.0,0.0) gl.glTranslatef(1.0, 0.0, 0.0) glut.glutSolidCube(0.1) gl.glPopMatrix() glut.glutSwapBuffers() gl.glFlush()
def create_cube_solid(color=None): """ Create a solid cube. :param color: Cube color :type color: list :return: OpenGL list """ obj = _gl.glGenLists(1) _gl.glNewList(obj, _gl.GL_COMPILE) _gl.glPushMatrix() if color is not None: _gl.glColor4fv(color) # noinspection PyBroadException try: _glut.glutSolidCube(1.0) except: if not _FIGURES_ERRS[3]: _print_gl_error( 'OpenGL actual version does not support glutSolidCube function' ) _FIGURES_ERRS[3] = True _gl.glPopMatrix() _gl.glEndList() return obj
def _draw_printer(self, domain_object): gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, [0.8, 0.2, 0.2, 1]) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, [0.8, 0.4, 0.4, 1]) gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, [0.2, 0.1, 0.1, 1]) gl.glTranslatef(0.0, 0.0, domain_object.height_mm) printer_size = 50 * domain_object.relitive_size gl.glTranslatef(0.0, 0.0, printer_size / 2.0) glut.glutSolidCube(printer_size, 5, 5) gl.glTranslatef(0.0, 0.0, -printer_size / 2.0) gl.glTranslatef(0.0, 0.0, -domain_object.height_mm)
def _draw(self): # use a fresh transformation matrix gl.glPushMatrix() # position object gl.glTranslate(value(self.pos.x), value(self.pos.y), value(self.pos.z)) gl.glMaterialfv(gl.GL_FRONT,gl.GL_DIFFUSE,self.color.rgb()) check_units('box dimensions must be distances', self.wx, self.wy, self.wz, meter) gl.glScale(value(self.wx), value(self.wy), value(self.wz)) glut.glutSolidCube(1) gl.glPopMatrix()
def draw_cube(size): ''' Draw a red teapot at the origin. ''' GL.glEnable(GL.GL_LIGHTING) GL.glEnable(GL.GL_LIGHT0) GL.glEnable(GL.GL_DEPTH_TEST) GL.glClear(GL.GL_DEPTH_BUFFER_BIT) # draw red teapot GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0,0,0,0]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [1.0,1.0,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) GLUT.glutSolidCube(size)
def RenderEntity(entity): position = entity.pos modelName = entity.render.modelName size = entity.render.size dimensions = entity.render.dimensions color = entity.render.color #if hasattr(entity, 'name') and entity.name == 'Ball': # print(position) gl.glLoadIdentity() gl.glTranslate(position[0], position[1], position[2]) gl.glColor(color[0], color[1], color[2]) gl.glScalef(dimensions[0], dimensions[1], dimensions[2]) glut.glutSolidCube(size)
def init(self): self.list_index = gl.glGenLists(1) print self.list_index gl.glNewList( self.list_index,gl.GL_COMPILE) gl.glPushMatrix() gl.glMaterialfv( gl.GL_FRONT, gl.GL_AMBIENT, self.ambient ) gl.glMaterialfv( gl.GL_FRONT, gl.GL_DIFFUSE, self.diffuse ) gl.glMaterialfv( gl.GL_FRONT, gl.GL_SPECULAR, self.specular ) gl.glMaterialf( gl.GL_FRONT, gl.GL_SHININESS, self.shininess ) gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, self.emission) #x,y,z = self.scale #gl.glScalef(x,y,z) glut.glutSolidCube(50.0) #glut.glutSolidTeapot(20.0) gl.glPopMatrix() gl.glEndList() if self.is3dgrid: x,y,z=np.mgrid[-200:200:5j,-200:200:5j, -200:200:5j] self.gridz=z.ravel() else: x,y=np.mgrid[-200:200:5j,-200:200:5j] self.gridx=x.ravel() self.gridy=y.ravel() print self.list_index
def render(self, holograma=False): gl.glPushMatrix() gl.glTranslatef(self.x * blockSize, self.y * blockSize, 0.0) if holograma: gl.glColor3f(self.color['r'], self.color['g'], self.color['b']) glut.glutWireCube(blockSize) else: gl.glMaterialfv( gl.GL_FRONT, gl.GL_AMBIENT, [self.color['r'], self.color['g'], self.color['b'], 1.0]) gl.glMaterialfv( gl.GL_FRONT, gl.GL_DIFFUSE, [self.color['r'], self.color['g'], self.color['b'], 1.0]) gl.glMaterialfv( gl.GL_FRONT, gl.GL_SPECULAR, [self.color['r'], self.color['g'], self.color['b'], 1.0]) gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, 100.0) glut.glutSolidCube(blockSize) gl.glPopMatrix()
def __init__(self, color=(0, 0, 0, 1)): Renderable.__init__(self, color) GL.glNewList(self.gl_list, GL.GL_COMPILE) GLUT.glutSolidCube(1) GL.glEndList()
def render_box(self, pos, size): GL.glPushMatrix() GL.glTranslated(*pos) GL.glScaled(*size) GLUT.glutSolidCube(1.0) GL.glPopMatrix()
def draw(self, renderer): glClearColor(.8, .8, .8, 1.0) glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 0, 0) GLUT.glutSolidCube(2)
def render(side): """Render scene in either GLU_BACK_LEFT or GLU_BACK_RIGHT buffer""" boxSize = 50 # size of cube height, width and depth = 50mm separate = 100 # separation for array of cubes 100mm GL.glViewport(0, 0, GLUT.glutGet(GLUT.GLUT_WINDOW_WIDTH), GLUT.glutGet(GLUT.GLUT_WINDOW_HEIGHT)) if side == GL.GL_BACK_LEFT: # render left frustum and lookAt points f = sC.frustumLeft l = sC.lookAtLeft else: # render right side view f = sC.frustumRight l = sC.lookAtRight GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() # collect parameters from stereoCamera.py for frustum GL.glFrustum(f[0], f[1], f[2], f[3], f[4], f[5]) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() # collect lookAt parameters from stereoCamera.py GLU.gluLookAt(l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8]) # draw array of cubes at varying positions across screen GL.glPushMatrix() GL.glTranslatef(-separate, 0.0, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() # draws centre cube - 100mm depth difference GL.glTranslatef(0.0, 0.0, -900) GL.glRotatef(animationAngle, 0.2, 0.7, 0.3) # rotates the cube GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate, 0.0, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(-separate, separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(0.0, separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate, separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(-separate, -separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(0.0, -separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate, -separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate * 2, separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate * 2, 0.0, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(separate * 2, -separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(-separate * 2, separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(-separate * 2, 0.0, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix() GL.glPushMatrix() GL.glTranslatef(-separate * 2, -separate, -1000) GLUT.glutSolidCube(boxSize) GL.glPopMatrix()
def draw_shape(self): # scale to appropriate size gl.glScalef(self.width, self.height, self.depth) # draw cube glut.glutSolidCube(1.0)
def draw(): GL.glClear(GL.GL_COLOR_BUFFER_BIT) #GL.OpenGL.GLUT.glutWireTeapot(0.5) GLUT.glutSolidCube(1) GL.glFlush()
def draw_bullets(bullets): for b in bullets: gl.glColor3fv(bullet_colors[b.owner]) with world_pos(b.position): glut.glutSolidCube(1.5)