Steps to Write a Simple OpenGL Program - 1
1) Include the neccessary header files
2) The code
In main(int argc, char* argv[] )
i) [Optional] Call glutInit(&argc, argv)
To initialize the glut with program options arguments.
ii) Call glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH)
Input arguments are ORed together.
iii) [Optional] Call glutInitWindowSize(800,600)
Create a window of that particular size.
iv) Call glutCreateWindow("Name of Window")
Crates an OpenGL-enabled Window.
v) Call glutReshapeFunc(ChangeSize)
Sets the window reshape event for the current window
vi) Call glutDisplayFunc(RenderScene)
Tells GLUT which function to call whenever the windows contents must be drawn.
Occurs when the GLUT window is resized, uncovered, asked to redraw with call to glutPostRedisplay.
Takes in a function of type void redrawFunction(void)
vii) Call our own initialize function - e.g. SetupRC()
SetupRC() is for initializing the background color, etc.
viii) Call glutMainLoop()
Begins the GLUT main event-handling loop. This function does not return until program terminates.
2) The code
In main(int argc, char* argv[] )
i) [Optional] Call glutInit(&argc, argv)
To initialize the glut with program options arguments.
ii) Call glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH)
Input arguments are ORed together.
iii) [Optional] Call glutInitWindowSize(800,600)
Create a window of that particular size.
iv) Call glutCreateWindow("Name of Window")
Crates an OpenGL-enabled Window.
v) Call glutReshapeFunc(ChangeSize)
Sets the window reshape event for the current window
- What the reshape function handler does is to ensure that we’re working with square pixels. If we don’t ensure that, when our window changes size, it will still have the same “dimensions”, meaning our objects will be oblongated or squeezed.
- Whenever a reshape occurs, the function being passed to the glutReshapeFunc will be called.
- The function should have the signature of void function(int x, int y)
- x - new width
- y - new height of the window
vi) Call glutDisplayFunc(RenderScene)
Tells GLUT which function to call whenever the windows contents must be drawn.
Occurs when the GLUT window is resized, uncovered, asked to redraw with call to glutPostRedisplay.
Takes in a function of type void redrawFunction(void)
vii) Call our own initialize function - e.g. SetupRC()
SetupRC() is for initializing the background color, etc.
viii) Call glutMainLoop()
Begins the GLUT main event-handling loop. This function does not return until program terminates.

0 Comments:
Post a Comment
<< Home