Objectives

Lab Setup

Reshape

void changeSize(int w, int h)
{
}
int main(int argc, char* argv[])
{
  //...
  glutReshapeFunc(changeSize);

  setupRC();
 //...
}

Aspect Ratio

  glViewport(0, 0, w, h);

  glMatrixMode( GL_PROJECTION);
  glLoadIdentity();

  float aspectRatio =  (float) w / (float)h;
  if (w <= h)
    gluOrtho2D(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio);
  else
    gluOrtho2D(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0);
void setupRC(void)
{
  glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  glOrtho(-100.0, 100.0, -100, 100.0, 1.0, -1.0);
}

Exercises

1.Debug Output

Experiment with outputting text from the changeSize() method:

  cout << "width:" << w << " :height:" << h << endl;

These are C++ iostream calls, so will require the iostream to be included, and the std namespace to be set:

#include <iostream>
using namespace std;

Output also the actual Ortho Projection co-ordinates.

2.Viewport

3. Menus

Glut has a menu subsystem

See if you can pop up a menu, and use it to toggle some of the features introduced in 1 or 2 above