/* This document gives a few tips on programming in C/OpenGL The order in which you write your methods is important. You cannot call a method unless the method is physically ABOVE the call in your code. The order in main() is especially important. Remember not to call the keyboard callback until you have set up the window. Debugging: 1) BLANK SCREEN APPEARS INSTEAD OF IMAGE -check to see if you are using single/double buffering correctly. Most of the time you'll be using double buffering, which means you must always remember to call glutSwapBuffers() in the display method; otherwise your image, drawn first on the back buffer, will not appear (you'll get a gray screen instead). -if you're sure whether this is the problem, try clearing to a different color in glClearColor(). If your screen does not appear in this color then you are probably starting on the back buffer. -if your 2) IMAGE FLIES OFF THE SCREEN WHEN YOU CLICK ON IT -in this case it's most likely that you forgot to put glPushMatrix() and glPopMatrix() in the display method. If you are doing any affine transformations then each time the display method is called (if you do not use glPushMatrix() and glPopMatrix()), then the image will be redrawn from where the last screen stopped drawing. That is, if you draw a box, then translate -40 in the x direction and draw another box, each time the display method is called it will start -40 more in the x direction, meaning that pretty soon you won't see your image anymore! 3) INCORRECT LIGHTING EFFECTS WITH ANIMATION -when you want a light that does not move with respect to the eye (meaning that you are physically moving your object, not the camera), then you want to set up a light before display() is called. 4) EXTRA LIGHTING TIPS -the fourth coordinate of the light position is very important! For example, the light position {1.0,2.0,3.0,0.0} means that the light is a distant light source with a direction vector (1.0,2.0,3.0). When the fourth coordinate is 1.0, then the light is a point source (what you need for a spotlight effect). 5) SETTING UP TEXTURE MAPPING -if using more than one texture, create an array and load each texture into the array (call twLoadTexture(int texNum, char* filename) each time). -before drawing object, specify the material color (twColor(..)) under the texture. -bind texture to object -enable texture, and enable the generation of coordinates onto which you are mapping if applicable -draw object -disable texture, disable generation of coords 6) MATH TIPS -make sure you convert degrees/radians when necessary. glRotatef(...) takes degrees as its first argument, but the math operations all take radians! -degrees to radians: multiply angle by (PI/180) -radians to degrees: multiply angle by (180/PI) */