PDA

View Full Version : Color Won't Change!!



11-11-2000, 07:18 PM
I made a square and a triangle and set the color to red two days ago. I used the same method to try to make it blue and no matter what color I try or how many times I try to clear the buffers or reset the color it will not do it.

void glutDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glutSetColor(1,0.0f,1.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f); // Top

glutSetColor(2,0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left

glutSetColor(3,0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS); // Draw A Quad

glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left

glColor3f(0.0,1.0f,0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right

glColor3f(0.0,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right

glColor3f(0.0,0.5f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd();
glFlush();
glutSwapBuffers();
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_INDEX | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(600,500);
glutInitWindowPosition(200,200);
glutCreateWindow("Shapes");
glutReshapeFunc(glutResize);
glutDisplayFunc(glutDisplay);
glutMainLoop();
return 0;
}

that's what I did. How do I chang colors????

DPalomo
11-12-2000, 02:30 AM
Try to use glColor3f(0.0f, 0.0f,1.0f);
instead of glutSetColor(). Maybe then you get
the wished result.

I hope this helps,

Daniel Palomo van Es

PS. The definition of glutSetColor is (from the GLUT specs)


glutSetColor sets the color of a colormap entry in the layer of use for the current window.

Usage

void glutSetColor(int cell,
GLfloat red, GLfloat green, GLfloat blue);

cell
Color cell index (starting at zero).
red
Red intensity (clamped between 0.0 and 1.0 inclusive).
green
Green intensity (clamped between 0.0 and 1.0 inclusive).
blue
Blue intensity (clamped between 0.0 and 1.0 inclusive).

Description

Sets the cell color index colormap entry of the current window's logical colormap for the layer in use with the color specified by red, green, and blue. The layer in use of the current window should be a color index window. cell should be zero or greater and less than the total number of colormap entries for the window. If the layer in use's colormap was copied by reference, a glutSetColor call will force the duplication of the colormap. Do not attempt to set the color of an overlay's transparent index.


[This message has been edited by DPalomo (edited 11-12-2000).]

11-12-2000, 06:28 AM
I was using glColor3f too and nothing happend. Thanks for hte suggestion, but are there any others.

Bob
11-13-2000, 01:30 AM
Do you have lighting enabled? If so, either turn it off or pass colors with the glMaterial-functions.