View Full Version : Understanding certain elements

03-09-2004, 03:51 PM
I am new to opengl and been writing all the basic hello world examples and was just wondering on certain function on what they do. I have comments describing what they mean. I would like to know what some of the ones I don't know do and why. Thanx in advance.

#include <GL/gl.h>
#include <GL/glut.h>

void display(void){
glClear(GL_COLOR_BUFFER_BIT); /*Actually clears the buffer to what*/
/*you defined earlier in */
glColor3f(0.0,0.0,1.0); /*sets drawing color*/
glBegin(GL_LINES); /*tells what the figure will be*/
glVertex3f(0.25,0.25,0.0);/*all the coordiantes*/
glEnd(); /*lets compiler know it is done*/
glFlush(); /*flushes to the buffer*/

int main(int argc,char **argv){
glutInit(&amp;argc,argv); /*Gets info for arguments of program*/
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); /*Need a little help*/
/*understanding this*/
glutInitWindowSize(250,250); /*creates Window Size*/
glutInitWindowPosition(100,100);/*Sets window position*/ glutCreateWindow("Iris"); /*sets name of window*/
glClearColor(0.0,0.0,0.0,0.0); /*tells what color to clear screen*/
glMatrixMode(GL_PROJECTION); /*need a little help understanding*/
glLoadIdentity(); /*have no clue what this does*/
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);/*sets limit to how big coordinates*/
glutDisplayFunc(display); /*Run function to display window*/
glutMainLoop(); /*keeps wndow open*/
return 0;

03-09-2004, 04:34 PM
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); I don't actually know glut but presumably this creates a window and sets up opengl, the GLUT_RGB tells GLUT to use rgb color values insted of an indexed palatte, and GLUT_SINGLE is a single buffered window.

Things I actually know for sure:
OpenGL transforms the coordinates you supply by using two 4x4 matrices (there are others but lets stick with two for now). glMatrixMode sets which matrix you are transforming, and GL_PROJECTION specifies the projection matrix. Matrices are generally combined by multiplication, so you need to initialize the matrix to 1 to get the expected results. glLoadIdentity() loads an identity matrix which is the matrix equivalent of 1. Hope that makes sense.

On another note you should add glMatrixMode(GL_MODELVIEW) after glOrtho. This is because although vertices are transformed by both the modelview and projection matrices, things like fog and lighting do not take both into account. If you do further transformations on the projection matrix and try and use fog or lighting it will not work right. So make sure you do all transformations except the glOrtho to the modelview matrix, it will save headaches down the road.

Edit: Spelling

[This message has been edited by chowe6685 (edited 03-09-2004).]