Prof Avery's weblog
the catsup bottle in your wine rack


CSU Fullerton Perl Powered Python vi Hacker

Geek News

del.icio.us bookmarks


Wed, Feb 16, 2005

Big Crypto News
From Bruce Schneier's weblog: SHA-1 has been broken. Two weeks from now we'll be talking about hash functions. By that time it may be confirmed, and we'll talk about the implications.

/var/spool/courses/csuf/2005/spring/cpsc433/misc #

The Reshape Callback
Ok, so I had to go back and re-read the documentation to get this working.

The default reshape callback (the one you get if you don't call glutReshapeFunc()) calls glViewport(0, 0, w, h) and doesn't change the coordinate system. The default coordinate system (which won't change unless you call gluOrtho2D()) has its origin in the lower left corner of the window.

Unfortunately, the coordinate system used for the mouse position has its origin in the upper left corner. That means that if you don't have a reshape callback, or if you call gluOrtho2d(0, w, 0, h);, you'll end up with mouse coordinates that are the opposite of drawing coordinates. To fix that, you need to do one of two things:

  1. Subtract the mouse y-coordinate from the height of the window
  2. Change your drawing coordinate system to match the mouse coordinate system
Luckily, option (2) also allows us to resize the window without stretching the drawing or moving it all over the screen. Use the following reshape callback:
void reshape(int w, int h)
	glViewport(0, 0, w, h); 

	gluOrtho2D(0, w, h, 0);
Don't forget to register the callback in main() with glutReshapeFunc(reshape).

Here's what the function does:

glViewport(0, 0, w, h);
Specifies that the viewport rectangle should occupy the entire window. The default reshape callback does the same thing.
We're about to specify 2D Orthographic projection. The default matrix mode is GL_MODELVIEW, so we need to switch.
Clear any existing projection matrix
gluOrtho2D(0, w, h, 0);
Specify the left, right, bottom, and top clipping planes. Note that the bottom clipping plane is h, not 0.

/var/spool/courses/csuf/2005/spring/cpsc465 #



January 2018
Sun Mon Tue Wed Thu Fri Sat