glDrawElements 绘制所有连接的对象
我不知道如何让 glDrawElements 不连接它绘制的所有内容...
//Draw Reds
glEnableVertexAttribArray(vLoc);
glEnableVertexAttribArray(cLoc);
glBindBuffer(GL_ARRAY_BUFFER,positionBufferRed);
glVertexAttribPointer(vLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ARRAY_BUFFER,redBuffer);
glVertexAttribPointer(cLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elementBufferRed);
glDrawElements(GL_TRIANGLES,nElements*3,GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(vLoc);
glDisableVertexAttribArray(cLoc);
//Draw Blues
glEnableVertexAttribArray(vLoc);
glEnableVertexAttribArray(cLoc);
glBindBuffer(GL_ARRAY_BUFFER,positionBufferBlue);
glVertexAttribPointer(vLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ARRAY_BUFFER,blueBuffer);
glVertexAttribPointer(cLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elementBufferBlue);
glDrawElements(GL_TRIANGLES,nElements*3,GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(vLoc);
glDisableVertexAttribArray(cLoc);
结果如下: http://img338.imageshack.us/img338/2440/cows.png
应该是两只独立的牛,但它们用黑线连接起来。任何建议将不胜感激!
I can't figure out how to get glDrawElements to not connect everything it draws...
//Draw Reds
glEnableVertexAttribArray(vLoc);
glEnableVertexAttribArray(cLoc);
glBindBuffer(GL_ARRAY_BUFFER,positionBufferRed);
glVertexAttribPointer(vLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ARRAY_BUFFER,redBuffer);
glVertexAttribPointer(cLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elementBufferRed);
glDrawElements(GL_TRIANGLES,nElements*3,GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(vLoc);
glDisableVertexAttribArray(cLoc);
//Draw Blues
glEnableVertexAttribArray(vLoc);
glEnableVertexAttribArray(cLoc);
glBindBuffer(GL_ARRAY_BUFFER,positionBufferBlue);
glVertexAttribPointer(vLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ARRAY_BUFFER,blueBuffer);
glVertexAttribPointer(cLoc,3,GL_FLOAT,GL_FALSE,0,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elementBufferBlue);
glDrawElements(GL_TRIANGLES,nElements*3,GL_UNSIGNED_INT,0);
glDisableVertexAttribArray(vLoc);
glDisableVertexAttribArray(cLoc);
This is what the result looks like:
http://img338.imageshack.us/img338/2440/cows.png
Should be two separate cows but instead they're connected with black lines. Any advice will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是您尝试绘制的元素数量是错误的(太大)。因此,GPU 尝试获取缓冲区中不存在的三角形,并意外访问下一个网格的顶点,而不是颜色(黑色)。
尝试使用 glDrawElements(GL_TRIANGLES,nElements,GL_UNSIGNED_INT,0);
如果它不起作用,请尝试使用手工编码的单个三角形。
这是一个例子:
My guess is that the number of elements you're trying to draw is wrong (too big). So the GPU tries to get triangles that don't exist in the buffer, and accidentally access the vertices of the next mesh, but not the color (black).
Try with glDrawElements(GL_TRIANGLES,nElements,GL_UNSIGNED_INT,0);
If it doesn't work, try with a handcoded single triangle.
Here's an example :