• Advertisement
Sign in to follow this  

DevIL Problems (getting image width/heigth)

This topic is 4517 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've managed to get the image to load (forgot to create a texture for OGL), but now I can't get the image width and height. The program just crashes.
/////////////////////////////////////////////////
void TextQuad::load_image( std::string filename )
/////////////////////////////////////////////////
{
         //The image that's going to be used
    	ILuint ImgId;

    	//Generate texture
    	glGenTextures( 1, &texture );
        
	//Generate DevIL image
	ilGenImages( 1, &ImgId );
    
	//Use the image
	ilBindImage( ImgId );
	
	//If the image loaded fine
	if( ilLoadImage( (ILstring)filename.c_str() ) )
        {
            //Get image dimensions (Crash happens here)
            w = ilGetInteger( IL_IMAGE_WIDTH ); 
            h = ilGetInteger( IL_IMAGE_HEIGHT ); 
        
            //Send it to OpenGL
	    texture = ilutGLBindTexImage();
	}
	
	//Delete DevIL's copy of the image
	ilDeleteImages( 1, &ImgId );
}


and here's the initialization function just in case that I forgot to initialize something:
///////////
bool init()
///////////
{
    //Initialize SDL
    if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
    {
        return false;    
    }
    
    //Create Window
    if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
    {
        return false;
    }
    
    //Set Attributes
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	
	//Start up DevIL
	ilInit();
    iluInit();
    ilutRenderer( ILUT_OPENGL );
    ilutInit();
	
    //Enable Texture mapping
    glEnable( GL_TEXTURE_2D );
    
    //Set clear color
    glClearColor( 0, 0, 0, 0 );
    
    //Set projection
    glMatrixMode( GL_PROJECTION );
    glPushMatrix();
    glLoadIdentity();
    glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 );
    
    //Set model matrix
    glMatrixMode( GL_MODELVIEW );
    glPushMatrix();
    glLoadIdentity();
    
    //Set caption
    SDL_WM_SetCaption( "OpenGL Test", NULL );
    
    return true;    
}

So what's going on here? [Edited by - Lazy Foo on October 10, 2005 2:53:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement