Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: GL_COLOR_MATERIAL problems

  1. #1
    Intern Newbie
    Join Date
    Jul 2004
    Posts
    40

    GL_COLOR_MATERIAL problems

    I'm trying to render a lightened scene with textured and colored polygons. Rendering textured polygons works well, but colored polygons are all white. So I tryed to use GL_COLOR_MATERIAL to render my colored polygons. My render loop is like that:

    {
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_COLOR_MATERIAL);
    DrawTexturedObjects();

    glDisable(GL_TEXTURE_2D);
    glEnable(GL_COLOR_MATERIAL);
    DrawColoredObjects();
    }

    The problem is, glDisable(GL_COLOR_MATERIAL) doesn't work! The first frame is rendered correctly, but once GL_COLOR_MATERIAL has been enabled, I can't disable it, so the next frames are incorrect (textured objects are no longer lit because GL_COLOR_MATERIAL is enabled).

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: GL_COLOR_MATERIAL problems

    Hi !

    If you try to use glColor to change the color of a polygon that will not work unless you disable lighting first (glDiable( GL_LIGHTING))

    Could that be the reason for the white polygons.

    glDisable( GL_COLOR_MATERIAL) only disables the tracking, the last used glColor will still be active for the last changed material, so you would need to reset this with a last glColor before disable GL_COLOR_MATERIAL, or better reset the material before you start rendering.

    Mikael

  3. #3
    Intern Newbie
    Join Date
    Jul 2004
    Posts
    40

    Re: GL_COLOR_MATERIAL problems

    Thanks fot answering.

    I use GL_COLOR_MATERIAL so my colored polygons are not white. The problem is that GL_COLOR_MATERIAL cancel the light effect on my textured polygons(probably because I didn't set any material property on those). Ans disabling GL_COLOR_MATERIAL doesn't change anything.

    As for reseting the color to white, it makes my textured polygons have the right colors, but I still have no lighting on them.

    Hope you understanf what I mean. Maybe I should just use material for everything, but then it would be slower I think.

  4. #4
    Intern Newbie
    Join Date
    Jul 2004
    Posts
    40

    Re: GL_COLOR_MATERIAL problems

    Well I just solved my problem, which was an ambient light acting strangely.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2005
    Location
    MA
    Posts
    1

    Re: GL_COLOR_MATERIAL problems

    I'm having the same problem with lighting on a textured polygon. I've created a texture map and have generated colors according to a contour color scheme I want. I've set up the texture, material and lighting properties then display it like this:
    Code :
    //needed here for blended shading model at each redraw
    	glShadeModel(GL_SMOOTH);
     
    	if(texture){
    		//uses predefined texture from setParams()
    		glBindTexture(GL_TEXTURE_2D, textures[1]);
    		//turns on texturing
    		glEnable(GL_TEXTURE_2D);
    	}
     
    	glEnable(GL_COLOR_MATERIAL);
     
    	//select the current color according to color scheme
    	if (colorScheme == DARK) glColor3f(0.25f,0.25f,0.25f);
    	if (colorScheme == LIGHT) glColor3f(0.8f,0.8f,0.8f);
    	if (colorScheme == MIDDLE) glColor3f(0.4f,0.4f,0.4f);
     
    	//draw "terrain" object then put texture on it
    	start = FSIZE/8;
    	end   = FSIZE*7/8;
    	cent  = float(FSIZE)/2.0f;
     
    	glPushMatrix();	
    	glTranslatef(-cent,-cent,-10.5);
     
    	for(i=start;i<end;++i){
    		glBegin(GL_QUAD_STRIP);
    		for(j=start;j<end;++j){
    			//set the normals for the surface rendered
    			glNormal3f(normsX[i][j],normsY[i][j],normsZ[i][j]);
    			//sets the current texture coordinates
    			glTexCoord2f(field[i][j]*b + a, field[i][j]*b + a);
    			//vertex to be rendered
    			glVertex3f(float(i),float(j),field[i][j]);
    			//repeat
    			glNormal3f(normsX[i+1][j],normsY[i+1][j],normsZ[i+1][j]);
    			glTexCoord2f(field[i+1][j]*b + a, field[i+1][j]*b + a);
    			glVertex3f(float(i+1),float(j),field[i+1][j]);
    		}
    		glEnd();
    	}
     
    	glDisable(GL_TEXTURE_2D);
    This all works fine! My problem is that when I try to change the RGB values for the texture so the glColor3f that I use can be
    Code :
    glColor3f(1.0f,1.0f,1.0f);
    I loose the specular highlighting. Can you, or anyone explain why? And how can I get the highlighting back if I want to keep the glColor3f values all 1.0?
    -I assumed that the glColor values would just be a percentage of the texture color values, which would mean there should be a way for me to set the numbers up so I wouldn't have to give a specific percentage value when calling glColor3f
    THANKS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •