Original Post
I have one window to display some images. I shoule be able to open any image files, and display it in the middle of the window (the window size if fixed.) I set allowed max image size as (maxTextureWidth, maxTextureHeight). And if opened image size is larger than this size, I will display a scaled version of this image. For reserving the size of ratio, I compute sth of the image and update the texture: { imageWidth = currentImageIpl->width; imageHeight = currentImageIpl->height; int channel = currentImageIpl->nChannels; textureDisplayRatio_x = (float)imageWidth / (float)maxTextureWidth; textureDisplayRatio_y = (float)imageHeight / (float)maxTextureHeight; if(textureDisplayRatio_x > 1.0 || textureDisplayRatio_y > 1.0) { if(textureDisplayRatio_x >= textureDisplayRatio_y) { imageWidth_display = maxTextureWidth; imageHeight_display = imageHeight / textureDisplayRatio_x; } else { imageWidth_display = imageWidth / textureDisplayRatio_y; imageHeight_display = maxTextureHeight; } textureDisplayRatio_x = (float)imageWidth_display / (float)maxTextureWidth; textureDisplayRatio_y = (float)imageHeight_display / (float)maxTextureHeight; } else { imageWidth_display = imageWidth; imageHeight_display = imageHeight; } imageData = currentImageIpl->imageData; if(channel == 3) glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, imageData); if(channel ==1) glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, imageWidth, imageHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, imageData); update = false; } I did it like this in PaintGL(): (I am using OpenGL with Qt) glLoadIdentity(); {... glTranslatef(GLfloat((maxTextureWidth - imageWidth_display) / 2),GLfloat((maxTextureHeight - imageHeight_display) / 2), 0); glBegin(GL_QUADS); glTexCoord2f(textureDisplayRatio_x, 0.0f); glVertex2f( imageWidth_display, imageHeight_display); glTexCoord2f(0.0f, 0.0f); glVertex2f(0, imageHeight_display); glTexCoord2f(0.0f, textureDisplayRatio_y); glVertex2f(0, 0); glTexCoord2f(textureDisplayRatio_x, textureDisplayRatio_y); glVertex2f( imageWidth_display, 0); glEnd(); ... } The problem is that the image is not displayed in window. What could be the problem? I checked all the computations are right. Thanks in advance.