Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from OpenGL.GL import *
- from OpenGL.GLU import *
- from pygame.locals import *
- vertices = (
- (1, 1, 1),
- (1, -1, 1),
- (-1, -1, 1),
- (-1, 1, 1),
- (1, 1, -1),
- (1, -1, -1),
- (-1, -1, -1),
- (-1, 1, -1)
- )
- edges = (
- (0, 1),
- (2, 3),
- (4, 5),
- (6, 7),
- (0, 1),
- (5, 4),
- (3, 2),
- (6, 7),
- (0, 3),
- (7, 4),
- (1, 2),
- (6, 5)
- )
- def draw_object():
- glPushMatrix()
- glColor3f(0, 1, 0)
- glBegin(GL_QUADS)
- x = 0
- for edge in edges:
- x = x + 1
- for vertex in edge:
- glVertex3iv(vertices[vertex])
- glEnd()
- glPopMatrix()
- def main():
- pygame.init()
- display = (800,600)
- pygame.display.set_caption("05 Lab 1")
- pygame.display.set_mode(display, DOUBLEBUF|OPENGL|RESIZABLE)
- glEnable(GL_DEPTH_TEST)
- gluPerspective(40, (display[0]/display[1]), 1, 150)
- glTranslatef(0.0, 0.0, -10)
- glRotatef(0, 1, 0, 0)
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- if event.type==pygame.KEYDOWN:
- if event.key==pygame.K_UP:
- glTranslatef(0, 0, 0.5)
- if event.key==pygame.K_DOWN:
- glTranslatef(0,0, -0.5)
- keys=pygame.key.get_pressed()
- if keys[K_w]:
- glTranslatef(0, 0.5, 0)
- if keys[K_s]:
- glTranslatef(0, -0.5, 0)
- if keys[K_a]:
- glTranslatef(-0.5, 0, 0)
- if keys[K_d]:
- glTranslatef(0.5, 0, 0)
- glRotatef(1, 1, 2, 1)
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
- draw_object()
- pygame.display.flip()
- pygame.time.wait(10)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement