def render(self): self.clock.record_frame_time() if self.is_recording and not self.timer.is_snoozed: self.frame_index += 1 frame_name = "Frame_{0:05d}.jpg".format(self.frame_index) self.save_screenshot(frame_name) self.timer.snooze() glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if camera.is_rotating: camera.rotate_z(0.2) camera.look() self.draw_detector() glEnable(GL_DEPTH_TEST) glEnable(GL_LINE_SMOOTH) glShadeModel(GL_FLAT) glEnable(GL_LIGHTING) for obj in self.shaded_objects: obj.draw(self.clock.time, self.spectrum) glDisable(GL_LIGHTING) for obj in self.objects: obj.draw(self.clock.time) self.draw_gui() glutSwapBuffers()
def main(): moons = [Moon(pos) for pos in d12_input] glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(800, 800) glutInitWindowPosition(350, 200) glutCreateWindow('name') glClearColor(0., 0., 0., 1.) glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) lightZeroPosition = [10., 4., 10., 1.] lightZeroColor = [0.8, 1.0, 0.8, 1.0] glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor) glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) glutDisplayFunc(lambda: display_scene(moons)) glutTimerFunc(0, timer, 0) glMatrixMode(GL_PROJECTION) gluPerspective(40., 1., 1., 40.) glMatrixMode(GL_MODELVIEW) gluLookAt(0, -10, 10, 0, 0, 0, 0, 1, 0) glPushMatrix() glutMainLoop()
def initializeGL(self): print("WDGQT_initialize") self.qglClearColor(self.trolltechPurple.darker()) self.object = self.makeObject() glShadeModel(GL_FLAT) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE)
def init(): glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.0) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
def InitGL(self, Width, Height): self.view_port_xr = 1 self.view_port_yr = 1 self.original_x = Width self.original_y = Height glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, Width, 0, Height, -1, 1) glScalef(1, -1, 1) glTranslatef(0, -Height, 0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) # Disables Depth Testing glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading # Anti-aliasing/prettyness stuff glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glEnable(GL_LINE_SMOOTH) glEnable(GL_POINT_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glClearColor(background_color()[0], background_color()[1], background_color()[2], 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def draw_gui(self): logo = self.logo logo_bytes = self.logo_bytes menubar_height = logo.size[1] + 4 width = glutGet(GLUT_WINDOW_WIDTH) height = glutGet(GLUT_WINDOW_HEIGHT) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0.0, width, height, 0.0, -1.0, 10.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() #glDisable(GL_CULL_FACE) glShadeModel(GL_SMOOTH) glClear(GL_DEPTH_BUFFER_BIT) # Top bar #glBegin(GL_QUADS) #glColor3f(0.14, 0.49, 0.87) #glVertex2f(0, 0) #glVertex2f(width - logo.size[0] - 10, 0) #glVertex2f(width - logo.size[0] - 10, menubar_height) #glVertex2f(0, menubar_height) #glEnd() try: self.draw_colour_legend() except TypeError: pass glPushMatrix() glLoadIdentity() glRasterPos(4, logo.size[1] + 4) glDrawPixels(logo.size[0], logo.size[1], GL_RGB, GL_UNSIGNED_BYTE, logo_bytes) glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) self.colourist.now_text() #draw_text_2d("{0}ns".format(int(self.min_hit_time)), width - 80, 20) #draw_text_2d("{0}ns".format(int(self.max_hit_time)), width - 80, height - menubar_height - 10) #draw_text_2d("{0}ns".format(int((self.min_hit_time + self.max_hit_time) / 2)), width - 80, int(height/2)) if self.show_help: self.display_help() if self.show_info: self.display_info()
def initializeGL(self): glClearColor(*self.color_background) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW)
def draw_lines(self, line_width=1): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) for position in self.line_positions: glPushMatrix() glTranslated(position[0], position[1], 0) glLineWidth(line_width) glBegin(GL_LINES) glVertex3f(0.0, 0.0, self.z_min) glVertex3f(0.0, 0.0, self.z_max) glEnd() glPopMatrix()
def initializeGL(self): # TODO: correct background color glClearColor(*self.color_background) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW)
def draw(self, line_width=2): glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glPushMatrix() glTranslated(self.x, self.y, self.z) glLineWidth(line_width) glColor3f(1.0, 1.0, 1.0) glBegin(GL_LINES) glVertex3f(0.0, 0.0, 0.0) glVertex3f(0.0, 0.0, self.length) glEnd() glPopMatrix()
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 if time <= self.time: return pos_start = self.pos + (self.speed * (-self.time) * self.dir) path = self.speed * (time - self.time) * self.dir if self.length: max_path = self.length * self.dir if np.linalg.norm(max_path) <= np.linalg.norm(path): path = max_path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix() if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled: height = np.linalg.norm(pos_end - pos_start) position = pos_end - self.dir * height glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glColor4f(0.0, 0.0, 0.8, 0.3) glPushMatrix() glTranslated(*position) glPushMatrix() v = np.array(self.dir) glMultMatrixf(transform(v)) glutSolidCone(0.6691 * height, height, 128, 64) glPopMatrix() glPopMatrix() glDisable(GL_LIGHTING)
def initializeGL(self): self._setup_lighting() glShadeModel(GL_SMOOTH) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glMatrixMode(GL_MODELVIEW) glLoadIdentity() if not self.isSharing(): ## setup_drawer() self._setup_display_lists() # defined in GLPane_minimal. [bruce 071030] return
def initializeGL(self): """ Called once by Qt when the OpenGL context is first ready to use. """ #bruce 080912 merged this from subclass methods, guessed docstring self._setup_lighting() glShadeModel(GL_SMOOTH) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glMatrixMode(GL_MODELVIEW) glLoadIdentity() if not self.isSharing(): self._setup_display_lists() return
def initializeGL(self): self._setup_lighting() glShadeModel(GL_SMOOTH) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glMatrixMode(GL_MODELVIEW) glLoadIdentity() if not self.isSharing(): ## setup_drawer() self._setup_display_lists( ) # defined in GLPane_minimal. [bruce 071030] return
def init(): width = mosaic_factory.ratio * size height = size print "loading textures:" for i, img in enumerate(mosaic_factory.images): print " {0}/{1}".format(i + 1, len(mosaic_factory.images)) textures[img] = load_texture(img.get_image()) generate_picture_display_list(img, width, height) print "generating mosaic display lists:" for i, img in enumerate(mosaic_factory.images): print " {0}/{1}".format(i + 1, len(mosaic_factory.images)) generate_mosaic_display_list(img) glEnable(GL_TEXTURE_2D) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glClearColor(0.0, 0.0, 0.0, 0.0) glShadeModel(GL_FLAT)
def render_to_png(filename, callback, obb, model_matrix=(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)): from pygame import init, display, quit from pygame.constants import OPENGL, DOUBLEBUF from OpenGL.GL import glLightfv, glCullFace, glEnable, glShadeModel, glMatrixMode, glLoadIdentity, glClear, \ glLoadMatrixf, glPolygonMode, glCallList, glReadPixels, GL_LIGHT0, GL_POSITION, GL_AMBIENT, GL_DIFFUSE, \ GL_BACK, GL_LIGHTING, GL_COLOR_MATERIAL, GL_DEPTH_TEST, GL_SMOOTH, GL_PROJECTION, GL_MODELVIEW, \ GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_FRONT_AND_BACK, GL_FILL, GL_LINE, GL_BGR, GL_UNSIGNED_BYTE from OpenGL.GLU import gluPerspective from cv2 import imwrite from numpy import frombuffer, uint8 init() viewport = (800, 600) display.set_mode(viewport, OPENGL | DOUBLEBUF) glLightfv(GL_LIGHT0, GL_POSITION, (0, -1, 0, 0)) glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1)) glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1)) glCullFace(GL_BACK) glEnable(GL_LIGHT0) glEnable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() width, height = viewport gluPerspective(90.0, width / float(height), 0.1, 100.0) glEnable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glLoadMatrixf(model_matrix) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glCallList(callback()) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glCallList(create_obb_gl_list(obb)) img_data = glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE) img = frombuffer(img_data, dtype=uint8) img = img.reshape((height, width, 3)) imwrite(filename, img) quit()
def initializeGL(self): print("initializeGL") self.texNumeros, self.texDecor = self.load_textures() glEnable(GL_TEXTURE_2D) glShadeModel(GL_SMOOTH) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glFrontFace(GL_CCW) light_ambient = [0.3, 0.3, 0.3, 0.1] glEnable(GL_LIGHTING) lightpos = (0, 0, 50) glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient) glLightfv(GL_LIGHT0, GL_POSITION, lightpos) glEnable(GL_LIGHT0) glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
def initializeGL(self): # We call this right after our OpenGL window is created. glClearColor(1.0, 1.0, 1.0, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) light_position = (0., 0., 1., 0.) white_light = (1., 1., 1., 0.501) d_light = (1., 1., 1., 0.01) spec = (1., 1., 1., 0.08) glLightfv(GL_LIGHT0, GL_POSITION, light_position) glLightfv(GL_LIGHT0, GL_AMBIENT, white_light) #glLightfv(GL_LIGHT0, GL_DIFFUSE, d_light) glLightfv(GL_LIGHT0, GL_SPECULAR, spec) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) #glBlendFunc(GL_SRC_ALPHA,GL_ONE) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glEnable(GL_COLOR_MATERIAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective( 45.0, float(self.size().height()) / float(self.size().width()), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.rotation = [0.0, 0.0] self.mesh.prepDraw()
def draw_gui(self): logo = self.logo logo_bytes = self.logo_bytes width = glutGet(GLUT_WINDOW_WIDTH) height = glutGet(GLUT_WINDOW_HEIGHT) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0.0, width, height, 0.0, -1.0, 10.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glShadeModel(GL_SMOOTH) glClear(GL_DEPTH_BUFFER_BIT) try: self.draw_colour_legend() except TypeError: pass glPushMatrix() glLoadIdentity() glRasterPos(4, logo.size[1] + 4) glDrawPixels(logo.size[0], logo.size[1], GL_RGB, GL_UNSIGNED_BYTE, logo_bytes) glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) self.colourist.now_text() if self.show_help: self.display_help() if self.show_info: self.display_info()
def _on_realize(self, *args): """ Called at the creation of the drawing area. Sets up the OpenGL rendering context. """ print("_on_realize(%s)" % str(args)) gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() if not gldrawable.gl_begin(glcontext): return self._set_view(WIDTH / float(HEIGHT)) glEnable(GL_TEXTURE_RECTANGLE_ARB) # 2D) glEnable(GL_BLEND) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 1.0) # black background glColor4f(1.0, 1.0, 1.0, 1.0) # default color is white glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) gldrawable.gl_end()
def initialize(self, display_function: callable): """Initialze the OpenGL display parts of the Window. Warning: Must be called on the same thread as OpenGL (usually the main thread), """ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(self.width, self.height) glutInitWindowPosition(*self._pos) self._gl_window = glutCreateWindow(self._window_name) glClearColor(0, 0, 0, 0) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glutIdleFunc(self._idle) glutVisibilityFunc(self._visible) glutReshapeFunc(self._reshape) glutDisplayFunc(display_function)
def initializeGL(self): # We call this right after our OpenGL window is created. glClearColor(1.0, 1.0, 1.0, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) light_position = (0., 0., 1., 0.) white_light = (1., 1., 1., 0.501) d_light = (1., 1., 1., 0.01) spec = (1., 1., 1., 0.08) glLightfv(GL_LIGHT0, GL_POSITION, light_position) glLightfv(GL_LIGHT0, GL_AMBIENT, white_light) #glLightfv(GL_LIGHT0, GL_DIFFUSE, d_light) glLightfv(GL_LIGHT0, GL_SPECULAR, spec) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) #glBlendFunc(GL_SRC_ALPHA,GL_ONE) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glEnable(GL_COLOR_MATERIAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(self.size().height())/ float(self.size().width()), 0.1, 1000000.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.rotation = [0.0, 0.0] self.mesh.prepDraw()
def init_opengl(self): """A general OpenGL initialization function. Sets all of the initial parameters. We call this right after our OpenGL window is created. """ glClearColor(0.0, 0.0, 0.0, 1.0) # This Will Clear The Background Color To Black glClearDepth(1.0) # Enables Clearing Of The Depth Buffer glDepthFunc(GL_LEQUAL) # The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST) # Enables Depth Testing glShadeModel(GL_SMOOTH) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) # Really Nice Perspective Calculations glEnable(GL_LIGHT0) glEnable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glEnable( GL_NORMALIZE) # important since we rescale the modelview matrix return True
def initializeGL(self): glClearColor(0.85, 0.85, 0.85, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glLightfv(GL_LIGHT0, GL_POSITION, (0.0, 0.0, 1.0, 0.0)) glEnable(GL_LIGHT0) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.display_list = glGenLists(1) glNewList(self.display_list, GL_COMPILE) glScalef(0.5, 0.5, 0.5) glEnable(GL_LIGHTING) # board glColor3f(0.0, 0.0, 0.0) self.draw_cuboid(4.0, 4.0, 0.16) # USB connector glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(0.0, -1.6, 0.28) self.draw_cuboid(0.75, 0.9, 0.4) glPopMatrix() # right button glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(1.15, -1.85, 0.16) self.draw_cuboid(0.4, 0.3, 0.16) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.155, 0.025) self.draw_cuboid(0.18, 0.1, 0.08) glPopMatrix() # left button glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(-1.15, -1.85, 0.16) self.draw_cuboid(0.4, 0.3, 0.16) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.155, 0.025) self.draw_cuboid(0.18, 0.1, 0.08) glPopMatrix() # left btb top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-1.65, 0.0, 0.38) self.draw_cuboid(0.5, 1.4, 0.6) glPopMatrix() # right btb top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(1.65, 0.0, 0.38) self.draw_cuboid(0.5, 1.4, 0.6) glPopMatrix() # left btb bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-1.65, 0.0, -0.33) self.draw_cuboid(0.5, 1.4, 0.5) glPopMatrix() # right btb bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(1.65, 0.0, -0.33) self.draw_cuboid(0.5, 1.4, 0.5) glPopMatrix() # left bricklet port glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-0.85, 1.8, -0.23) self.draw_cuboid(1.2, 0.4, 0.3) glPopMatrix() # right bricklet port glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(0.85, 1.8, -0.23) self.draw_cuboid(1.2, 0.4, 0.3) glPopMatrix() # left direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-1.05, 1.425, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # top direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.675, 1.8, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # right direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.3, 1.425, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # bottom direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.675, 1.05, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # left y orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(0.275, 1.7, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # right y orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(0.425, 1.7, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # top z orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(0.35, 1.15, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # bottom z orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(0.35, 1.0, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # top x orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(1.0, 1.15, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # bottom x orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(1.0, 1.0, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # top alignment corner glPushMatrix() glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glNormal3f(0.0, 0.0, 1.0) glVertex3f(-2.0, -2.0, 0.081) glVertex3f(-1.1, -2.0, 0.081) glVertex3f(-2.0, -1.1, 0.081) glEnd() glPopMatrix() # bottom alignment corner glPushMatrix() glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glNormal3f(0.0, 0.0, -1.0) glVertex3f(-2.0, -2.0, -0.081) glVertex3f(-2.0, -1.1, -0.081) glVertex3f(-1.1, -2.0, -0.081) glEnd() glPopMatrix() glDisable(GL_LIGHTING) # axis glPushMatrix() glTranslatef(-2.3, -2.3, -0.38) glLineWidth(3.0) glBegin(GL_LINES) glColor3f(1, 0, 0) # x axis is red glVertex3f(0, 0, 0) glVertex3f(3, 0, 0) glColor3f(0, 0.5, 0) # y axis is green glVertex3f(0, 0, 0) glVertex3f(0, 3, 0) glColor3f(0, 0, 1) # z axis is blue glVertex3f(0, 0, 0) glVertex3f(0, 0, 3) glEnd() glLineWidth(1.0) glPopMatrix() glEndList()
def initializeGL(self): self.qglClearColor(Qt.white) glutInit(sys.argv) glutInitDisplayMode(GLUT_RGB, GLUT_DOUBLE, GLUT_DEPTH) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH)
def __init__(self): print(str(bool(glutInit))) print("hello and weolcome") print( "if you see an error next try the unofficial binaries of pyopengl") print("initializing glut etc") glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH) glutInitWindowSize(640, 480) glutCreateWindow(name) print("set blend function") glBlendFunc(GL_SRC_ALPHA, GL_ONE) print("set colours and lights") glClearColor(0., 0., 0., 1.) glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) print("set light 1") lightZeroPosition = [10., 4., 10., 1.] lightZeroColor = [0.9, 1.0, 0.9, 1.0] #green tinged glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor) glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.2) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) print("set light 2") lightZeroPosition2 = [-10., -4., 10., 1.] lightZeroColor2 = [1.0, 0.9, 0.9, 1.0] #green tinged glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2) glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2) glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2) glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT1) #initialization of letters print("initialzing letters") self.letters = Letters.Letters() #for game models print("making model lists") MakeLists() print("ignore key repeat") glutIgnoreKeyRepeat(1) print("attach glut events to functions") glutSpecialFunc(self.keydownevent) glutSpecialUpFunc(self.keyupevent) glutReshapeFunc(self.reshape) glutKeyboardFunc(self.keydownevent) glutKeyboardUpFunc(self.keyupevent) glutDisplayFunc(self.display) #glutIdleFunc(self.display) print("initial projection") glMatrixMode(GL_PROJECTION) gluPerspective(60.0, 640.0 / 480., 1., 50.) glMatrixMode(GL_MODELVIEW) glPushMatrix() print("generating level") self.level = generateLevel(0) print("keys set up") self.initkey("zxdcfvqaopm") self.animate() print("about to loop...") glutMainLoop() return
def draw(self, width, height, selection_box=None): scene = context.application.scene camera = context.application.camera glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if selection_box is not None: # set up a select buffer glSelectBuffer(self.select_buffer_size) glRenderMode(GL_SELECT) glInitNames() glMatrixMode(GL_PROJECTION) glLoadIdentity() # Apply the pick matrix if selecting if selection_box is not None: gluPickMatrix(0.5 * (selection_box[0] + selection_box[2]), height - 0.5 * (selection_box[1] + selection_box[3]), selection_box[2] - selection_box[0] + 1, selection_box[3] - selection_box[1] + 1, (0, 0, width, height)) # Apply the frustum matrix znear = camera.znear zfar = camera.znear + camera.window_depth if width > height: w = 0.5 * float(width) / float(height) h = 0.5 else: w = 0.5 h = 0.5 * float(height) / float(width) if znear > 0.0: glFrustum(-w * camera.window_size, w * camera.window_size, -h * camera.window_size, h * camera.window_size, znear, zfar) else: glOrtho(-w * camera.window_size, w * camera.window_size, -h * camera.window_size, h * camera.window_size, znear, zfar) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Move to eye position (reverse) gl_apply_inverse(camera.eye) glTranslatef(0.0, 0.0, -znear) # Draw the rotation center, only when realy drawing objects: if selection_box is None: glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glShadeModel(GL_SMOOTH) self.call_list(scene.rotation_center_list) # Now rotate to the model frame and move back to the model center (reverse) gl_apply_inverse(camera.rotation) # Then bring the rotation center at the right place (reverse) gl_apply_inverse(camera.rotation_center) gl_apply_inverse(scene.model_center) scene.draw() if selection_box is not None: # now let the caller analyze the hits by returning the selection # buffer. Note: The selection buffer can be used as an iterator # over 3-tupples (near, far, names) where names is tuple that # contains the gl_names associated with the encountered vertices. return glRenderMode(GL_RENDER) else: # draw the interactive tool (e.g. selection rectangle): glCallList(self.tool.total_list)
def shade_model(cls, mode: ShadingTechnique): glShadeModel(mode.value)
def draw(self, width, height, selection_box=None): scene = context.application.scene camera = context.application.camera glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if selection_box is not None: # set up a select buffer glSelectBuffer(self.select_buffer_size) glRenderMode(GL_SELECT) glInitNames() glMatrixMode(GL_PROJECTION) glLoadIdentity() # Apply the pick matrix if selecting if selection_box is not None: gluPickMatrix(0.5 * (selection_box[0] + selection_box[2]), height - 0.5 * (selection_box[1] + selection_box[3]), selection_box[2] - selection_box[0] + 1, selection_box[3] - selection_box[1] + 1, (0, 0, width, height)) # Apply the frustum matrix znear = camera.znear zfar = camera.znear + camera.window_depth if width > height: w = 0.5*float(width) / float(height) h = 0.5 else: w = 0.5 h = 0.5*float(height) / float(width) if znear > 0.0: glFrustum(-w*camera.window_size, w*camera.window_size, -h*camera.window_size, h*camera.window_size, znear, zfar) else: glOrtho(-w*camera.window_size, w*camera.window_size, -h*camera.window_size, h*camera.window_size, znear, zfar) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Move to eye position (reverse) gl_apply_inverse(camera.eye) glTranslatef(0.0, 0.0, -znear) # Draw the rotation center, only when realy drawing objects: if selection_box is None: glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glShadeModel(GL_SMOOTH) self.call_list(scene.rotation_center_list) # Now rotate to the model frame and move back to the model center (reverse) gl_apply_inverse(camera.rotation) # Then bring the rotation center at the right place (reverse) gl_apply_inverse(camera.rotation_center) gl_apply_inverse(scene.model_center) scene.draw() if selection_box is not None: # now let the caller analyze the hits by returning the selection # buffer. Note: The selection buffer can be used as an iterator # over 3-tupples (near, far, names) where names is tuple that # contains the gl_names associated with the encountered vertices. return glRenderMode(GL_RENDER) else: # draw the interactive tool (e.g. selection rectangle): glCallList(self.tool.total_list)
def initializeGL(self): glClearColor(0.85, 0.85, 0.85, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glLightfv(GL_LIGHT0, GL_POSITION, (0.0, 0.0, 1.0, 0.0)) glEnable(GL_LIGHT0) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.display_list = glGenLists(1) glNewList(self.display_list, GL_COMPILE) glScalef(0.5, 0.5, 0.5) glEnable(GL_LIGHTING) # board glColor3f(0.0, 0.0, 0.0) self.draw_cuboid(4.0, 4.0, 0.16) # USB connector glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(0.0, -1.6, 0.28) self.draw_cuboid(0.75, 0.9, 0.4) glPopMatrix() # right button glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(1.15, -1.85, 0.16) self.draw_cuboid(0.4, 0.3, 0.16) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.155, 0.025) self.draw_cuboid(0.18, 0.1, 0.08) glPopMatrix() # left button glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(-1.15, -1.85, 0.16) self.draw_cuboid(0.4, 0.3, 0.16) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.155, 0.025) self.draw_cuboid(0.18, 0.1, 0.08) glPopMatrix() # left btb top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-1.65, 0.0, 0.38) self.draw_cuboid(0.5, 1.4, 0.9) glPopMatrix() # right btb top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(1.65, 0.0, 0.38) self.draw_cuboid(0.5, 1.4, 0.9) glPopMatrix() # left btb bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-1.65, 0.0, -0.33) self.draw_cuboid(0.5, 1.4, 0.5) glPopMatrix() # right btb bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(1.65, 0.0, -0.33) self.draw_cuboid(0.5, 1.4, 0.5) glPopMatrix() # left bricklet port glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-0.85, 1.8, -0.23) self.draw_cuboid(1.2, 0.4, 0.3) glPopMatrix() # right bricklet port glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(0.85, 1.8, -0.23) self.draw_cuboid(1.2, 0.4, 0.3) glPopMatrix() # left direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-1.05, 1.425, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # top direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.675, 1.8, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # right direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.3, 1.425, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # bottom direction LED glPushMatrix() glColor3f(0.0, 0.5, 0.0) glTranslatef(-0.675, 1.05, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # left y orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(0.275, 1.7, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # right y orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(0.425, 1.7, 0.115) self.draw_cuboid(0.1, 0.2, 0.07) glPopMatrix() # top z orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(0.35, 1.15, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # bottom z orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(0.35, 1.0, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # top x orientation LED glPushMatrix() glColor3f(1.0, 0.0, 0.0) glTranslatef(1.0, 1.15, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # bottom x orientation LED glPushMatrix() glColor3f(0.0, 0.0, 1.0) glTranslatef(1.0, 1.0, 0.115) self.draw_cuboid(0.2, 0.1, 0.07) glPopMatrix() # top alignment corner glPushMatrix() glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glNormal3f(0.0, 0.0, 1.0) glVertex3f(-2.0, -2.0, 0.09) glVertex3f(-1.1, -2.0, 0.09) glVertex3f(-2.0, -1.1, 0.09) glEnd() glPopMatrix() # bottom alignment corner glPushMatrix() glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glNormal3f(0.0, 0.0, -1.0) glVertex3f(-2.0, -2.0, -0.09) glVertex3f(-2.0, -1.1, -0.09) glVertex3f(-1.1, -2.0, -0.09) glEnd() glPopMatrix() glDisable(GL_LIGHTING) # axis glPushMatrix() glTranslatef(-2.3, -2.3, -0.38) glLineWidth(3.0) glBegin(GL_LINES) glColor3f(1,0,0) # x axis is red glVertex3f(0,0,0) glVertex3f(3,0,0) glColor3f(0,0.5,0) # y axis is green glVertex3f(0,0,0) glVertex3f(0,3,0) glColor3f(0,0,1) # z axis is blue glVertex3f(0,0,0) glVertex3f(0,0,3) glEnd() glLineWidth(1.0) glPopMatrix() glEndList()
def initializeGL(self): glClearColor(0.85, 0.85, 0.85, 1.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.display_list = glGenLists(1) glNewList(self.display_list, GL_COMPILE) # Draw board glColor3f(0.0, 0.0, 0.0) self.draw_cuboid(1.0, 1.0, 0.1) # Draw USB connector glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(0.0, -0.8, 0.2) self.draw_cuboid(0.2, 0.25, 0.1) glPopMatrix() # Draw button right glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(0.65, -0.95, 0.125) self.draw_cuboid(0.1, 0.075, 0.05) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.075, 0.0) self.draw_cuboid(0.05, 0.025, 0.045) glPopMatrix() # Draw button left glPushMatrix() glColor3f(0.5, 0.51, 0.58) glTranslatef(-0.65, -0.95, 0.125) self.draw_cuboid(0.1, 0.075, 0.05) glColor3f(0.0, 0.0, 0.0) glTranslatef(0.0, -0.075, 0.0) self.draw_cuboid(0.05, 0.025, 0.045) glPopMatrix() # Draw btb left top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-0.75, 0.0, 0.25) self.draw_cuboid(0.13, 0.5, 0.15) glPopMatrix() # Draw btb right top glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(0.75, 0.0, 0.25) self.draw_cuboid(0.13, 0.5, 0.15) glPopMatrix() # Draw btb left bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-0.75, 0.0, -0.2) self.draw_cuboid(0.13, 0.5, 0.1) glPopMatrix() # Draw btb right bottom glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(0.75, 0.0, -0.2) self.draw_cuboid(0.13, 0.5, 0.1) glPopMatrix() # Draw bricklet port left glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(-0.425, 0.9, -0.125) self.draw_cuboid(0.325, 0.1, 0.05) glPopMatrix() # Draw bricklet port right glPushMatrix() glColor3f(1.0, 1.0, 1.0) glTranslatef(0.425, 0.9, -0.125) self.draw_cuboid(0.325, 0.1, 0.05) glPopMatrix() # Draw Axis glPushMatrix() glTranslatef(-1.2, -1.2, -0.3) glLineWidth(5.0) glBegin(GL_LINES) glColor3f(1,0,0) # x axis is red glVertex3fv((0,0,0)) glVertex3fv((2,0,0)) glColor3f(0,0.5,0) # y axis is green glVertex3fv((0,0,0)) glVertex3fv((0,2,0)) glColor3f(0,0,1) # z axis is blue glVertex3fv((0,0,0)) glVertex3fv((0,0,2)) glEnd() glPopMatrix() glEndList()