Я использую этот код для рисования разных кубов с разными цветами, используя LWJGL:
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(rcol.x, rcol.y, rcol.z); // Color Vector
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Right Of The Quad (Top)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Left Of The Quad (Top)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Bottom Left Of The Quad (Top)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Bottom Right Of The Quad (Top)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Top Right Of The Quad (Bottom)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Top Left Of The Quad (Bottom)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Left Of The Quad (Bottom)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Right Of The Quad (Bottom)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Top Right Of The Quad (Front)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Top Left Of The Quad (Front)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Bottom Left Of The Quad (Front)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Bottom Right Of The Quad (Front)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Left Of The Quad (Back)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Right Of The Quad (Back)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Right Of The Quad (Back)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Left Of The Quad (Back)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Top Right Of The Quad (Left)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Left Of The Quad (Left)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Left Of The Quad (Left)
GL11.glVertex3f(rpos.x - rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Bottom Right Of The Quad (Left)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z - rsiz.z); // Top Right Of The Quad (Right)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y + rsiz.y, rpos.z + rsiz.z); // Top Left Of The Quad (Right)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z + rsiz.z); // Bottom Left Of The Quad (Right)
GL11.glVertex3f(rpos.x + rsiz.x, rpos.y - rsiz.y, rpos.z - rsiz.z); // Bottom Right Of The Quad (Right)
GL11.glEnd();
Он хорошо рисует куб, а цвет идеален, но как только я добавляю в него свет, всепобелел и выглядит ужасно.Вот мой код освещения:
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
float lightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values
float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values
float lightPosition[] = { 20.0f, 15.0f, 20.0f, 1.0f }; // Light Position
float lightSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Light Position
ByteBuffer temp = ByteBuffer.allocateDirect(16);
temp.order(ByteOrder.nativeOrder())
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, (FloatBuffer)temp.asFloatBuffer().put(lightSpecular).flip());
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip()); // Setup The Ambient Light
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip()); // Setup The Diffuse Light
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip()); // Position The Light
Кто-нибудь знает, что я здесь не так делаю?Вот фотки примера: