How do I generate mipmaps using GL Image?

Started by
3 comments, last by Sean_Seanston 9 years, 9 months ago

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?

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.

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...

Your conclusion is correct.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Alright cool, that's great then.

Thanks.

This topic is closed to new replies.

Advertisement