🔒 Locked
SOIL_load_image and mipmaps
Advertisement
Original Post
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 );
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...
Thanks!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement