Jump to content
  • Advertisement
Sign in to follow this  
Orx

Strange devIL difficulties

This topic is 4559 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 attempting to use devIL to load an image in the constructor of the class that uses it, using what's basically the same code to load an image used in lesson 6's devIL/openIL version. When the code is run, ImgId has a value of 2, which appears to be a completely valid image name. However, when ilutGLBindTexImage() is called, two 1281 IL_INVALID_ENUM errors are pushed onto the error stack, and the result returned by ilutGLBindTexImage() is zero, which calls ilDefaultImage(). Has anyone encountered this sort of error before? What am I doing incorrectly such that the bound image causes ilutGLBindTexImage() to produce erroneous results? The problematic code is as follows:

Sprite::Sprite( char *filename )
{	
	ILuint ImgId;									
	ilGenImages(1, &ImgId);								
	ilBindImage(ImgId);									
	if ( ! ilLoadImage(filename) )  					
	{	
		ilDeleteImages(1, &ImgId);						
		cerr << " Error loading texture: " 				
			 << filename << endl;
	}

	m_Texture = ilutGLBindTexImage(); 

	ILenum Error;
	while ((Error = ilGetError()) != IL_NO_ERROR) 
	{
		printf("%d: %s/n", Error, iluErrorString(Error));
	} 

   	ilDeleteImages(1, &ImgId);
	
}


m_Texture is the member of the Sprite object that's used in such as glBindTexture( GL_TEXTURE_2D, m_Texture ).

Share this post


Link to post
Share on other sites
Advertisement
try adding "ilutRenderer(ILUT_OPENGL);" at the beginning.

from the devIL tutorials: http://openil.sourceforge.net/tuts/tut_10/index.htm
Quote:

Before you call any ilut functions dealing with OpenGL and after you have initialized OpenGL, you *must* call ilutRenderer with the ILUT_OPENGL parameter.

Required line to initialize DevIL's OpenGL access.

Share this post


Link to post
Share on other sites
I have ilutRenderer(ILUT_OPENGL) as one of the first things I do in main. It looks like this:


int main(int argc, char* argv[])
{
// initialize texture handler DevIL
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
ilutInit();

// everything else

return 0;
}




Should I be calling ilutRenderer(ILUT_OPENGL) prior to each image load procedure?

Share this post


Link to post
Share on other sites
I've switched the lines, but that did not fix the error. If there's an example of loading an image properly within a constructor, with the result saved as a class member, that would be helpful.

Share this post


Link to post
Share on other sites
I don't recall the exact name, but i believe a function along the lines of "ilutGLLoadImage(const char*)" exists, that wraps it all up for you and returns an OpenGL texture id - if you have no need to modify the image itself, then this function should suit you well.

Share this post


Link to post
Share on other sites
I converted my code over to using ilutGLLoadImage, but it still returns 0, while also adding those invalid enum errors to the stack. From looking at what seems to be the code for ilutGLLoadImage from at Koders.com, it seems that the enum errors are caused by boolean checks in the deviIL code, since there are no enum values that are taken by ilutGLLoadImage. What would be necessary at this point? Apparently devIL in its 1.6.7 incarnation does work, so why would one devIL function pass an invalid enum value to another? In case anyone's wondering, the file call looks similar to "xxx.tga", and the file is in the correct directory...

Share this post


Link to post
Share on other sites
I'm using VS .Net. I would have figured gcc would have led to less problems than VS, though.

Share this post


Link to post
Share on other sites
Here is how I used it in some demo code I wrote.


ILuint ImgId;
ilutRenderer( ILUT_OPENGL );
ilGenImages(1, &ImgId);
ilBindImage(ImgId);
// Load the map file and Check for Errors
if (!ilLoadImage(mapPath))
{ // If Could Not Load, Delete Image
ilDeleteImages(1, &ImgId);
}
else
{
ILenum Error;
Error = ilGetError();
// Attach the map image to the material
materials[materialCount].texture = ilutGLBindTexImage();
// Delete the Image since the material has a Copy
ilDeleteImages(1, &ImgId);
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!