OpenGL makes it easy to create complex surfaces such as line strips, triangle strips and quad strips. A strip uses the last set of coordinates of one object as the first set for the next object. By far the easiest to understand is the Line Strip. The comments after each vertex explain it best.
' a line stripCALL ClearView eyeX , eyeY , eyeZ , centerX , centerY , centerZ , upX , upY , upZ
CALL glColor4fv 1 , 0 , 0 , 1CALL glBegin GL.LINE.STRIPCALL glVertex 0 , 0 , 0'start of first lineCALL glVertex 1 , 1 , 0'end of first line, start of second lineCALL glVertex .5 , 1.5 , 0'end of second line, start of third lineCALL glVertex -1 , .5 , 0'end of third line, start of fourth lineCALL glVertex -1.5 , 1.5 , 0'end of fourth lineCALL glEnd
CALL RefreshView
WAIT
For a triangle strip the first three vertices describe the first triangle. Then the fourth vertex along with the previous two describe the next triangle, and so on. Since I couldn't make up my mind which color to use for the first triangle, this snippet also demonstrates how to convert normal RGB values for use with OpenGL.
' a triangle stripCALL ClearView eyeX , eyeY , eyeZ , centerX , centerY , centerZ , upX , upY , upZ
COLORDIALOG "", chosen$
red =val(word$(chosen$,1))/255
green =val(word$(chosen$,2))/255
blue =val(word$(chosen$,3))/255CALL glColor4fv red , green , blue , 1CALL glBegin GL.TRIANGLE.STRIPCALL glVertex -1 , -1 , 0'first set triangle coordinatesCALL glVertex -1 , 1 , 0'second set triangle coordinatesCALL glVertex 1 , 1 , 0'third set triangle coordinatesCALL glColor4fv 1 , 1 , 0 , 1'change color to make it easier to tell triangles apartCALL glVertex .5 , 1.5 , 0'coordinate for second triangle, along with the previous twoCALL glColor4fv 0 , 0 , 0 , 1CALL glVertex 2 , 1.25 , 0'coordinate for third triangle, along with the previous twoCALL glEnd
CALL RefreshView
WAIT
The same principle applies for quad strips.
' a quad stripCALL ClearView eyeX , eyeY , eyeZ , centerX , centerY , centerZ , upX , upY , upZ
CALL glColor4fv 1 , 0 , 1 , 1CALL glBegin GL.QUAD.STRIP'coordinates for first quadCALL glVertex -.5 , -.5 , 0CALL glVertex 0 , -.5 , 0CALL glVertex -.25 , 0 , 0CALL glVertex .25 , 0 , 0CALL glColor4fv 0 , 0 , 0 , 1'coordinates for second quad, along with the previous twoCALL glVertex .25 , .5 , 0CALL glVertex .75 , .5 , 0CALL glColor4fv 0 , 1 , 0 , 1'coordinates for third quad, along with the previous twoCALL glVertex .25 , 1 , 0CALL glVertex .75 , 1 , 0CALL glEnd
CALL RefreshView
WAIT
OpenGL also has the ability to create polygons, shapes with 3 or more sides. There is no practical limit to the number of sides in a polygon but there shouldn't be any concave areas (indentations).
OpenGL 3D Graphics in Liberty BASIC
Lesson Five: Complex surfaces
by Robert McAllisterOpenGL makes it easy to create complex surfaces such as line strips, triangle strips and quad strips. A strip uses the last set of coordinates of one object as the first set for the next object. By far the easiest to understand is the Line Strip. The comments after each vertex explain it best.
For a triangle strip the first three vertices describe the first triangle. Then the fourth vertex along with the previous two describe the next triangle, and so on. Since I couldn't make up my mind which color to use for the first triangle, this snippet also demonstrates how to convert normal RGB values for use with OpenGL.
The same principle applies for quad strips.
OpenGL also has the ability to create polygons, shapes with 3 or more sides. There is no practical limit to the number of sides in a polygon but there shouldn't be any concave areas (indentations).
In the next lesson we will start "Creating shapes"