CSC418/2504 Fall 2000: Assignment 3 FAQ

General Answers

  1. Where can I get more OpenGL documentation?

  2. Where can I get more GLUT documentation?

  3. How can I have multiple windows with OpenGL?

    To create a new window, use the

    function. Before calling it, you need to call functions, which specify the size and position of the new window.

    glutCreateWindow returns the ID of the new window just created. This ID gets used in several places:

    1. when the GLUT library calls your "display" or "resize" functions (which you registered using the calls), it is telling you that a window needs to re-drawn, or that the user has re-sized a window.
    2. Which window is GLUT talking about? You can ask GLUT, by calling which returns the ID of the window in question.

  4. How do I draw Text?

    The simplest way is to send text to standard output, which is what happens when you call printf in C or cout in C++.

    You can, however, write text to OpenGL windows. Use the

    function. It draws a single character at the current position, and then advances the position in preparation of the next character. The GLUI program example2.cpp has some code to draw a character string:
      glDisable( GL_LIGHTING );  /* Disable lighting while we render text */
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      gluOrtho2D( 0.0, 100.0, 0.0, 100.0  );  /* Change this to fit your window */
      glMatrixMode( GL_MODELVIEW );
      glLoadIdentity();
      glColor3ub( 0, 0, 0 );       /* Black text */
      glRasterPos2i( 10, 10 );     /* Text start position */
    
      for( int i=0; i<(int)strlen( text ); i++ )
        glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, text[i] );
          
    Note that you will probably not want any 3D transformations to take place when you are drawing the text.


Answers Specific to an Assignment Question

  1. Question #1: How can I get G1 continuity?

    In this case, you can't. The question is incomplete. Ignore parts b, d and f.

  2. Project #3: How do I "Snap to a Grid"?

    Given the mouse's current (x y) position, calculate the nearest grid point (convert your x,y to grid coordinates, round, and convert back), and adjust the shape of whatever you are dragging to that new point.

  3. Project #3: How can I adjust angles if I'm snapping to a grid?

    You could allow angles to only have "nice" values (eg, 10, 30, 45 degrees, etc), and rotate the object only if the mouse point is near such an angle.

  4. Project #6: How can I interpolate values using cubic curves?

    I suggest you use Cardinal splines. They are described in the text, and I will talk about them in class. The basic idea is this:

    You are given a set of points P0, P1, P2, P3, ... and you need a curve that passes through them, but is "smooth". Add extra control points (I'll tell you how), between the original points: P0, Q1, P1, R1, Q2, P2, R2, Q3, P3, R3, ... and then draw a series of Bezier cubics, with the following control points:

    1. P0, Q1, P1 (this is a Bezier quadratic, actually)
    2. P1, R1, Q2, P2
    3. P2, R2, Q3, P3
    4. P3, R3, Q4, P4
    and so on.

    How do you get these extra control points? For each original control point, look at the control point just before and the one just after. Subtract them, to get a direction vector, which you use to place your new control points. Thus:

    depending on the value of α you'll get different amounts of "sharpness" at each original point. A good value of α is around 0.25.

  5. Project #6: Where can I find sample animations?

    Sample animations from previous years are available at:


Alejo Hausner, Dept of Computer Science, University of Toronto
Last modified: Sun Dec 3 22:22:37 EST 2000