def run(): pygame.init() screen = pygame.display.set_mode(SCREEN_SIZE, FULLSCREEN | HWSURFACE | OPENGL | DOUBLEBUF) resize(*SCREEN_SIZE) init() # Read the skybox model sky_box = model3d.Model3D() sky_box.read_obj('tanksky/skybox.obj') # Set the wraping mode of all textures in the sky-box to GL_CLAMP_TO_EDGE for material in sky_box.materials.itervalues(): glBindTexture(GL_TEXTURE_2D, material.texture) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) # Used to rotate the world mouse_x = 0.0 mouse_y = 0.0 # Don't display the mouse cursor pygame.mouse.set_visible(False) while True: for event in pygame.event.get(): if event.type == QUIT: return if event.type == KEYDOWN: return # We don't need to clear the color buffer (GL_COLOR_BUFFER_BIT) # because the skybox covers the entire screen glClear(GL_DEPTH_BUFFER_BIT) glLoadIdentity() mouse_rel_x, mouse_rel_y = pygame.mouse.get_rel() mouse_x += float(mouse_rel_x) / 5.0 mouse_y += float(mouse_rel_y) / 5.0 # Rotate around the x and y axes to create a mouse-look camera glRotatef(mouse_y, 1, 0, 0) glRotatef(mouse_x, 0, 1, 0) # Disable lighting and depth test glDisable(GL_LIGHTING) glDepthMask(False) # Draw the skybox sky_box.draw_quick() # Re-enable lighting and depth test before we redraw the world glEnable(GL_LIGHTING) glDepthMask(True) # Here is where we would draw the rest of the world in a game pygame.display.flip()
def run(): pygame.init() screen = pygame.display.set_mode(SCREEN_SIZE, HWSURFACE | OPENGL | DOUBLEBUF) resize(*SCREEN_SIZE) init() clock = pygame.time.Clock() # lê o modelo tank_model = model3d.Model3D() tank_model.read_obj('mytank.obj') rotation = 0.0 while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() quit() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) time_passed = clock.tick() time_passed_seconds = time_passed / 1000. glLoadIdentity() glRotate(15, 1, 0, 0) glTranslatef(0.0, -1.5, -3.5) rotation += time_passed_seconds * 45.0 glRotatef(rotation, 0, 1, 0) tank_model.draw_quick() pygame.display.flip()
def paintGL(self): PyGLWidget.paintGL(self) # glBegin(GL_TRIANGLES) # glColor3f(1,0,0) # glVertex3f(0,0,0) # glColor3f(0,1,0) # glVertex3f(0,1,0) # glColor3f(0,0,1) # glVertex3f(1,1,0) # glEnd() # Read the model tank_model = model3d.Model3D() tank_model.read_obj('mytank.obj') tank_model.draw_quick()