Jump to content


zooming


5 replies to this topic

#1 VenomSpawn

    New Member

  • Members
  • Pip
  • 2 posts

Posted 22 April 2006 - 11: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.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 23 April 2006 - 12:36 AM

Sounds like a syntax bug. Why don't you post the code you are trying to use?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 VenomSpawn

    New Member

  • Members
  • Pip
  • 2 posts

Posted 23 April 2006 - 12:42 AM

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.

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 23 April 2006 - 01:11 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Apocalypse

    New Member

  • Members
  • PipPip
  • 24 posts

Posted 24 April 2006 - 10: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;
  }
}

Apocalypse, the End of the World.

#6 Wernaeh

    Senior Member

  • Members
  • PipPipPipPip
  • 368 posts

Posted 24 April 2006 - 01:20 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users