OpenGL Pentagon Example
Fall 2013
- v1.cpp, which draws a polygon using
immediate-mode calls to
glVertex
- v2.cpp, which replaces the now-deprecated
GL_POLYGON
with three GL_TRIANGLES
- v3.cpp, which moves the vertices into a
client-side array, which we index into in calling
glVertex
- v4.cpp, which replaces nine calls to
glVertex
with one call to glDrawArrays
.
In order to do this, it needs to use OpenGL's "client-side vertex array" --
a client-side array that OpenGL knows about, so it can retrieve the data from it
- v5.cpp, which replaces
glDrawArrays
with glDrawElements
. This allows
us to specify only the indices of the vertices rather than re-specifying
the vertices themselves
- v6.cpp, which stores the array of vertices
in a "buffer" on the GPU rather than on the client side. This is the first
version that needs to explicitly identify what attribute(s) it's sharing
with the GLSL program. (I'm not sure how previous versions got away without
that....)
- v7.cpp, which uses TWO buffers -- one for
vertex positions and one for vertex colors -- "wrapped up" in a single
vertex array object. The result is a smear of color that my wife calls
a "rainbow pentagon". (To handle color, we need different vertex and
fragment shaders; see vpassthru.glsl and fpassthru.glsl.)
- v8.cpp, which replaces the smear of color
with several monochromatic triangles. (This program uses the same
shaders as version 7.)
- More versions to come, as I figure out how to make them
work...
- AngelInitShader.cpp, which all of the
above main programs use to read in the GLSL programs
- GrecoInitShader.cpp, Dan
Greco's modified version of the above. (I then modified it further.
The version I've posted here is working for me, from the command line,
and I think it works in Visual Studio as well.)
- Angel.h, my slightly modified version of
Angel's header file, declaring
InitShader
to take in
string
parameters rather than const char
*
. You'll also need to make sure you have Angel's supporting
header files mat.h
, vec.h
, and perhaps
CheckError.h
. Oddly enough, Angel supplies about five
not-quite-identical versions of each of those files; it's not clear
which one is best to use.
- Makefile, which controls the
compiling-and-linking process. You should be able to type make
v4, and it'll compile and link v4.cpp to produce an
executable named v4, which you can then run directly.
- vshader21.glsl, the vertex shader
program for versions 1-6
- fshader21.glsl, the fragment shader
program for versions 1-6
- init-shader.rkt, a Racket version
of
InitShader.cpp
, to go with the following...
- v1.rkt, a Racket version of v1.cpp
- v2.rkt, a Racket version of v2.cpp
- v3.rkt, a Racket version of v3.cpp
- v4.rkt, a Racket version of v4.cpp
- v5.rkt, a Racket version of v5.cpp
- v6.rkt, a Racket version of v6.cpp