Compressed textures and gluBuild2DMipMaps()
I''m trying to compress my textures. I use gluBuild2DMipMaps() to generate my mipmaps, and as I far as I can tell, you can''t use GL_COMPRESSED_RGB with gluBuild2DMipMaps(). At least, that''s what the man page (and some fooling around) leads me to believe. Is there a way to automatically generate mipmaps with compression? This is my first attempt at texture compression, so I may be way off. Thanks for the help.
There''s an extension called SGIS_generate_mipmaps that you can use to automatically generate mipmaps.
I''ve tried googling for a helpful example, but can''t come up with anything that makes much sense to me. How do you actually use SGIS_generate_mipmaps?
Google returns this as the very first link when I search for the extension name. It''s the specification for the extension, and it describes everything about that extension.
Thanks for the response. I have read that several times now. Sometimes I need something a little easier to approach than the extension spec, and this may be one of those times. Perhaps when I said, "anything that makes much sense to me", I should have said "something with an example".
After a few more days of pondering, rereading the spec,and more googling, I think I may have the idea. I''m not at my machine at the moment, so I can''t try it though. I would do something like:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GENERATE_MIPMAP_SGIS, TRUE);
Then instead of gluBuildMipmaps(), I would just use glTexImage2D() and give the format as GL_COMPRESSED_RGB instead of GL_RGB. Is that right?
After a few more days of pondering, rereading the spec,and more googling, I think I may have the idea. I''m not at my machine at the moment, so I can''t try it though. I would do something like:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GENERATE_MIPMAP_SGIS, TRUE);
Then instead of gluBuildMipmaps(), I would just use glTexImage2D() and give the format as GL_COMPRESSED_RGB instead of GL_RGB. Is that right?
That looks correct.
Just remember to enable it before loading the texture data, as mipmaps are only generated when a change is made to the base level. Enabling it for an existing texture does not involve a change of the base level texture, and mipmaps will therefore not be generated.
And you might want to change the minification filter to a mipmap-filter to actually use you''re new mipmaps
Just remember to enable it before loading the texture data, as mipmaps are only generated when a change is made to the base level. Enabling it for an existing texture does not involve a change of the base level texture, and mipmaps will therefore not be generated.
And you might want to change the minification filter to a mipmap-filter to actually use you''re new mipmaps
Ok, so I'm actually trying this now and I seem to have the mipmap generation stuff working. Here's what I do:
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Generate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage->w, TextureImage->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
And that works fine. However, it quits working (textures disappear) if I use:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage->w, TextureImage->h, 0, GL_COMPRESSED_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
The same happens if I use GL_COMPRESSED_RGB_ARB. Again, I've never done texture compression before so it may be something really dumb. I have a few ideas about what I may need to do, so here they are: Do I need to change glTexImage2D() to glCompressedTexImage2D()? Do I need to tell it what kind of compression to use or something? Anyway, I hope someone can point me in the right direction. Oh, and thanks for all the help so far, Brother Bob. I appreciate it.
[edited by - Mr Grinch on October 16, 2003 1:08:35 AM]
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Generate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage->w, TextureImage->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
And that works fine. However, it quits working (textures disappear) if I use:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage->w, TextureImage->h, 0, GL_COMPRESSED_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
The same happens if I use GL_COMPRESSED_RGB_ARB. Again, I've never done texture compression before so it may be something really dumb. I have a few ideas about what I may need to do, so here they are: Do I need to change glTexImage2D() to glCompressedTexImage2D()? Do I need to tell it what kind of compression to use or something? Anyway, I hope someone can point me in the right direction. Oh, and thanks for all the help so far, Brother Bob. I appreciate it.
[edited by - Mr Grinch on October 16, 2003 1:08:35 AM]
quote:Original post by Mr Grinch
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
Mipmapping only makes sense for minification, not for magnification. Therefore, you cannot use a mipmap filter for magnification. GL_LINEAR and GL_NEAREST are the only two legal values.
quote:
However, it quits working (textures disappear) if I use:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage->w, TextureImage->h, 0, GL_COMPRESSED_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
You got GL_COMPRESSED_RGB in the wrong place. The last three parameters describes the source data you want to upload. You want the internal format to be compressed, so you need to put it in the third parameter, which tells OpenGL (or rather gives hints on) how to store it internally.
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB, TextureImage->w, TextureImage->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->pixels);
quote:
Do I need to change glTexImage2D() to glCompressedTexImage2D()? Do I need to tell it what kind of compression to use or something?
glCompressedTexImage is for uploading precompressed data. Then you need to specify exactly what compression method the data have been compressed with.
That''s embarassing. I had always thought of those reversed. I got that to work, so thanks for the help Brother Bob. I also went back to trying with gluBuild2DMipMaps() since I had tried GL_COMPRESSED_RGB in the wrong place there, too, and it seems to work fine. Is there a way to check whether my textures have actually been compressed or not?
To see if it's compressed or not, use glGetTexLevelParameter and GL_TEXTURE_COMPRESSED. For more information on on texture compresssion, look here.
[edited by - Brother Bob on October 18, 2003 7:42:42 PM]
[edited by - Brother Bob on October 18, 2003 7:42:42 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement