Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

FreJa

texture problem...

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

Hi, I''m trying to load some Tga textures, and apply them to 3d objects, but when I do it the texture doesn''t appear, instead of that my 3d object gets a funny skin... like with rainbow colors...!! Any suggestions? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Sounds like your TGA loader is not reading in correctly. Start there.

Share this post


Link to post
Share on other sites
quote:
Original post by FreJa
This just happens with some tga textures...


what do these broken tgas have in common?
are they non-n²? 32bit RLE compressed? the ones that arent working have something in common. find out what it is, then let us know.

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites
I had this problem awhile ago, and it ended up being a 24-bit vs. 32-bit problem. When you read the header of the TGA, check the number of bytes per pixel. If you have 3 bytes per pixel, use GL_RGB when you call glTexImage2D (or whatever you''re using), or GL_RGBA is you have 4 bytes per pixel. It was a problem that stumped me for a little while. Hopefully that''s your problem.

Share this post


Link to post
Share on other sites
Based on how you load the TGA right now, it can be as easy as loading the 24-bit TGA. If you just read in the raw data, decompress it if you need to, and send it along to OpenGL, then the difference between 24-bit and 32-bit is just in the flag you pass to glTexImage2D(). For example:

int textureType = GL_RGB;
if(tga.bytesPerPixel == 4)
textureType = GL_RGBA;

Four bytes per pixel is 32-bit, three is 24-bit. You shouldn''t have to change how you actually load in the raw data, assuming you correctly calculate the size of the raw image data to be read using the number of bytes per pixel:

int imageSize = tgawidth * tgaheight * bytesperpixel;
/* Then just read that many bytes from the file */


Share this post


Link to post
Share on other sites
I think thats what I already do:


colorMode = tgaHeader->bitCount / 8;
imageSize = tgaHeader->imageWidth * tgaHeader->imageHeight * colorMode;

imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);


fread(imageData, sizeof(unsigned char), imageSize, filePtr);

for (imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode)
{
colorSwap = imageData[imageIdx];
imageData[imageIdx] = imageData[imageIdx+2];
imageData[imageIdx + 2] = colorSwap;
}



??

Share this post


Link to post
Share on other sites
quote:
Original post by FreJa
I think thats what I already do:


colorMode = tgaHeader->bitCount / 8;
imageSize = tgaHeader->imageWidth * tgaHeader->imageHeight * colorMode;

imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);


fread(imageData, sizeof(unsigned char), imageSize, filePtr);

for (imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode)
{
colorSwap = imageData[imageIdx];
imageData[imageIdx] = imageData[imageIdx+2];
imageData[imageIdx + 2] = colorSwap;
}



??



Then if your ColorMode == 4 you should pass GL_RGBA to glTexImage2D. If your ColorMode == 3 pass GL_RGB to glTexImage2D.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!