Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import*
- from OpenGL.GL import*
- from OpenGL.GLU import*
- def draw_cube():
- glBegin(GL_SQUARE)
- glColor(1, 0, 0)
- glVertex3f(0, 1, 0)
- glVertex3f(-1, -1, 1)
- glVertex3f(1, -1, 1)
- glColor(0, 1, 0)
- glVertex3f(0, 1, 0)
- glVertex3f(1, -1, 1)
- glVertex3f(1, -1, -1)
- glColor(1, 1, 0)
- glVertex3f(0, 1, 0)
- glVertex3f(1, -1, -1)
- glVertex3f(-1, -1, -1)
- glColor(0, 0, 1)
- glVertex3f(0, 1, 0)
- glVertex3f(-1, -1, -1)
- glVertex3f(-1, -1, 1)
- glColor(1, 0, 0)
- glVertex3f(0, 3, 0)
- glVertex3f(1, -1, 1)
- glVertex3f(-1, -1, 1)
- glColor(1, 1, 0)
- glVertex3f(0, 3, 0)
- glVertex3f(-1, -1, -1)
- glVertex3f(1, -1, -1)
- glColor(0, 1, 0)
- glVertex3f(0, -3, 0)
- glVertex3f(1, -1, -1)
- glVertex3f(1, -1, 1)
- glColor(0, 0, 1)
- glVertex3f(0, 3, 0)
- glVertex3f(-1, -1, 1)
- glVertex3f(-1, -1, -1)
- glEnd()
- def main():
- pygame.init()
- display = (800, 600)
- pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
- pygame.display.set_caption("05 Performance Task 01")
- gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)
- glTranslatef(0.0, 0.0, -5)
- glScalef(0.5, 0.5, 0.5)
- glRotatef(180, 0, 0, 1)
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_a:
- glTranslatef(-1, 0, 0)
- glScalef(1, 1, 1)
- if event.key == pygame.K_d:
- glTranslatef(1, 0, 0)
- glScalef(1, 1, 1)
- if event.key == pygame.K_w:
- glTranslatef(0, 1, 0)
- glScalef(-1, -1, -1)
- if event.key == pygame.K_s:
- glTranslatef(0, -1, 0)
- glScalef(-1, -1, -1)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- draw_cube()
- pygame.display.flip()
- pygame.time.wait(30)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement