Skip to main content
GameDev.net gamedev.net
🔒 Locked

SOIL_load_image and mipmaps

Started by vladic2000x May 16, 2013 at 6:34 AM 1 replies 4.5k views
Original Post
vladic2000x
vladic2000x
Hello! Is there a way to get access to different mipmap levels using SOIL_load_image()?
The code below crashes the app:
int width, height, mipMapLeveCount;
unsigned char* imageDataPtr =SOIL_load_image( "texture/checker.dds", &width, &height, &mipMapLeveCount, SOIL_LOAD_RGB);
unsigned char* tempPtr=imageDataPtr;
for(int mipmapLevel = 0; mipmapLevel < mipMapLeveCount; mipmapLevel++)
{
glTexImage2D( GL_TEXTURE_2D, mipmapLevel, GL_RGB, width, height, 0, GL_RGB,GL_UNSIGNED_BYTE, imageDataPtr );
imageDataPtr+=width*height*3;
width/=2;
height/=2;
}
SOIL_free_image_data( tempPtr );
swiftcoder
swiftcoder

The third parameter isn't the number of mipmaps, it is the number of channels (which in your case will be 3, since you specify RGB).

The number of mipmaps should be roughly floor( log2( min(width, height) ) ).

Provided, of course, that your image has mipmaps, and SOIL is actually loading them. I haven't stared at the code in a while, but I seem to remember that one needed to use SOIL itself to do the upload to OpenGL, all in one shot, and specify the SOIL_FLAG_DDS_LOAD_DIRECT flag...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.