-2

I am rendering a scene with some map image in OpenGL and using lat, lon of the map as coordinates directly. So my scene does not start at 0,0 and goes up to width, height. Although I can see my polygon (very small), I can't zoom by changing the z-value of the eye in the gluLookAt().

/*
 * My boundary for map quad with texture
 */
#define TOP 41.9061
#define BOTTOM 41.8546
#define LEFT -87.7012
#define RIGHT -87.6054

/*
 *  window size
 */
const unsigned int window_width = 1024;
const unsigned int window_height = 739;

/*
 * drawing a polygon with texture
 */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mainMapTextureId);
glBegin( GL_POLYGON );   
//bottom left
glTexCoord2f( 0.0f, 1.0f );
glVertex3f(LEFT, BOTTOM, 0.0);

//bottom right
glTexCoord2f( 1.0f, 1.0f ); 
glVertex3f(RIGHT, BOTTOM, 0.0);

//top right
glTexCoord2f( 1.0f, 0.0f );
glVertex3f(RIGHT, TOP, 0.0);

//top left
glTexCoord2f( 0.0f, 0.0f ); 
glVertex3f(LEFT, TOP, 0.0);
glEnd();


/*
 * Setting up the camera
 */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)window_width/(GLfloat)window_height, 0.0, 10.0);
gluLookAt( (float)(LEFT+RIGHT)/2.0, (float)(TOP+BOTTOM)/2.0, 1.0, 
               (float)(LEFT+RIGHT)/2.0, (float)(TOP+BOTTOM)/2.0, 0.0,
        0.0f, 1.0f, 0.0f);
genpfault
  • 51,148
  • 11
  • 85
  • 139
musa
  • 11
  • 2

1 Answers1

2

It is not legal to have a value of 0.0 for the near plane of gluPerspective. Try replacing it with a nominal small value (0.1f).

Also always put a glGetError call in your code at the end, it will alert you to problems.

Tim
  • 35,413
  • 11
  • 95
  • 121