Added 3d_view.py

Basic code to handle necessary opengl objects for 3d_view.py.
This commit is contained in:
Phyks 2013-10-02 22:45:51 +02:00
parent 0c10e9f0b3
commit 8b55b5eab5
1 changed files with 54 additions and 0 deletions

54
3d_view.py Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env python
import pyglet
import pyglet.gl as gl
window = pyglet.window.Window()
@window.event
def on_draw():
# Reset
# =====
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
# Camera view
# ===========
gl.gluPerspective(70, window.width / window.height, 1, 1000)
gl.gluLookAt(2, 1, 1, 0, 0, 0, 0, 0, 1)
# Draw the cube
# =============
gl.glBegin(gl.GL_QUADS)
# Left face
gl.glColor3f(1.0, 0, 0)
gl.glVertex3f(1, -1, -1)
gl.glVertex3f(1, -1, 1)
gl.glVertex3f(-1, -1, 1)
gl.glVertex3f(-1, -1, -1)
# Right face
gl.glColor3f(0, 1.0, 0)
gl.glVertex3f(-1, -1, 1)
gl.glVertex3f(-1, 1, 1)
gl.glVertex3f(-1, 1, -1)
gl.glVertex3f(-1, -1, -1)
#Bottom face
gl.glColor3f(0, 0, 1.0)
gl.glVertex3f(1, -1, -1)
gl.glVertex3f(-1, -1, -1)
gl.glVertex3f(-1, 1, -1)
gl.glVertex3f(1, 1, -1)
gl.glEnd()
gl.glColor3f(0, 0, 0)
pointer = gl.gluNewQuadric()
gl.gluSphere(pointer, 0.1, 20, 20)
pyglet.app.run()