Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Multiple Images on One Texture

This topic is 4611 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

Hello, I would like to find a method to load several images (from the file system) and apply them to one texture. Currently, I am able to get my application to work by placing one image onto one texture. The problem with this lies in the fact that OpenGL textures are required to be a size of 2n. This can lead to a large waste of memory if I have an image size of 640*480 that requires a texture of 1028*1028. I have considered 2 methods: 1) Create the original image (bmp, jpg, png) with a size of 1028*1028 and placing as many images that I can fit onto it. The following code shows the whole image on the screen: glBegin(GL_TRIANGLE_STRIP); glTexCoord2f( texCoords[0], texCoords[1]); glVertex2i(0, 0); glTexCoord2f( texCoords[2], texCoords[1]); glVertex2i(width, 0); glTexCoord2f( texCoords[0], texCoords[3]); glVertex2i(0, height); glTexCoord2f( texCoords[2], texCoords[3]); glVertex2i(width, height); glEnd(); Once I have this, how then do I determine which image I would actually like to see on the texture? Say I want to see a rectangle of size 50*50 at the location 10, 10. How would I go about doing this? I have tried using glScissor, but with no avail. 2) Programmatically create a large texture with NULL image data and later place seperate image data onto the texture. glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //create the texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); ............. //later, pull out image data and replace a spot on the texture glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels ); This method seems to just produce a blank screen for me. Also, if I can get this method to work, then the viewing of an image from method #1 also comes in to play. Any light on this would be great. If there are any other known methods, I would be grateful to hear of them. Thanks, Dave

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!