


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
An overview of a software framework for drawing geometry in 2d or 3d using opengl. It covers downloading and using the framework, understanding relevant opengl commands, and drawing 2d geometry. Students will focus on geometry and graphics rather than software engineering. The framework simplifies opengl interactions and spares students from the messier details.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Fall 2005
Linked from the Homework and Labs page of the class web site is a zip file containing a code framework you can use for your labs. The framework is a general platform for drawing geometry in 2D or 3D through OpenGL. It has facilities for opening a single OpenGL window, detecting keystrokes and mouse events, and entering text commands. These facilities should be more than sufficient for the projects assigned this semester. We want you to focus on geometry and graphics, not software engineering.
Another purpose of the software framework is to spare you the messier details of inter- acting with OpenGL. OpenGL is a large and powerful API, with hundreds of options and function calls. For the first two programming labs (and also for lab 0), you will only need to call about a half-dozen different GL calls. The second part of this tutorial will cover the GL interfaces you should be familiar with.
Download the software framework from the class web site. Inside the archive are several files with the name Demo, each with a different suffix. These are Visual Studio’s support files. The one you want to open is Demo.sln, which the Windows GUI labels as “Microsoft Visual Studio Solution Object.” This is the main project file.
There are two subdirectories that contain source code. You should not need to worry about the code in the Common/ directory. The Rendering/ directory contains three files:
You should read through the Callbacks.cpp file to get an idea of what the program can do. The order in which functions are called, and the commands you will need to draw geometry, are discussed in the next section.
You can learn as much about OpenGL as you need to succeed in Comp 360 in about an hour. If you’re interested in more details about the OpenGL API, I recommend spending a week reading through the OpenGL Programming Guide (the “Red Book”)– there is a link with details about this book on the class web site. For now, you can get by with just the functions covered here.
The framework we provide calls the callback functions in this order:
call the initCallback(); Loop forever: clear the old frame draw the new frame: call setGluLookAt(); call renderFunc(); draw a framerate counter handle new user input (keystrokes, etc.) by calling appropriate callbacks call idleFunc();
The idea is that the location in 3D space of OpenGL’s camera is set in the setGluLookAt() function, and then everything is rendered in the ensuing call to renderFunc(). In many of your labs, you will want to draw 2D geometry, not 3D. To override the 3D camera and draw in 2D, you call the static function OpenGLFrame::setOrthographicProjection(); to return to 3D, call OpenGLFrame::resetPerspectiveProjection(). (Later on in the course, Dr. Goldman will explain the math behind projections. For now, you can equate ”orthographic” to 2 dimensions, and ”perspective” to 3 dimensions.)
Since your first two labs will deal entirely with 2 dimensional geometry, the provided framework code already calls setOrthographicProjection() and resetPerspectiveProjection() in the body of renderFunc(). For now, all your drawing code should fall between these two function calls.
You will notice another line of GL code in the body of renderFunc()– specifically, the call glDisable(GL LIGHTING). This tells OpenGL that we don’t want it to make dynamic lighting computations when it draws our geometry on the screen. Generally, lighting only makes sense in a 3D environment; for our 2D programs we will leave it disabled.
Once we have set an orthographic projection and disabled lighting, we are ready to draw geometry. The general method for drawing in OpenGL is as follows:
sions as the pixel dimensions of the window. The origin will be in the upper left-hand corner of the window, and the y-dimension will grow downwards. Thus, drawing a point at coordinates (100.0, 100.0) will generate a point 100 pixels below and 100 pixels to the right of the window’s upper-left corner.