Changed example from quads to triangles
This commit is contained in:
parent
769d34473e
commit
06c8c3623e
1 changed files with 20 additions and 7 deletions
|
|
@ -7,20 +7,23 @@ import glu
|
||||||
proc display() {.cdecl.} =
|
proc display() {.cdecl.} =
|
||||||
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) # Clear color and depth buffers
|
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) # Clear color and depth buffers
|
||||||
glMatrixMode(GL_MODELVIEW) # To operate on model-view matrix
|
glMatrixMode(GL_MODELVIEW) # To operate on model-view matrix
|
||||||
|
|
||||||
# Render a color-cube consisting of 6 quads with different colors
|
|
||||||
glLoadIdentity() # Reset the model-view matrix
|
glLoadIdentity() # Reset the model-view matrix
|
||||||
glTranslatef(1.5, 0.0, -7.0) # Move right and into the screen
|
glTranslatef(1.5, 0.0, -7.0) # Move right and into the screen
|
||||||
|
|
||||||
glBegin(GL_QUADS) # Begin drawing the color cube with 6 quads
|
# Render a cube consisting of 6 quads
|
||||||
|
# Each quad consists of 2 triangles
|
||||||
|
# Each triangle consists of 3 vertices
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES) # Begin drawing of triangles
|
||||||
|
|
||||||
# Top face (y = 1.0f)
|
# Top face (y = 1.0f)
|
||||||
# Define vertices in counter-clockwise (CCW) order with normal pointing out
|
|
||||||
glColor3f(0.0, 1.0, 0.0) # Green
|
glColor3f(0.0, 1.0, 0.0) # Green
|
||||||
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)
|
||||||
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)
|
||||||
|
glVertex3f( 1.0, 1.0, -1.0)
|
||||||
|
glVertex3f(-1.0, 1.0, 1.0)
|
||||||
|
|
||||||
# Bottom face (y = -1.0f)
|
# Bottom face (y = -1.0f)
|
||||||
glColor3f(1.0, 0.5, 0.0) # Orange
|
glColor3f(1.0, 0.5, 0.0) # Orange
|
||||||
|
|
@ -28,6 +31,8 @@ proc display() {.cdecl.} =
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
# Front face (z = 1.0f)
|
# Front face (z = 1.0f)
|
||||||
glColor3f(1.0, 0.0, 0.0) # Red
|
glColor3f(1.0, 0.0, 0.0) # Red
|
||||||
|
|
@ -35,6 +40,8 @@ proc display() {.cdecl.} =
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
# Back face (z = -1.0f)
|
# Back face (z = -1.0f)
|
||||||
glColor3f(1.0, 1.0, 0.0) # Yellow
|
glColor3f(1.0, 1.0, 0.0) # Yellow
|
||||||
|
|
@ -42,13 +49,17 @@ proc display() {.cdecl.} =
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
# Left face (x = -1.0f)
|
# Left face (x = -1.0f)
|
||||||
glColor3f(0.0, 0.0, 1.0) # Blue
|
glColor3f(0.0, 0.0, 1.0) # Blue
|
||||||
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)
|
||||||
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)
|
||||||
|
glVertex3f(-1.0, 1.0, 1.0)
|
||||||
|
glVertex3f(-1.0, -1.0, -1.0)
|
||||||
|
|
||||||
# Right face (x = 1.0f)
|
# Right face (x = 1.0f)
|
||||||
glColor3f(1.0, 0.0, 1.0) # Magenta
|
glColor3f(1.0, 0.0, 1.0) # Magenta
|
||||||
|
|
@ -56,6 +67,8 @@ proc display() {.cdecl.} =
|
||||||
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)
|
||||||
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() # End of drawing
|
glEnd() # End of drawing
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue