1

I'm having trouble getting colors to work properly with OpenGL. I draw my shapes properly, and they look fine, but when I call glColor4d(r,g,b,a), it doesn't correctly use the color as it's RGB should dictates, but instead draws a different but similar color. For example, most greens get drawn as either completely yellow or completely green, and any grays get drawn as solid white.

Color[r=132,g=234,b=208,a=255,hexa=84EAD0]
Color[r=150,g=1,b=59,a=255,hexa=96013B]
Color[r=88,g=117,b=170,a=255,hexa=5875AA]
Color[r=219,g=190,b=26,a=255,hexa=DBBE1A]
Color[r=208,g=51,b=164,a=255,hexa=D033A4]
Color[r=85,g=43,b=228,a=255,hexa=552BE4]
Color[r=167,g=123,b=184,a=255,hexa=A77BB8]
Color[r=241,g=183,b=25,a=255,hexa=F1B719]

In this short list of random color values, all of them are drawn as solid FFFFFF white, even though none of them should be white.

Code i'm using to draw rectangles:

public void drawRectangle(Color fill, double x, double y, double width, double height, double rot){
    GL11.glPushMatrix();
    GL11.glTranslated(x, y, 0);
    GL11.glRotated(rot, 0, 0, 1);
    GL11.glTranslated(-x, -y, 0);
    GL11.glBegin(GL11.GL_TRIANGLES);
    if(fill != null)GL11.glColor4d(fill.getRed(), fill.getGreen(), fill.getBlue(), fill.getAlpha());
    double width2 = width/2;
    double height2 = height/2;
    GL11.glVertex2d(x - width2, y + height2);
    GL11.glVertex2d(x - width2, y - height2);
    GL11.glVertex2d(x + width2, y + height2);
    GL11.glEnd();
    GL11.glBegin(GL11.GL_TRIANGLES);
    if(fill != null)GL11.glColor4d(fill.getRed(), fill.getGreen(), fill.getBlue(), fill.getAlpha());
    GL11.glVertex2d(x - width2, y - height2);
    GL11.glVertex2d(x + width2, y + height2);
    GL11.glVertex2d(x + width2, y - height2);
    GL11.glEnd();
    GL11.glPopMatrix();
}
4

1 回答 1

4

glColor4d()将参数从 0.0 到 1.0,而不是 255 glColor4i()。在大多数情况下,上面的所有1.0内容都更改为1.0并导致白色。
改变

GL11.glColor4d(fill.getRed(), fill.getGreen(), fill.getBlue(), fill.getAlpha());

GL11.glColor4d(fill.getRed() / 255.0, fill.getGreen() / 255.0, fill.getBlue() / 255.0, fill.getAlpha() / 255.0);
于 2013-06-28T06:51:41.577 回答