PDA

View Full Version : Wireframe-Rendering VBO; glEdgeFlagPointer



Oldani
01-11-2010, 02:42 AM
Hello,

I do have problems with the glEdgeFlagPointer, it seams that I do something wrong. My goal is to render meshes in the wireframe-mode with reduced number of edges (glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)). I work with vbo-redering. I just made a small example to demonstrate my goal. The following square is rendered with 2 Triangles. In the wireframe-mode I want to see just the border edges:

http://img199.imageshack.us/img199/8893/edgeflags.png (http://img199.imageshack.us/i/edgeflags.png/)

My VBO is made like this: column 1, 2 and 3 are used for the normals, clumn 4, 5 and 6 for the vertex. To keep it simple I do not use uv-coordinates for textures:

http://img41.imageshack.us/img41/8564/vbo.jpg (http://img41.imageshack.us/i/vbo.jpg/)

In my point of view the edge-flag-array should made like this, but this might by my fault.



GLfloat g_pVertex[]=
{
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
};
unsigned int g_pTriangleIdx[] =
{
0,1,3,
1,2,3
};
GLboolean g_pEdgeArr[] =
{
1,0,1,
1,1,0
};
GLuint pIds[] = {0, 0, 0};
bool create()
{
...

glGenBuffers(3, pIds);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, pIds[0]);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*6 * sizeof(GLfloat), g_pVertex, GL_STATIC_DRAW_ARB);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, pIds[1]),
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 2*3 * sizeof(unsigned int), g_pTriangleIdx, GL_STATIC_DRAW_ARB);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, pIds[2]),
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 2*3 * sizeof(GLboolean), g_pEdgeArr, GL_STATIC_DRAW_ARB);

...
}

void paint()
{
if (!create())
return false;

glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, pIds[0]);

glNormalPointer(GL_FLOAT, 6 * sizeof(GLfloat), 0);
char* offset = 0;
offset = (char*)(sizeof(GLfloat) * 3);
glVertexPointer(3, GL_FLOAT, 6 * sizeof(GLfloat), offset);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, pIds[2]);
glEdgeFlagPointer(0, 0);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, pIds[1]);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_EDGE_FLAG_ARRAY);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

glDisableClientState(GL_EDGE_FLAG_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, NULL);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, NULL);
}


However, my final rendering looks like this:
http://img199.imageshack.us/img199/980/finalra.jpg (http://img199.imageshack.us/i/finalra.jpg/)

Has anyone an idea where I do the mistake?

Thanks a lot!

Oldani
01-11-2010, 06:47 AM
Hello,

Maybe I found the problem. It seems that you have to store the edge-information on the vertex. That means that I have to split the corners that have different border-edges. That is very annoying! And not to efficient for the memory. Is there no other way?

http://img259.imageshack.us/img259/7664/edgesh.jpg (http://img259.imageshack.us/i/edgesh.jpg/)

Dark Photon
01-11-2010, 07:21 AM
Maybe I found the problem. It seems that you have to store the edge-information on the vertex. That means that I have to split the corners that have different border-edges. That is very annoying! And not to efficient for the memory. Is there no other way?
Why not just send only the lines down the pipe that you want to draw when in wireframe mode and render real LINES (or LINE_STRIPS, LINE_LOOPS, etc.)?

Maybe I'm misunderstanding something, and I've never used edge flag, but my understanding is that all it does is determines what gets rendered when you're rendering polygons/triangles and glPolygonMode is GL_POINT or GL_LINE, and not GL_FILL. No?

overlay
01-11-2010, 07:33 AM
As well as a normal, an edge-flag is a vertex attribute.
You can not escape the splitting because the index-array is per vertex not per attribute.

I requested a indexing per attribute:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=265744#Post2657 44

Anyway, in my experience, drawing polygons primitives in GL_LINE mode with edge-flag is really inefficient compared to just draw lines with GL_LINES primitives (as Dark Photon suggested).

Oldani
01-11-2010, 08:10 AM
Anyway, in my experience, drawing polygons primitives in GL_LINE mode with edge-flag is really inefficient compared to just draw lines with GL_LINES primitives (as Dark Photon suggested).

Why not just send only the lines down the pipe that you want to draw when in wireframe mode and render real LINES (or LINE_STRIPS, LINE_LOOPS, etc.)?
Thank you for your answers. If I draw the primitives with GL_Line I canít make use from the face-culling. An other advantage is that I could use the same VBO for wire-frame and shaded look-and-feel.