0% found this document useful (0 votes)
24 views2 pages

C Cubi

The document contains code for drawing a rotating cube in OpenGL using Python. It defines functions for initializing OpenGL, drawing the cube, and contains the main loop. The cube is drawn using quads and rotated around the x-axis over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

C Cubi

The document contains code for drawing a rotating cube in OpenGL using Python. It defines functions for initializing OpenGL, drawing the cube, and contains the main loop. The cube is drawn using quads and rotated around the x-axis over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

from OpenGL.

GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

X_AXIS = 0.0
Y_AXIS = 0.0
Z_AXIS = 0.0

def InitGL(Width, Height):

glClearColor(0.0, 0.0, 0.0, 0.0)


glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)

def DibujaCubo():
global X_AXIS,Y_AXIS,Z_AXIS

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glLoadIdentity()
glTranslatef(0.0,0.0,-6.0)

glRotatef(X_AXIS,1.0,0.0,0.0)

glBegin(GL_QUADS)

glColor3f(0.0,1.0,0.0)
glVertex3f( 1.0, 1.0,-1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f( 1.0, 1.0, 1.0)

glColor3f(1.0,0.0,0.0)
glVertex3f( 1.0,-1.0, 1.0)
glVertex3f(-1.0,-1.0, 1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f( 1.0,-1.0,-1.0)

glColor3f(0.0,1.0,1.0)
glVertex3f( 1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0,-1.0, 1.0)
glVertex3f( 1.0,-1.0, 1.0)

glColor3f(1.0,1.0,0.0)
glVertex3f( 1.0,-1.0,-1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f( 1.0, 1.0,-1.0)

glColor3f(0.0,0.0,1.0)
glVertex3f(-1.0, 1.0, 1.0)
glVertex3f(-1.0, 1.0,-1.0)
glVertex3f(-1.0,-1.0,-1.0)
glVertex3f(-1.0,-1.0, 1.0)

glColor3f(1.0,0.0,1.0)
glVertex3f( 1.0, 1.0,-1.0)
glVertex3f( 1.0, 1.0, 1.0)
glVertex3f( 1.0,-1.0, 1.0)
glVertex3f( 1.0,-1.0,-1.0)

glEnd()

X_AXIS = X_AXIS - 0.30

glutSwapBuffers()
glFlush()

def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(640,480)
glutInitWindowPosition(200,200)
glutCreateWindow(b'OpenGL Python Cube')
glutDisplayFunc(DibujaCubo)
glutIdleFunc(DibujaCubo)
InitGL(640, 480)
glutMainLoop()

if __name__ == "__main__":
main()

You might also like