Previous Lesson C++ OpenGL Video Tutorials Main Next Lesson



Lesson 1: A Simple OpenGL Project

If you cannot see the video below, please install the Adobe Flash Player.
 





A Simple OpenGL Project




This lesson begins our OpenGL video tutorial series. In this lesson, we create a basic OpenGL project to show how to set up the GLUT library files for development. At this point, we are skipping over the programming to focus getting the environment set up for programming OpenGL projects. Detailed are shown in the video. Here, we give a text description of the set-up process:

 

  1. Begin by creating a console project, like the one we created in C++ Console Lesson 1. However, we call the project "OpenGLLesson1," instead of "HelloWorld."
  2. After adding main.cpp to the project, copy the code segment below to the file instead of our "HelloWorld" program.


  3. #include <glut.h>
    
    void DrawLine() {
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0, 1.0, 1.0);
        glBegin(GL_LINES);
        glVertex3f(0.25, 0.25, 0.0);
        glVertex3f(0.75, 0.75, 0.0);
        glEnd();
        glFlush();
    }
    
    void Initialize() {
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    }
    
    int main(int iArgc, char** cppArgv) {
        glutInit(&iArgc, cppArgv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(250, 250);
        glutInitWindowPosition(200, 200);
        glutCreateWindow("Draw Line");
        Initialize();
        glutDisplayFunc(DrawLine);
        glutMainLoop();
        return 0;
    }
    

  4. Left-click the link on Nate Robins' page and save the file to C:\temp. Create a folder there if you do not have one already.
  5. Open the folder C:\temp, Right-click the file glut-3.7.6-bin.zip and left-click Extract All... from the pop-up menu.
  6. This will pop up the extraction dialogue shown here. Left-click the box next to Show extracted files when complete to uncheck it. Then, left-click the Extract button.
  7. Open the folder C:\temp\glut-3.7.6-bin\glut-3.7.6-bin and drag the file glut.h to the folder C:\Program Files\Microsoft Visual Studio 9.0\VC\include.
  8. Drag the file glut32.dll from C:\temp\glut-3.7.6-bin\glut-3.7.6-bin to C:\Windows\System32.
  9. Drag the file glut32.lib from C:\temp\glut-3.7.6-bin\glut-3.7.6-bin to C:\Program Files\Microsoft Visual Studio 9.0\VC\lib.
  10. Finally, left-click Debug in the menubar and left-click Start without Debugging in the submenu. When the program is finishes compiling and executes, you should see a window with a line drawn in it.





Previous Lesson C++ OpenGL Video Tutorials Main Next Lesson


Home | Reference | Play Games! | Forum | Site Map | Contact Us