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:
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 programexample2.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.
In this case, you can't. The question is incomplete. Ignore parts b, d and f.
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.
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.
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:
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:
Sample animations from previous years are available at: