PDA

View Full Version : Two image in one image texture



azrael11
01-11-2010, 04:28 PM
I have two pictures
one standard 512x512 for a cube texture filled in black nothing else
the other is 456x340
How can i merge this and make it one and get this ...
I want to get a 512x512 image with the 456x340 image in the middle of the 512X512 so i can load in memory with bindtexture and use it in my cube

chronozphere
01-11-2010, 06:31 PM
So you want each side of the cube to show exactly the same image?

In that case it would be easy. Just merge the pictures in your favorite image editing program. If the background 512x512 image is only black, you could enlarge the other image to 512x512 and make all the empty sides black. :)

azrael11
01-11-2010, 07:52 PM
So you want each side of the cube to show exactly the same image?

In that case it would be easy. Just merge the pictures in your favorite image editing program. If the background 512x512 image is only black, you could enlarge the other image to 512x512 and make all the empty sides black. :)

Hell i am not good in english...
All this i want to make it on the fly...
I want to show different images in a cube,but the best respective image for a cube is the 8^ like 512x512 or 1024x1024 and the other images differents this size like 430x350 or 515x800..
so the goal is to read the size of the image use the black mask and put the diff image in the middle merge on the fly and create a texture for the cube so the image shows not scaled or streched

Thanks for the help... sorry for my bad english...

User137
01-11-2010, 10:05 PM
OpenGL uses power of 2 texture sizes so you need to load image so that it fits in it. If your image is size 800x400 you would need to draw it on a 1024x512 texture and load that in. However you don't have to stretch it when drawing.

Normal full size texture coordinates go from point (0,0) to (1,1).

If you have a image that's size is 430x350, loaded in 512x512 texture without scaling, then texture coordinates for the Quad are:
(0,0) to (430/512, 350/512) -> Therefore you can forget everything about black masks and merging stuff...

Another thing is, if you have to fill something with solid color then disable textures when doing so. Especially if its as big as 512x512 fully black image is big waste of graphics power.

Or is the question about how you should build the texture data? In that case you need to tell if you use SDL or other libs to load images, Delphi or fpc/Lazarus?

grudzio
02-11-2010, 07:59 PM
You can also use glTexSubImage2D (http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml) to copy your 456x340 image onto 512x512 texture. Do something like this during your OpenGL initialization


//bind 512x512 texture
glBindTexture(GL_TEXTURE_2D,texId);
//copy 430x350 image onto texture
// x offset = (512 - 430) div 2
// y offset = (512 - 350) div 2
// asuming rgba texture format
glTexSubImage2D(GLTEXTURE_2D, 41, 81, 430, 350, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

and then draw your cube with this modified texture.