[英]Using glArrayElement with LWJGL
I'm following along with the OpenGL tutorial found here . 我将跟踪此处找到的OpenGL教程。 I'm on chapter 2 right now and it's going over the advantages of using
glArrayElement
to render objects. 我现在在第2章,它讨论了使用
glArrayElement
渲染对象的优点。 Currently, my code is as follows: 目前,我的代码如下:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
double vertices[] = {100, 200, 0, 200, 100, 0, 100, 100, 0};
double colors[] = {1, .5, .8, .3, .5, .8, .3, .5, .8};
DoubleBuffer vertexBuffer = BufferUtils.createDoubleBuffer(9).put(vertices);
DoubleBuffer colorBuffer = BufferUtils.createDoubleBuffer(9).put(colors);
glVertexPointer(3, 0, vertexBuffer);
glColorPointer(3, 0, colorBuffer);
while(!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glArrayElement(0);
glArrayElement(1);
glArrayElement(2);
glVertex3d(300, 200, 0);
glVertex3d(400, 100, 0);
glVertex3d(300, 100, 0);
glEnd();
//Display.sync(60);
Display.update();
}
The second triangle, defined explicitly by calls to glVertex3d
is rendered fine. 通过调用
glVertex3d
明确定义的第二个三角形可以正常显示。 Bu the first triangle does not render at all. 但是第一个三角形根本不渲染。 Am I making a simple mistake?
我是在犯一个简单的错误吗?
While scouring for more sample code, I came across a snippet that said you had to "flip each buffer." 在搜寻更多示例代码时,我遇到了一个片段,说您必须“翻转每个缓冲区”。 Adding
新增中
vertexBuffer.flip();
colorBuffer.flip();
Right before the while
loop solved my problem! 在
while
循环之前解决了我的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.