Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

OpenGL Texture compression for uncompressed image data

This topic is 4489 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 am not sure if I am setting up my compressed texture code correctly. I have uncompressed data and sending it to OpenGL. I would like to know if my code is correct...
glBindTexture(GL_TEXTURE_2D, texture[index]);

LoadTGAFile();

if(bpp == 32)
				{
	                imageTypeFormat = GL_RGBA;
		            imageTypeInternal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
				}
				else
				{
					imageTypeFormat = GL_RGB;
					imageTypeInternal = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
				}

if(useMipmaps)
			{
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode1);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
				gluBuild2DMipmaps(GL_TEXTURE_2D, imageTypeInternal, imageWidth, imageHeight, imageTypeFormat, GL_UNSIGNED_BYTE, imageData);
			}
			else
			{
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode1);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode1);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
				glTexImage2D(GL_TEXTURE_2D, 0, imageTypeInternal,  imageWidth, imageHeight, 0, imageTypeFormat,  GL_UNSIGNED_BYTE, imageData);
			}

Thanks

Share this post


Link to post
Share on other sites
Advertisement
Yes that's correct - but one thing you might want to do is pass a generic compressed format as internal format such as GL_COMPRESSED_RGB. GL will pick automatically the best compression mode available such as DXT1, DXT3 or DXT5.

Ofcourse if you have a preference for one of the aforementioned for quality and you have made sure that that specific format is supported by the card / driver then you should be fine with your code.

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!