I’m having some difficulty figuring out how to do a few of the basic things that I’m looking to do in opengl. I’ve been using the Red Book. In addressing my question, you should know that
i. I know the math.
ii. I know how to program.
iii. I’ve taken a computer graphics class at
UCLA, so I know what I want to do here.
I’m looking to define my own 3D polygons. I’ve got the basic data structure in mind (vertices, normals, faces, etc.). The only thing is that whenever the Red Book draws something, it calls a glut function such as glutSolidCube.
My question is basically once I’ve got my 3d polygon defined, exactly how do I use opengl to transform all the vertices. All of the opengl matrix multiplication commands I’ve seen are of the form
Matrix X Matrix -> Matrix
I need something of the form
Matrix X Vector -> Vector
Any help that is offered will be appreciated.
You don’t transform your vertices individually. You set up the projection and modelview matrices, and OpenGL automatically applies those transforms to all vertices you pass to it.
Which do I do first, set up the matrices or define the vertices (or does it matter)?
I assume I have to set up the matrices before I draw the vertices.
Thanx for your help
I suggest you to consult the openGL specifications, especially this section: http://trant.sgi.com/opengl/docs/Specs/glspec1.1/node14.html#1986
And yes, the modelview and projection matrices are set before you send any of your vertices to be rendered. So a basic transformation pipeline would be something like this:
Load vertex coordinates and possible texture coordinates and normals and store them in separete arrays or any other format suitable for your application. Then for every frame set up your modelview matrix to represent current transformation. Render the original vertices using any of the function calls available, like glDrawElements or glBegin/glEnd pairs. (This is the part where the vertices are multiplied with the transformation and projection matrices.)