PDA

View Full Version : image display problem



satya
11-30-2005, 08:15 PM
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_widt h);

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

Gavin
12-02-2005, 08:53 AM
x = centre_of_screen_x - (image_width/2)
y = centre_of_screen_y - (image_height/2)