【发布时间】:2013-06-28 00:02:44
【问题描述】:
我无法让颜色与 OpenGL 一起正常工作。 我正确地绘制了我的形状,它们看起来很好,但是当我调用 glColor4d(r,g,b,a) 时,它没有正确使用颜色,因为它的 RGB 应该指示,而是绘制不同的但相似的颜色。例如,大多数绿色被绘制为完全黄色或完全绿色,而任何灰色都被绘制为纯白色。
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]
在这个随机颜色值的简短列表中,它们都被绘制为纯 FFFFFF 白色,即使它们都不应该是白色的。
我用来绘制矩形的代码:
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();
}
【问题讨论】:
标签: java opengl rendering lwjgl