Hi,
I am completely new to OpenGL programming, seeing some code on the net I just managed to
read and display some pixmaps. But the problem is the image is not exactly centered in the view port. Can you guys help me in that.
I have this following code
glGetIntegerv(GL_VIEWPORT, view_port);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho((GLdouble)0, (GLdouble)image_width, (GLdouble)0,
(GLdouble)image_ht, (GLdouble)-1.0, (GLdouble)1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
zx = (double)(view_port[2] - view_port[0]) / (double)image_width;
zy = (double)(view_port[3] - view_port[1]) / (double)image_ht;
if( zx > zy )
zx = zy ;
glPixelStorei(GL_UNPACK_ROW_LENGTH,(int)image_width);
vieport_width = (view_port[2] - view_port[0]);
raster_pos_x = vieport_width - image_width;
if(raster_pos_x < 0)
raster_pos_x = 0;
else
raster_pos_x /= 2;
glPixelZoom((GLfloat)zx,(GLfloat)zy);
glRasterPos2i((GLint)raster_pos_x, (GLint)0);
rgba = GetTheImageInfo();
if( rgba )
{
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
glDisable(GL_BLEND);
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
TIA
Satya