CS 418 Lectures Assignments Exams Links

MP0: Simple OpenGL Demo

 

Goals

During the course of this semester, we will make extensive use of OpenGL -- a powerful cross-platform 3D graphics programming interface. It is used in a diverse range of applications, from CAD to games like Quake III. Since most of you have not used OpenGL before, we are providing you with this very simple demo to help you experiment with them. You may modify this demo, but you do NOT need to turn in your new code. After working with this demo, you will have learned:

  • How to compile and run a simple C++ progrom.
  • How to use rudimentary OpenGL commands to draw a simple 2-D figure.
  • How to take advantage of the libgfx support library which we are providing for you.

Before You Get Started

For all projects, we will be using the Linux workstations in 0216 Siebel.

In order to assist you in developing your projects, we are providing the ligfx support library to you. All the necessary pre-compiled libraries are installed on the CSIL machines. For the current assignment, you'll be using the GUI framework provided by this library. It's built on top of the FLTK cross-platform GUI toolkit.

All our demo/skeleton code will be written in C++. We assume that you already know C/C++. While we will not use any sophisticated C++ features, you should certainly understand the basics of control flow, method invocation, and class definition. Unfortunately, we simply do not have the time to provide any kind of substantial help in learning to program in C/C++, so it is your responsibility to learn (or refresh your knowledge of) the C++ skills necessary to complete this project.

Getting Started

  1. Download the MP0 demo project. This is a Zip file which contains the Linux Makefile, the source file, and a README. Once you have extracted the files, follow the instructions given in the README file.
  2. Read the demo code mp0.cxx. It is quite short, and we have tried to document it carefully. The comments in the code explain how the various parts of the program function. Compile and run the demo code.
If you have trouble with any part of this, please see an instructor or TA during their office hours. Alternatively, post a message on the course newsgroup (news.cs.uiuc.edu/class.cs418). We usually check the newsgroup regularly and will attempt to respond promptly to questions posted there.

Features

Here is a list of the basic features of this demo program:

  • It will initially draw a polygon with N sides of equal length in the center of the main window using basic OpenGL drawing commands.
  • When the user drags the mouse around the window, the polygon moves along with it.
  • When animation is enabled (from the View menu) the polygon animates in the following way: It begins with 3 equal sides; the number of sides increments one at a time to 12; It then decreases one at a time to 3. This process repeats until animation is disabled.

Tips and hints

  • Only certain OpenGL commands can occur between glBegin()/glEnd() pairs. This means that many functions (e.g., pixel_to_canvas()) will not work correctly in this context. Always call such functions before you call glBegin().