[SOLVED] wrong colors

Started by Keith, November 19, 2010, 22:02:00

Previous topic - Next topic

Keith

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.

Matthias

Disable texturing if you want to render colored lines.

Keith

 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();

  }

Keith

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?

broumbroum

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.

Matthias

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.

Keith

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?

Keith

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();
    }