openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.91k stars 2.55k forks source link

ofMesh drawWireframe #1744

Open julapy opened 11 years ago

julapy commented 11 years ago

i came across an issue today when trying to draw a ofMesh wireframe. when the wireframe is drawn inside ofGLRenderer, the draw mode is always set to GL_LINES. but the result was an incomplete wireframe. when i set the draw mode to GL_LINE_STRIP it was rendering correctly.

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/gl/ofGLRenderer.cpp#L101

i think when choosing between GL_LINES and GL_LINE_STRIP to draw wireframes, it depends on the way the triangle vertices are stores, OF_PRIMITIVE_TRIANGLES, OF_PRIMITIVE_TRIANGLE_STRIP etc... but this is a bit of a guess atm... has anyone else come across this?

arturoc commented 11 years ago

can you ask in the dev list? i think keith will know better but he probably doesn't follow the github issues

On 12/11/2012 10:27 AM, lukasz karluk wrote:

i came across an issue today when trying to draw a ofMesh wireframe. when the wireframe is drawn inside ofGLRenderer, the draw mode is always set to GL_LINES. but the result was an incomplete wireframe. when i set the draw mode to GL_LINE_STRIP it was rendering correctly.

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/gl/ofGLRenderer.cpp#L101

i think when choosing between GL_LINES and GL_LINE_STRIP to draw wireframes, it depends on the way the triangle vertices are stores, OF_PRIMITIVE_TRIANGLES, OF_PRIMITIVE_TRIANGLE_STRIP etc... but this is a bit of a guess atm... has anyone else come across this?

— Reply to this email directly or view it on GitHub https://github.com/openframeworks/openFrameworks/issues/1744.

bilderbuchi commented 11 years ago

Also you can ping @kpasko, and maybe he notices it.

ofTheo commented 11 years ago

@julapy I think you're right. an OF_PRIMITIVE_TRIANGLE_STRIP mesh would need OF_PRIMITIVE_LINE_STRIP where as OF_PRIMITIVE_TRIANGLES would need OF_PRIMITIVE_LINES

kpasko commented 11 years ago

good idea christoph :)

Quickly, this is ideally handled via glPolygonMode(GL_FRONT_AND_BACK,GL_LINE), but that's a no-go for gles. Unless GL has added some form of magic and switched things up on me, if the mesh is indexed for either OF_PRIMITIVE_TRIANGLES or OF_PRIMITIVE_TRIANGLE_STRIP, there's not an easy way to get it right with either LINES or LINE_STRIP without getting lucky. I'm actually surprised GL_LINE_STRIP worked correctly for you, as either way it likely only draws the diagonals of the tri-strip and not the borders. Basically nothing fancy going on, its just mimicking the indexing GL internally uses for tris or strips; unfortunately these aren't the same as the way it uses lines or line strips. I can post some images if its helpful.

You could potentially play with using GL_LINE_LOOP paired with edgeFlags, but I think its probably better to just set up the index array correctly for these cases...