Reputation: 793
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();
}
Upvotes: 1
Views: 926
Reputation: 2496
glColor4d()
takes parameters from 0.0 to 1.0, not to 255 as glColor4i()
does. Everything above 1.0
is changed to 1.0
and results in white color in most cases.
Change
GL11.glColor4d(fill.getRed(), fill.getGreen(), fill.getBlue(), fill.getAlpha());
to
GL11.glColor4d(fill.getRed() / 255.0, fill.getGreen() / 255.0, fill.getBlue() / 255.0, fill.getAlpha() / 255.0);
Upvotes: 4