1

I have a several quads which are successfully being displayed on the screen, however when I try to set the colour of one of them it sets the color of all of them.

GL11.glColor3f(red,green,blue);


    xh = getXsize() / 2;
    yh = getYsize() / 2;
    GL11.glPushMatrix();
    GL11.glTranslated(x, y, 0);
    GL11.glTranslatef(10.0f, 10.5f, -0.0f); 
    GL11.glRotated(rotate, 0.0f, 0.0f, -1.0f); 
    GL11.glTranslatef(-10.0f, -10.5f, 0.0f);
    GL11.glTranslated(-x, -y, 0);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2d(x - xh, y - yh);
    GL11.glVertex2d(x - xh, y + yh);
    GL11.glVertex2d(x + xh, y + yh);
    GL11.glVertex2d(x + xh, y - yh);
    GL11.glEnd();
    GL11.glPopMatrix();
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • Can you provide the values you are using for red, green, blue in GL11.glColor3f(red, green, blue);? It would also be helpful to know in what context you are rendering - for instance: is this code called in a loop, do you use GL11.glClear() before? – Anthill Nov 10 '12 at 18:14
  • blue is equal to 0, red and green get changed throughout the course of the program, they go from 0-1 and 1-0 respectively. The program is in a loop, and I use glClear(GL_COLOR_BUFFER_BIT); at the beginning of the loop. –  Nov 10 '12 at 18:23

1 Answers1

1

As far as I see, only one quad is drawn in the code you have posted. Anyways, when you call GL11.glColor3f(red,green,blue) it will be applied to all following quads you draw after calling it. Basically, if you want different color quads, you need to call the function with different values, every time before drawing new quad.

You should give a look on the following to this resource (it's not JWJGL, but OpenGL) in the section called : Specifying a Color and a Shading Model, which explains bit better how the color is being applied to the simple shapes.

Serhiy
  • 4,073
  • 3
  • 36
  • 66