Jump to content
  • Advertisement
Sign in to follow this  
stella1016

OpenGL texture mapping

This topic is 3692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Daaark
Did you call glEnable(GL_TEXTURE_2D), and glBindTexture(...)?


Yes, I did glEnable(GL_TEXTURE_2D), but not glBindTexture(...). I only have one texture. So I don't need to bind, right?

Share this post


Link to post
Share on other sites
And in initializeGL(), I did this:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, maxTextureWidth, maxTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

Then later I only substitute part of the texture.

Share this post


Link to post
Share on other sites
Sorry I didn't mension that, it works well for images which are smaller than my maxTexture size. Only the images bigger than maxTexture size have problem.

OH, I found my problem, the Texture is smaller than my image, I need to new another texture.

:)

Share this post


Link to post
Share on other sites
OK. I have a question, how to scale the image to the size which I want it to be? Then I don't have to new another texture, since I have a fixed size texture already. Is there any function supporting this?

what I have are: input size, output size, image data

Share this post


Link to post
Share on other sites
Assuming the resizing is just for display purposes, just draw a bigger quad. OpenGL will do the rest for you.

BTW, did you notice that in your PaintGL() function there are only 2 glVertex2f() calls? For a quad you need 4, so no quad would be rendered. ;)

Edit: OK, just overlooked them. They were hidden due to missing line breaks. :(

Edit2: It could also be a matter of winding. Is backface culling disabled?

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
Assuming the resizing is just for display purposes, just draw a bigger quad. OpenGL will do the rest for you.

BTW, did you notice that in your PaintGL() function there are only 2 glVertex2f() calls? For a quad you need 4, so no quad would be rendered. ;)

Edit: OK, just overlooked them. They were hidden due to missing line breaks. :(


The main problem is that here I only have one texture init. Because I need also display webcam output, in order to make it efficient I used glTexSubImage2D(). Here it looks like I need to create another texture to display...I have to, right?

The best way should be using the present texture, but no way...

For the quad, do you mean draw a quad, and change the viewport or something?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!