Hello Guest

[SOLVED] wrong colors

  • 7 Replies
  • 8543 Views
[SOLVED] wrong colors
« on: November 19, 2010, 22:02:00 »
My drawing is appearing as I expect except for the colors. No matter how I set the vertex colors, all polygons still appear in this ugly blue-green. GL_LINES, each of which has its own color, appear as black. I am using vertex arrays. The normals seem to be working just fine.  Shading seems to be correct also. Diagnostics show the correct colors being set. I have tried setting everything to red or some gradation between 0 and 1 for green or black and it does not make any difference. If you would like to see some of the code, please let me know what you are interested in seeing. I started with the Gears demo and have been modifying it.
« Last Edit: November 23, 2010, 17:46:36 by Keith »

Re: wrong colors
« Reply #1 on: November 19, 2010, 22:19:24 »
Disable texturing if you want to render colored lines.

Re: wrong colors
« Reply #2 on: November 22, 2010, 17:27:17 »
 I am rendering using the following code:

The interesting thing is that if uncomment 
  GL11.glDisable(GL11.GL_TEXTURE_2D);
which comes after surface.draw(), the surface is drawn in white (correctly shaded for the light). If the line above is commented out, all polygons (no matter what color is set for the vertices) are drawn in an ugly blue-green. In no case are the lines drawn in the correct colors.

 private void drawSurface()
  {
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    if (zOffset <= 0)
    {
      zOffset = 0;
    }
   
    float adjX = (float) x,
          adjY = (float) y,
          adjZ = (float) (z + zOffset);
   
    GLU.gluLookAt(adjX, adjY, adjZ,
                  adjX + angleX, adjY + angleY, adjZ,
                  0f, 0f, 1f); // rotate so z axis is up
   
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    // set lighting
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, lightPos);
   
    if (surface != null)
    {
      surface.draw();
    }
   
    // GL11.glDisable(GL11.GL_TEXTURE_2D);
   
    if (contourLines != null)
    {
      contourLines.draw();
    }

    Display.update();
   
    GL11.glPopMatrix();

  }

Re: wrong colors
« Reply #3 on: November 22, 2010, 22:26:09 »
I have fixed part of my problem, but the basic problem still remains.

The code is now:
 
    if (surface != null)
    {
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      surface.draw();
    }
   
    if (contourLines != null)
    {
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      contourLines.draw();
    }


so textures are enabled before the surface draw and disabled before the line draw.

My surface is still the same wrong color no matter what color I set it to and the lines now draw as a light pink, no matter what colors I set them to.

Why do I need to enable textures when I am trying to fill the  polygons with a color?

Re: wrong colors
« Reply #4 on: November 22, 2010, 23:14:40 »
I think it s the lighting you enabled that is in fault. Either switch it off, or set the three params diffuse , ambient and specular to a white 100%. Whenever the light is                 switched on, it should not  change the color.

Re: wrong colors
« Reply #5 on: November 22, 2010, 23:51:58 »
The default mode is GL_MODULATE - it will multiply the vertex color with the texture color. So if you just want to see your texture set the color to white (1,1,1,1) - if you just want to see your colored lines disable texturing.

Re: wrong colors
« Reply #6 on: November 23, 2010, 15:51:16 »
I have gotten this advice twice, to "disable texturing." In my code, just before I draw the lines,
GL11.glDisable(GL11.GL_TEXTURE_2D);


Is there something else I should be doing?

[SOLVED] Re: wrong colors
« Reply #7 on: November 23, 2010, 17:45:34 »
broumbroum is the winner. The lighting was the problem. The following code works to draw a surface, then draw lines over it in the correct colors. Thanks for your help.

   
 if (surface != null)
    {
      GL11.glEnable(GL11.GL_LIGHTING);
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      surface.draw();
    }
   
    if (contourLines != null)
    {
      GL11.glDisable(GL11.GL_LIGHTING);
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      contourLines.draw();
    }