Jump to content
  • Advertisement
Sign in to follow this  
FireNet

OpenGL OpenGL + DevIL problem

This topic is 4521 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 a very weird problem when I use DevIL to load an image. Once an image is loaded it messes up the colors of the primitives drawn.Change the color of the border of the image and the primitive's colors changes too. Link: http://www.freefileupload.net/file.php?file=files/030306/1141390114/rsfile.zip Change the color of the png image's border and see what happens. Any idea why it happens? The worst part is that the color changes even if I dont render the image at all :P. Here's the code I use to render it:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    
    glBegin(GL_QUADS);
    for(int i=0;i<200;i++)
    {
         glColor3f(1,1,1);
	 glVertex3f(rand()%200,rand()%200,1);
	    
    }
    glEnd();
	
    glColor3f(1,1,1);
    //ex_tile.Draw(0,200,200,0);
	
    glBegin(GL_LINE_LOOP);
	for(int i=0;i<200;i++)
        {
	    glColor3ub(255,255,255);
	    glVertex3f(400+rand()%200,400+rand()%200,1);
	    
	}
    glEnd();
	
    glColor3f(1,1,1);
    ex_tile.Draw(0,500,500,0);


Here's the bit related to DevIL
        // Initialize IL
	ilInit();
	
	// Initialize ILU
	iluInit();
	
	// Initialize ILUT with OpenGL support.
	ilutRenderer(ILUT_OPENGL);

        ILinfo Info;
        GLuint id;

        id = ilutGLLoadImage("data/dimg.png");
        iluGetImageInfo(&Info);

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The OpenGL initialisation code enables texturing.


But the problem here is that the colors of the primitives draw are influenced by the texture, even after I call glColor*().


I found a partial fix:


glPushAttrib(GL_TEXTURE_BIT)
id = ilutGLLoadImage("data/dimg.png");
glPopAttrib();



If no draw are called, the colors are fine;




glPushAttrib(GL_TEXTURE_BIT)
glColor3f(1,1,1);
ex_tile.Draw(0,500,500,0);
glPopAttrib();



With this, it works just fine.



Now what?
I dont want to call glPushAttrib(GL_TEXTURE_BIT) for every tile I draw.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Are you (or DevIL) enabling texturing anywhere and forgetting to disable it?
Like I hinted at in my other post (I should have made it more clear, sorry) you need to disable texturing. This is because OpenGL is a state machine; if you enable something, it is enabled until you disable it. If you have texturing enabled and want to draw something without textures, you have to disable texturing first.

My guess as to why wrapping DevIL's texture creation with push/pop attribute works even though you have texturing enabled previously is that before you call that you have the default texture bound (texture id 0). ilutGLLoadImage probably binds the texture it is creating which made it "not work" for you before. But now when you pop the GL_TEXTURE_BIT attribute OpenGL is reverting back to having the default texture bound. By default, having texture id 0 bound has the same end result as having texturing disabled.

It's safer to just make sure you enable texturing before you render anything that needs it and make sure it is disabled before rendering anything that doesn't need it.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!