def gl_init( width, height ): global __legocaptex,__quadratic setviewport(width, height) __legocaptex = layer_manager.load_2d_texture(pygame.image.tostring(__image, "RGBA"), LEGO_CAP_WIDTH, LEGO_CAP_HEIGHT) __quadratic = GLU.gluNewQuadric() GLU.gluQuadricTexture(__quadratic, GLU.GLU_TRUE) GLU.gluQuadricDrawStyle(__quadratic,GLU.GLU_FILL) GLU.gluQuadricOrientation(__quadratic, GLU.GLU_OUTSIDE) GLU.gluQuadricNormals(__quadratic, GLU.GLU_SMOOTH) GL.glClearColor( 0.0, 0.2, 0.5, 1.0 ) GL.glEnable(GL.GL_POINT_SMOOTH) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) GL.glEnable(GL.GL_COLOR_MATERIAL) GL.glDisable(GL.GL_CULL_FACE) GL.glAlphaFunc(GL.GL_GREATER,0.1) GL.glClearAccum(0.0, 0.0, 0.0, 1.0) GL.glClear(GL.GL_ACCUM_BUFFER_BIT) #GL.glGenLists(1) draw_mode_3d()
def __init__(self, molecule, hide_hydrogens=False, randomize_single_bonds=False, bond_width=.1, bond_length=2): self.molecule = molecule self.hide_hydrogens = hide_hydrogens self.randomize_single_bonds = randomize_single_bonds self.rotate_atoms(self.molecule) self.bond_width = bond_width self.bond_length = bond_length self.quad = glu.gluNewQuadric() glu.gluQuadricNormals(self.quad, glu.GLU_SMOOTH) glu.gluQuadricDrawStyle(self.quad, glu.GLU_FILL) self.cylinder_resolution = 100 self.sphere_resolution = 100 self.zoom = 5 self.rotations = [] self.scroll_up_button = 3 self.scroll_down_button = 4 self.scroll_buttons = [self.scroll_up_button, self.scroll_down_button] self.zoom_increment = 0.2 self.default_element_color = (221/255, 119/255, 1) self.bond_color = (128/255,) * 3 self.drag_start = None
def __init__(self, molecule, hide_hydrogens=False, randomize_single_bonds=False, bond_width=.1, bond_length=2): self.molecule = molecule self.hide_hydrogens = hide_hydrogens self.randomize_single_bonds = randomize_single_bonds self.rotate_atoms(self.molecule) self.bond_width = bond_width self.bond_length = bond_length self.quad = glu.gluNewQuadric() glu.gluQuadricNormals(self.quad, glu.GLU_SMOOTH) glu.gluQuadricDrawStyle(self.quad, glu.GLU_FILL) self.cylinder_resolution = 100 self.sphere_resolution = 100 self.zoom = 5 self.rotations = [] self.scroll_up_button = 3 self.scroll_down_button = 4 self.scroll_buttons = [self.scroll_up_button, self.scroll_down_button] self.zoom_increment = 0.2 self.default_element_color = (221 / 255, 119 / 255, 1) self.bond_color = (128 / 255, ) * 3 self.drag_start = None
def applyShape(self): self._Quadric=GLU.gluNewQuadric() GLU.gluQuadricNormals(self._Quadric, self.GL(self._normals)) GLU.gluQuadricTexture(self._Quadric, self.GL(self._texture)) GLU.gluCylinder(self._Quadric, self._base, self._top, self._height, self._subdiv, 1) GLU.gluDeleteQuadric(self._Quadric) self._Quadric = None
def init_gl(self): """ Initialise OpenGL settings """ self.sphere = GL.glGenLists(1) GL.glNewList(self.sphere, GL.GL_COMPILE) quad_obj = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(quad_obj, GLU.GLU_FILL) GLU.gluQuadricNormals(quad_obj, GLU.GLU_SMOOTH) GLU.gluSphere(quad_obj, 1, 16, 16) GL.glEndList() GL.glShadeModel(GL.GL_SMOOTH) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_CULL_FACE) GL.glEnable(GL.GL_LIGHTING) # make sure normal vectors of scaled spheres are normalised GL.glEnable(GL.GL_NORMALIZE) GL.glEnable(GL.GL_LIGHT0) light_pos = list(_LIGHT_POSITION) + [1] GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_pos) GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [1.0, 1.0, 1.0, 1.0]) GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0.2, .2, .2, 1]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [0.7, 0.7, 0.7, 1]) GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [0.1, 0.1, 0.1, 1]) GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 20) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(60, 1, .01, 10) GL.glMatrixMode(GL.GL_MODELVIEW)
def applyShape(self): self._Quadric = GLU.gluNewQuadric() GLU.gluQuadricNormals(self._Quadric, self.GL(self._normals)) GLU.gluQuadricTexture(self._Quadric, self.GL(self._texture)) GLU.gluCylinder(self._Quadric, self._base, self._top, self._height, self._subdiv, 1) GLU.gluDeleteQuadric(self._Quadric) self._Quadric = None
def draw_nodes(pos, nodelist, node_color, node_size, node_border_size, node_border_color, scale, fancy, lights): GL.glDisable(GL.GL_DEPTH_TEST) i = 0 if fancy: vp = GL.glGetIntegerv(GL.GL_VIEWPORT) sphere_size_scale = 2./(vp[2]+vp[3]) for n in nodelist: if fancy: if lights: GL.glEnable(GL.GL_LIGHTING) GL.glPushMatrix() if len(pos[n]) ==2: position = tuple(list(pos[n]) + [0.]) else: position = pos[n] GL.glTranslate(*position) GL.glScale(scale,scale,scale) GL.glColor(*node_color[i]) sphere = GLU.gluNewQuadric() GLU.gluQuadricNormals(sphere,GLU.GLU_SMOOTH) GLU.gluQuadricTexture(sphere,GLU.GLU_TRUE) GLU.gluSphere(sphere, node_size[i]*sphere_size_scale, 32, 32) GL.glPopMatrix() if lights: GL.glDisable(GL.GL_LIGHTING) else: GL.glPointSize(node_size[i]+node_border_size[i]) GL.glBegin(GL.GL_POINTS) GL.glColor(*node_border_color[i]) GL.glVertex(*tuple(pos[n])) GL.glEnd() GL.glPointSize(node_size[i]) GL.glBegin(GL.GL_POINTS) GL.glColor(*node_color[i]) GL.glVertex(*tuple(pos[n])) GL.glEnd() i+=1 GL.glEnable(GL.GL_DEPTH_TEST)
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(1.0, 1.0, 1.0) # Default color is white # Draw the flashlight self.drawFlashLight() # Draw the sphere glMaterialfv(GL_FRONT, GL_AMBIENT, [0.3, 0.3, 0.3, 1.0]) glMaterialfv(GL_FRONT, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) glLightfv(self.light, GL_POSITION, self.lightposition) glMaterialf(GL_FRONT, GL_SHININESS, 25.0) quad = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(quad, GLU.GLU_FILL) GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH) GLU.gluSphere(quad, 3.0, 30, 30) glFlush()
def _initGL(self,Width,Height): GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0, 0.0, 0.0, 0.0) # This Will Clear The Background Color To Black GL.glClearDepth(1.0) # Enables Clearing Of The Depth Buffer GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) GL.glEnable(GL.GL_BLEND); # Enable Blending GL.glLineWidth(1.); GL.glDisable(GL.GL_LINE_SMOOTH) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); self.width = Width self.height = Height self.quad = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.quad, GLU.GLU_SMOOTH) GLU.gluQuadricTexture(self.quad, GL.GL_TRUE)
def paint_enter(self): """ Implements the GLNodeAdapter's paint_enter method for an OpenGL Render operation. """ GL.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_LINE_BIT | GL.GL_CURRENT_BIT) GL.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glMultMatrixf(self._node.matrix().data()) GL.glColor(self._node.color.getRgbF()) q = self.__quadric r = self._node.radius sl = self._node.slices st = self._node.stacks GLU.gluQuadricNormals(q, GLU.GLU_SMOOTH ) GLU.gluQuadricDrawStyle(q, GLU.GLU_FILL ); GLU.gluSphere(q, r, sl, st)
def paint_enter(self): """ Implements the GLNodeAdapter's paint_enter method for an OpenGL Render operation. """ GL.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_LINE_BIT | GL.GL_CURRENT_BIT) GL.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glMultMatrixf(self._node.matrix().data()) GL.glColor(self._node.color.getRgbF()) # The positive Z-axis is the default direction for Cylinder Quadrics in OpenGL. # If our vector is not parallel to the z-axis, e.g. (0, 0, Z), then rotate it. # 1) Get a normal from the z-v plane # 2) Get the angle inbetween z-v on the plane (see vector dot product) # 3) Rotate the normal by that angle. v = self._node.axis m = Matrix4x4.identity() if v.x != 0 or v.y != 0: zaxis = Vector3D(0,0,1) angle = zaxis.angle(v) normal = zaxis.crossproduct(v, True) m *= Matrix4x4.rotation(angle, normal) # The positive Z-axis is the default direction fo Cylinder Quadrics in OpenGL. # If our z is negative, we need to flip the cylinder if v.z < 0: yaxis = Vector3D(1,0,0) m *= Matrix4x4.rotation(math.radians(180), yaxis) GL.glMultMatrixf(m.data()) q = self.__quadric r = self._node.radius h = self._node.length sl = self._node.slices st = self._node.stacks lp = self._node.loops GLU.gluQuadricDrawStyle (q, GLU.GLU_FILL) GLU.gluQuadricNormals (q, GLU.GLU_SMOOTH) GLU.gluQuadricOrientation(q, GLU.GLU_OUTSIDE) self._glcylinder(q, r, h, sl, st, lp)
def render_arrow(self, p, q, r_base=0.01, head_width=0.015, head_len=0.01): # glDisable(GL_LIGHTING) m_quadric = self.quadric GLU.gluQuadricNormals(m_quadric, GLU.GLU_SMOOTH) p = np.array(p) q = np.array(q) u = (q - p) u /= norm(u) P = q - head_len * u z = np.array([0, 0.0, 1.0]) z /= norm(z) if norm(z - u) < 1e-8: axis = np.array([0, 0, 1]) angle = 0.0 else: axis = np.cross(z, u) axis /= norm(axis) angle = math.acos(u.dot(z)) M = R_axis_angle(axis, angle) m = [ M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0, M[0, 2], M[1, 2], M[2, 2], 0.0, P[0], P[1], P[2], 1.0 ] m2 = [ M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0, M[0, 2], M[1, 2], M[2, 2], 0.0, p[0], p[1], p[2], 1.0 ] GL.glPushMatrix() GL.glMultMatrixd(m2) arrow_len = norm(q - p) - head_len # glColor(0.9, 0.2, 0.2) GLU.gluCylinder(m_quadric, r_base, r_base, arrow_len, 10, 10) GL.glPopMatrix() if head_width > 1e-6 and head_len > 1e-6: # glColor(1.0, 0.0, 0.0) GL.glPushMatrix() GL.glMultMatrixd(m) GLUT.glutSolidCone(head_width, head_len, 10, 3) GL.glPopMatrix()
def init_gl(self): """ Initialise OpenGL settings """ self.sphere = GL.glGenLists(1) # creates model for planet GL.glNewList(self.sphere, GL.GL_COMPILE) quad_obj = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(quad_obj, GLU.GLU_FILL) GLU.gluQuadricNormals(quad_obj, GLU.GLU_SMOOTH) GLU.gluSphere(quad_obj, 1, 16, 16) GL.glEndList() GL.glShadeModel(GL.GL_SMOOTH) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_CULL_FACE) GL.glEnable(GL.GL_LIGHTING) # make sure normal vectors of scaled spheres are normalised GL.glEnable(GL.GL_NORMALIZE) GL.glEnable(GL.GL_LIGHT0)
def render_arrow(self, p, q, r_base=0.01, head_width=0.015, head_len=0.01): # glDisable(GL_LIGHTING) m_quadric = self.quadric GLU.gluQuadricNormals(m_quadric, GLU.GLU_SMOOTH) p = np.array(p) q = np.array(q) u = (q - p) u /= norm(u) P = q - head_len * u z = np.array([0, 0.0, 1.0]) z /= norm(z) if norm(z - u) < 1e-8: axis = np.array([0, 0, 1]) angle = 0.0 else: axis = np.cross(z, u) axis /= norm(axis) angle = math.acos(u.dot(z)) M = R_axis_angle(axis, angle) m = [M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0, M[0, 2], M[1, 2], M[2, 2], 0.0, P[0], P[1], P[2], 1.0] m2 = [M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0, M[0, 2], M[1, 2], M[2, 2], 0.0, p[0], p[1], p[2], 1.0] GL.glPushMatrix() GL.glMultMatrixd(m2) arrow_len = norm(q - p) - head_len # glColor(0.9, 0.2, 0.2) GLU.gluCylinder(m_quadric, r_base, r_base, arrow_len, 10, 10) GL.glPopMatrix() if head_width > 1e-6 and head_len > 1e-6: # glColor(1.0, 0.0, 0.0) GL.glPushMatrix() GL.glMultMatrixd(m) GLUT.glutSolidCone(head_width, head_len, 10, 3) GL.glPopMatrix()
def __init__(self): self.quadric = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.quadric, GLU.GLU_SMOOTH) #Create Smooth Normals GLU.gluQuadricTexture(self.quadric, gl.GL_TRUE) #Create Texture Coords
def drawSphere(s,color=cyan,ndiv=8): """Draws a centered sphere with radius s in given color.""" quad = GLU.gluNewQuadric() GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH) GL.glColor(*color) GLU.gluSphere(quad,s,ndiv,ndiv)
def __init__(self): self.sphere = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.sphere, GLU.GLU_NONE) GLU.gluQuadricTexture(self.sphere, gl.GL_FALSE)
def draw_arrows(pos, edgelist, edge_color, arrow_points, arrow_size, scale, lights, fancy): GL.glDisable(GL.GL_DEPTH_TEST) if lights: GL.glEnable(GL.GL_LIGHTING) k = 0 for (i,j) in edgelist: d = [] for r in range(len(pos[i])): d.append(pos[i][r]-pos[j][r]) d = tuple(d + [0]) GL.glPushMatrix() GL.glTranslate(arrow_points[k][0][0], arrow_points[k][0][1], arrow_points[k][0][2]) GL.glScale(scale,scale,scale) GL.glRotate(arrow_points[k][1],-d[1],d[0],0) GL.glColor(*edge_color[k]) vp = GL.glGetIntegerv(GL.GL_VIEWPORT) arrow_size_scale = 2./(vp[2]+vp[3]) if fancy: cone = GLU.gluNewQuadric() GLU.gluQuadricNormals(cone,GLU.GLU_SMOOTH) GLU.gluQuadricTexture(cone,GLU.GLU_TRUE) GLU.gluCylinder(cone, 0, arrow_size_scale*arrow_size[k]/3., arrow_size_scale*arrow_size[k], 32, 32) else: s1 = arrow_size[k]*arrow_size_scale s2 = arrow_size_scale*arrow_size[k]/3. GL.glBegin(GL.GL_POLYGON); GL.glVertex3d(0, 0, 0); GL.glVertex3d(-s2, s2, s1); GL.glVertex3d(-s2, -s2, s1); GL.glVertex3d(0, 0, 0); GL.glVertex3d(-s2, s2, s1); GL.glVertex3d(s2, s2, s1); GL.glVertex3d(0, 0, 0); GL.glVertex3d(s2, s2, s1); GL.glVertex3d(s2, -s2, s1); GL.glVertex3d(0, 0, 0); GL.glVertex3d(s2, -s2, s1); GL.glVertex3d(-s2, -s2, s1); GL.glVertex3d(-s2, -s2, s1); GL.glVertex3d(s2, -s2, s1); GL.glVertex3d(s2, s2, s1); GL.glVertex3d(-s2, s2, s1); GL.glEnd(); GL.glPopMatrix() k+=1 if lights: GL.glDisable(GL.GL_LIGHTING) GL.glEnable(GL.GL_DEPTH_TEST)
def __init__(self): self.sphere = GLU.gluNewQuadric() GLU.gluQuadricNormals(self.sphere, GLU.GLU_SMOOTH) GLU.gluQuadricTexture(self.sphere, gl.GL_TRUE)
def applyShape(self): Q=GLU.gluNewQuadric() GLU.gluQuadricNormals(Q, self.GL(self._normals)) GLU.gluQuadricTexture(Q, self.GL(self._texture)) GLU.gluSphere(Q, self._radius, self._subdiv, self._subdiv/2) GLU.gluDeleteQuadric( Q )
def applyShape(self): Q = GLU.gluNewQuadric() GLU.gluQuadricNormals(Q, self.GL(self._normals)) GLU.gluQuadricTexture(Q, self.GL(self._texture)) GLU.gluSphere(Q, self._radius, self._subdiv, self._subdiv / 2) GLU.gluDeleteQuadric(Q)