View Full Version : zooming
VenomSpawn
04-22-2006, 04:27 PM
Hi,
I want to zoom using gluPerspective but inside of a case block. I currently cant do it because it says that w and h are not defined... is there a way i can use it, or another method? it is used to initialize in my display method and works fine. Thanks for the help.
Reedbeta
04-22-2006, 05:36 PM
Sounds like a syntax bug. Why don't you post the code you are trying to use?
VenomSpawn
04-22-2006, 05:42 PM
void reshape (int w, int h){
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(450.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0,0.0);
}
void keyboard (unsigned char key, int x, int y){
switch (key) {
case 'a':
gluPerspective(450.0*2, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
break;
case 'A':
break;
case 27:
break;
default:
break;
}
}
Doesnt seem like a syntax error. Its just that the variables arent defined in my void keyboard, but they are in the resize.
Reedbeta
04-22-2006, 06:11 PM
Okay, in future use the [ code ] [ /code ] tags to keep the syntax formatting there. And, obviously, if the variables are defined in one function you're not going to be able to use them in another! The variables only exist inside the scope where they're defined, in this case, the scope of a particular function.
Apocalypse
04-24-2006, 03:42 AM
Use global variables!
static int _width;
static int _height;
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(450.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0,0.0);
_width = w;
_height = h;
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'a':
gluPerspective(450.0*2, (GLfloat) _width/(GLfloat)_height, 1.0, 20.0);
break;
case 'A':
case 27:
default:
break;
}
}
Wernaeh
04-24-2006, 06:20 AM
By the way, what are the x and y parameters supposed to be ? Seems like these should be w and h instead. Or, use an additional set of parameters (dependant on how "general" your keyboard call should be).
Cheers,
- Wernaeh
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.