Problem with pygame with open GL.

Problem with pygame with open GL.

Postby lynx » Mon Apr 04, 2016 5:54 pm

The triangle keeps shrinking/getting farther away. I have determined that the glRotatef on line 66 is to blame.I have no idea how to stop it. Code:
Code: Select all
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

verticies = (
    (0, -1, -1),
    (0, 1, -1),
    (0, 0, 1),
    )


edges = (
    (0, 1),
    (0, 2),
    (1, 2)
    )

def drawCube():

   
    glBegin(GL_LINES)
    for edge in edges:
        for vertex in edge:
            glColor3fv((1, 0, 0))
            glVertex3fv(verticies[vertex])
   
    glEnd()

def main():
    pygame.init()
    display = (800, 600)
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

    gluPerspective(45.0, (display[0]/display[1]), 0.0, 50.0)

    glTranslatef(0.0,0.0,-30.0)

    glRotatef(90, 0, 1, 0)
    rotate = 0
    move = 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 == K_UP:
                    move = .1
                   
                elif event.key == K_RIGHT:
                    rotate = 1
                   
                elif event.key == K_LEFT:
                    rotate = -1
               
            if event.type == pygame.KEYUP:
                if event.key == K_RIGHT or event.key == K_LEFT:
                    rotate = 0
                elif event.key == K_UP:
                    move = 0
                               
        glTranslatef(0, 0, move)
        glRotatef(3, rotate, 0, 0)       
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        drawCube()
        pygame.display.flip()
        pygame.time.wait(10)
   
main()
Last edited by micseydel on Mon Apr 04, 2016 6:01 pm, edited 1 time in total.
Reason: Code tags. Initial post lock.
lynx
 
Posts: 1
Joined: Mon Apr 04, 2016 5:38 pm

Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 2 guests