Tom Kelliher, CS 320
Mar. 27, 2000
Project 1 due in one week. Written final?
Midterm on 4/10.
Read 3.1--3.5.
Classes, maze class.
Interactive graphics.
2-D viewing:
What is clipping?
The orthographic projection:
Suppose we have two objects, each at and
.
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); void glOrtho2d(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);``Multiply the current matrix with an orthographic matrix'' --- make the projection matrix the current matrix.
OpenGL matrices:
Translation, rotation, scaling.
Orthographic, perspective.
Several we've already seen:
glutInit(int *argcp, char *argv[])
glutCreateWindow(char *title)
glutInitDisplayMode(unsigned int mode)
Example:
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);Mode bit examples:
GLUT_RGBA
, GLUT_RGB
, GLUT_INDEX
.
GLUT_SINGLE
, GLUT_DOUBLE
.
GLUT_DEPTH
.
The aspect ratio's of the clipping rectangle and viewing window should match. Otherwise, distortion results.
void glViewport(GLint x, GLint y, GLsizei w, GLsizei h);where
Example. Assume you have a viewing window:
glViewport(100, 100, 50, 50)This sets the viewport to the upper righthand quarter of the viewing window.
glutInitWindowSize(gww, gwh);But, the user can resize the window at will.
#define WINDOW_WIDTH 200 #define WINDOW_HEIGHT 200 void reshape(int, int); int maintainAspectRatio = 1; int gww = WINDOW_WIDTH; int gwh = WINDOW_HEIGHT; int main() { /* ... */ glutInitWindowSize(gww, gwh); glutReshapeFunc(reshape); /* ... */ } void reshape(int w, int h) { if (maintainAspectRatio) gww = gwh = (w < h) ? w : h; /* aspect ratio = 1 */ else { gww = w; gwh = h; } }
Points to note:
Note the overlap and observe the result.
The user could easily write a small function to position and render strings.