0
\$\begingroup\$

I'm trying to render line list using indices of triangles as follow

float *vertices = static_cast<float *>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));

for (int i = 0; i < out.numberofpoints; i++)
{
    vertices[(i*3)] = out.pointlist[(i*3)];
    vertices[(i*3)+1] = out.pointlist[(3*i)+1];
    vertices[(i*3) + 2] = out.pointlist[(3*i)+2];

}

vertexBuffer->unlock();

uint16_t *indices = static_cast<uint16_t *>(indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));


int  l, t;
int numTriangles = out.numberoftrifaces*3*sizeof(uint16_t);
for (l = 0, t = 0; t<numTriangles; t += 3) {
    // Each vertex has to be listed twice
    indices[l] = out.trifacelist[t];      l++;
    indices[l] = out.trifacelist[t + 1];    l++;
    indices[l] = out.trifacelist[t + 2];    l++;
    indices[l] = out.trifacelist[t + 2];    l++;
    indices[l] = out.trifacelist[t + 1];    l++;
    indices[l] = out.trifacelist[t];      l++;
}


indexBuffer->unlock();

The problem that ogre renders broken triangles and it's completely wrong. I'm not doing anything wrong regarding rendering the lines that the triangles are composed

I'm using ogre 1.9

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Can you post an image? \$\endgroup\$ – Bálint Jan 18 '18 at 9:39
  • \$\begingroup\$ @Bálint I posted an image. \$\endgroup\$ – andre ahmed Jan 18 '18 at 9:43
1
\$\begingroup\$

The triangles you're drawing per iteration of the loop are the triangles:

t, t + 1, t + 1

And

t + 2, t + 2, t

These are degenerate triangles, presumably you want:

t, t + 1, t + 2
t + 2, t + 1, t
\$\endgroup\$
  • \$\begingroup\$ Thanks for your fast reply. and how much would be the size of line index ? \$\endgroup\$ – andre ahmed Jan 18 '18 at 9:43
  • \$\begingroup\$ This should draw triangles or line list ? \$\endgroup\$ – andre ahmed Jan 18 '18 at 9:44
  • \$\begingroup\$ I attached the picture, still broken triangles \$\endgroup\$ – andre ahmed Jan 18 '18 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.