



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A step-by-step tutorial on creating a simple opengl window using visual c++ and the opengl utility toolkit (glut). It covers setting up the visual c++ environment, entering and compiling the code, and executing the program. The tutorial also includes instructions on how to handle errors and execute the program.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Visua l C+ + Tut or ia l CSE 1 6 7 , W int e r 2 0 0 3 Fa r ha na Ba nduk w a la
One of t he best ways t o begin underst anding t he st ruct ure and st yle of a t ypical OpengGL program is t o ent er, com pile, and run a sm all exam ple. The list ing below cont ains a sim ple program which uses OpenGL Ut ilit y Toolkit ( GLUT) t o open a window. I f t his is t he first t im e you’ve seen t his sort of program , it probably will not m ake a lot of sense init ially. Don’t worry about t hat. For now, t he goal is t o use t he Visual C+ + environm ent t o creat e, com pile and execut e t his sim ple program.
//simplewindow.cpp #include <windows.h> #include <gl\glut.h>
// Called to draw scene void renderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//drawing code here
glFlush(); }
void initState(void) { glClearColor(0.0f,0.0f,0.0f,1.0f); }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow("Simple Window"); glutDisplayFunc(renderScene);
initState();
glutMainLoop();
This sm all program does t hree t hings. First it init ializes t he glut library, and creat es a window. Next , it set s up t he display callback ( renderScene) and last it init iat es t he m ain event loop ( glut MainLoop). We will discuss t he det ails of t his program st ruct ure in subsequent classes. For now, t his helps you set up t he Visual C+ + environm ent and get a piece of OpenGL code com piled.
Tut orial St eps:
What you see now is " norm al". Along t he t op is t he m enu bar and several t oolbars. Along t he bot t om is a st at us window where various m essages will be displayed.
The first opt ion sim ply com piles t he source file list ed and form s t he obj ect file for it. This opt ion does not perform a link, so it is useful only for quickly com piling a file t o check for errors. The second opt ion com piles all of t he source files in t he proj ect t hat have been m odified since t he last build, and t hen links t hem t o form an execut able. The t hird opt ion recom piles all of t he source files in t he proj ect and relinks t hem. I t is a " com pile and link from scrat ch" opt ion t hat is useful aft er you change cert ain com piler opt ions or m ove t o a different plat form.