Created
January 3, 2014 12:51
-
-
Save pedesen/8237422 to your computer and use it in GitHub Desktop.
Code zum OpenGL in Pygame Tutorial - Part 3 (http://pypede.wordpress.com/2009/09/05/opengl-in-pygame-tutorial-part-3/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from sys import exit | |
from OpenGL.GL import * | |
from OpenGL.GLU import * | |
def reshape((width,height)): | |
glViewport(0, 0, width, height) | |
glMatrixMode(GL_PROJECTION) | |
glLoadIdentity() | |
gluPerspective(60, 1.0*width/height, 0.1, 1000.0) | |
glMatrixMode(GL_MODELVIEW) | |
def init(): | |
screen = (800,600) | |
pygame.init() | |
surface = pygame.display.set_mode(screen, pygame.OPENGL|pygame.DOUBLEBUF, 16) | |
pygame.display.set_caption("Hallo Welt!") | |
glClearColor(1.0, 1.0, 1.0, 1.0) | |
reshape(screen) | |
def get_event(): | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
exit() | |
def draw(): | |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) | |
glLoadIdentity() | |
gluLookAt(0, 0, 6, 0, 0, -100, 0, 1 ,0) | |
glBegin(GL_QUADS) | |
glColor(0, 0, 1.0) | |
glVertex2f(-2, 2) # oben links | |
glVertex2f(2, 2) # oben rechts | |
glVertex2f(2, -1) # unten rechts | |
glVertex2f(-2, -1) # unten links | |
glEnd() | |
pygame.display.flip() | |
def main(): | |
init() | |
maxfps = 100 | |
clock = pygame.time.Clock() | |
while True: | |
clock.tick(maxfps) | |
draw() | |
get_event() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment