Jump to content
  • Advertisement
Sign in to follow this  
Sean_Seanston

OpenGL How do I generate mipmaps using GL Image?

This topic is 1566 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'm following these tutorials here:http://www.mbsoftworks.sk/index.php?page=tutorials&series=1

Except that I've decided to use GLFW instead of GLUT, and use the Unoffical OpenGL SDK in general.

 

So I've got to the tutorial on textures:

http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=9

 

He uses something called FreeImage, but since I already have GL Image set up as part of the SDK, I thought I'd use that instead.

 

Loading a texture seems simple:http://glsdk.sourceforge.net/docs/html/group__module__glimg.html

 

I've used that code in my application and it all compiles fine, but I'm just wondering about one thing: the tutorial mentions generating mipmaps, but I'm not sure how that works with GL Image. I've searched for documentation and found this:

http://glsdk.sourceforge.net/docs/html/group__module__glimg__texture.html

Where it mentions that when CreateTexture() returns:

The texture returned will always be texture-complete, with the proper base and max mipmap level set, and reasonable filtering parameters set on it.

 

 

But there's no other mention of the word mipmap on that page and I haven't been able to find anything else regarding mipmaps and GL Image.

I'm quite unfamiliar with how mipmaps work in OpenGL though, so maybe it should be obvious to someone who knows about this.

 

GL Image seems to take care of the calls to glGenTextures(), glTexImage2D() etc. with the short bit of code I linked to, but does it have its own function to generate mipmaps somehow, or should I manually bind the texture to GL_TEXTURE_2D and then call glGenerateMipmap(GL_TEXTURE_2D);?

But then what about the reference to "the proper base and mipmap level" being set by CreateTexture()? Is that just something it does to allow proper mipmap generation later on by the usual glGenerateMipmap() method?

Share this post


Link to post
Share on other sites
Advertisement
From a cursory glance it seems like you can load DDS files into an image set and load that into a texture. DDS files support pre baked mipmap levels, that are stored alongside the full resolution image. By the looks of it, the createTexture method just reacts to the presence (or absence) of mipmap levels in the image set.

Share this post


Link to post
Share on other sites

I see...

 

Well one thing is that it mentions different loaders for DDS as for JPG, BMP, GIF etc.

 

glimg::loaders::dds being for DDS, and glimg::loaders::stb for the others.

 

Those are used to load the texture into the image set... so that's before CreateTexture() and the mipmapping that was mentioned... makes sense I guess that it would work like you say, considering the single mention of mipmapping with no further explanation.

 

So then presumably... using CreateTexture() with an ImageSet that was loaded using the stb loader would ignore mipmaps by default.

 

Do you think then it's most likely that the following code is how mipmapping is meant to be done with ordinary JPGs?:

//Declare texture ID
GLuint texture = 0;
//Load JPG into ImageSet
std::auto_ptr< glimg::ImageSet > imgSet( glimg::loaders::stb::LoadFromFile( argPath.c_str() ) );
//Create texture from ImageSet
texture = glimg::CreateTexture( imgSet.get(), 0 );

//If MipMaps are required
if( mipMaps )
{
//Bind texture to context
glBindTexture( GL_TEXTURE_2D, texture );
//Generate Mipmaps for texture
glGenerateMipmap( GL_TEXTURE_2D );
}

Is there any reason that might seem odd to someone who understands OpenGL textures, or like it wouldn't work as desired?

 

This then working off the assumption that I'm essentially doing the same thing as he's doing in the tutorial, because I'm assuming that CreateTexture() goes exactly as far as generating the texture, binding it to the context, and copying over the texture data, as well as probably unbinding it when it's done. At that rate, I assume it makes sense to bind the texture, call glGenerateMipmap() and continue as in the tutorial.

 

I'll see if it works once I have the rest of the tutorial working, just thought I'd see if I could get a clearer idea beforehand so I'm not stuck then...

Edited by Sean_Seanston

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!