绘图与glDrawElements所有对象连接 [英] glDrawElements drawing all objects connected

查看:115
本文介绍了绘图与glDrawElements所有对象连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何获得与glDrawElements不连接一切它吸引...

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);

这是什么样的结果是这样的: http://img338.imageshack.us/img338/2440/cows.png

This is what the result looks like: http://img338.imageshack.us/img338/2440/cows.png

应该是两个不同的牛,而是他们与黑线连接。任何意见将AP preciated!

Should be two separate cows but instead they're connected with black lines. Any advice will be appreciated!

推荐答案

我的猜测是,你想画的元素数量是错误的(太大)。所以在GPU试图获取不在缓冲存在,并意外访问下一个网格的顶点的三角形,而不是颜色(黑色)。

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).

尝试与glDrawElements与(GL_TRIANGLES,nElements,GL_UNSIGNED_INT,0)

Try with glDrawElements(GL_TRIANGLES,nElements,GL_UNSIGNED_INT,0);

如果它不能正常工作,请尝试用一只手codeD一个三角形。

If it doesn't work, try with a handcoded single triangle.

下面是一个例子:

GLsizei const TonemapperElementCount = 3;
GLsizeiptr const TonemapperElementSize = TonemapperElementCount * sizeof(glm::uint32);
glm::uint32 const TonemapperElementData[TonemapperElementCount] =
{
    0, 1, 2,
};

GLsizei const TonemapperVertexCount = 3;
GLsizeiptr const TonemapperPositionSize = TonemapperVertexCount * sizeof(glm::vec4);
glm::vec4 const TonemapperPositionData[TonemapperVertexCount] =
{ // A full-screen triangle in normalized screen space.
    glm::vec4( -1.0f, -1.0f,0,1),
    glm::vec4( 3.0f, -1.0f ,0,1),
    glm::vec4( -1.0f, 3.0f ,0,1),
};

这篇关于绘图与glDrawElements所有对象连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆