Activity 1

Modified

Basic OpenGL

Rearrange the following as a working OpenGL program.

  1. int main(int argc, char** argv)
  2. #include <GL/glut.h>
  3. glutDisplayFunc(mydisplay);
  4. glEnd();
  5. void mydisplay()
  6. glColor3f(1.0,1.0,1.0);
  7. glVertex3f(0.5,0.5,-3.0);
  8. glClear(GL_COLOR_BUFFER_BIT);
  9. glBegin(GL_LINES);
  10. glFlush();
  11. glutMainLoop();
  12. glutCreateWindow("simple");
  13. glVertex3f(-0.5,-0.5,-1.0);

Is the line visible now?

Enter in Visual Studio and test.

Viewing volume

Where should the following be added to change the viewing volume?

glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);

Is the line visible now?

Enter in Visual Studio and test.

Mouse events

Change the program to place dots whenever the right mouse button is clicked (see page 117).

State of program

What changes are necessary to connect the dots with lines.

Make the changes and test.