OpenGL (ES) Android -- 为什么这个 glcolorpointer 只显示黑色?

发布于 2024-11-05 11:43:49 字数 860 浏览 0 评论 0原文

我正在尝试绘制渐变,但首先我只想让 glcolorpointer 正常工作。如果我使用 glColor4f(...) 它会正确绘制颜色,但 glcolorpointer 只是绘制黑色。请帮忙


gl11.glPushMatrix();
//gl11.glColor4f(RGBBorder[0], RGBBorder[1], RGBBorder[2], alpha);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexPointerCube);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexPointerCube);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);    
float colors[] = {.7f,.7f,.7f,.5f};
ByteBuffer vbb = ByteBuffer.allocateDirect(colors.length * 4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer buff = vbb.asFloatBuffer();
buff.put(colors);
buff.position(0);               

gl.glColorPointer(4, GL10.GL_FLOAT, 0, buff);
gl11.glVertexPointer(3, GL10.GL_FLOAT, 0, 0);
gl11.glDrawElements(GL11.GL_TRIANGLES, indicesCube, GL11.GL_UNSIGNED_SHORT, 0);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl11.glPopMatrix();

I'm trying to draw a gradient, but first I just want to get the glcolorpointer working. If I use glColor4f(...) it draw colors correctly, but the glcolorpointer just draws black. Help please


gl11.glPushMatrix();
//gl11.glColor4f(RGBBorder[0], RGBBorder[1], RGBBorder[2], alpha);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexPointerCube);
gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexPointerCube);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);    
float colors[] = {.7f,.7f,.7f,.5f};
ByteBuffer vbb = ByteBuffer.allocateDirect(colors.length * 4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer buff = vbb.asFloatBuffer();
buff.put(colors);
buff.position(0);               

gl.glColorPointer(4, GL10.GL_FLOAT, 0, buff);
gl11.glVertexPointer(3, GL10.GL_FLOAT, 0, 0);
gl11.glDrawElements(GL11.GL_TRIANGLES, indicesCube, GL11.GL_UNSIGNED_SHORT, 0);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl11.glPopMatrix();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所有深爱都是秘密 2024-11-12 11:43:49

我认为问题在于您只为一个顶点添加颜色,并且将 buff 留得太小而无法处理您拥有的所有顶点。使用颜色缓冲区,在本例中,每个顶点应该有 4 个浮点乘以 8(假设您正在绘制一个立方体)。它应该与引入顶点坐标非常相似,即使我从未使用过 GL11.glBindBuffer 。这次的不同之处在于您为每个顶点分配的颜色值。

本教程如果您还没有读过,那么这本书非常值得一读。

I think the problem is that you add color for one vertex only, and leave buff too small to handle all vertices you have. Using color buffer you're supposed to have, in this case, 4 floats per vertex, times 8 (assuming it's a cube you're drawing). It should be very much the same as introducing your vertex coordinates, even though I've never played around with GL11.glBindBuffer. This time with the difference it's a color value you're assigning for each vertex.

This tutorial is very good read if you haven't done it already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文