我试图在jogl中为我的多边形着色。我已将顶点存储在数组中,三角形顺序的索引数组和颜色数组。代码如下,但我面临的问题是三角形是白色,而不是颜色缓冲区的颜色。
float f[] = {1000,2000,-4000,-2000,-2000,-4000,2000,-2000,-4000,1000,-4000,-4000};
FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(12);
this.coordCount = 12;
buffer.put(f);
buffer.rewind();
int indx[] = {0,1,2,1,3,2};
IntBuffer indxBuffer = GLBuffers.newDirectIntBuffer(6); //Total number of vertices
this.indexCount = 6;
indxBuffer.put(indx);
indxBuffer.rewind();
float color[] = {1,0,1,0,0,0,0,0,0,1,0,0};
FloatBuffer colorBuffer = GLBuffers.newDirectFloatBuffer(12);
colorBuffer.put(color);
colorBuffer.rewind();
gl.glDisable(GL.GL_TEXTURE_2D);
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glFrontFace(GL.GL_CCW);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, buffer);
gl.glColorPointer(3, GL.GL_FLOAT, 0, colorBuffer);
gl.glDrawElements(GL.GL_TRIANGLES, this.indexCount, GL.GL_UNSIGNED_INT, indxBuffer);
gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glEnable(GL.GL_TEXTURE_2D);
我在NASA世界风球上做这个渲染。但我不认为这会导致任何问题。有人能帮我解决问题吗?我被困在这一段时间了。
谢谢,
答案 0 :(得分:0)
得到解决方案,只需启用颜色和材料。
gl.glEnable(GL2.GL_COLOR_MATERIAL);
gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE);