• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
luckyyyyyy

Fastest way to render line mesh over 3D triangular mesh?

5 posts in this topic

I am rendering lines over 3D triangular mesh in order to visualize the mesh triangles. Well-known feature of every 3D modeling software right?
but I am drawing the line with glVertex3f, How can I draw with vertex buffer or vertex array.
and how can i optimize this code.. because with this code, i am getting very low FPS... just 15..
any idea ?


[code]
void RenderModelMeshAsLines(GLpoint *P, GLFace *T, int nbF)
{
if(nbF > 0)
{
glLineWidth(2.0); // Set The Line Width
GLfloat r=0.0f, g=0.0f, b=0.0f;
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT);
glPushMatrix();
glBegin(GL_LINE);
for (int i=0; i<nbF; i++)
{
DrawLine(P[T[i].v1], P[T[i].v2], r,g,b);
DrawLine(P[T[i].v2], P[T[i].v3], r,g,b);
DrawLine(P[T[i].v3], P[T[i].v1], r,g,b);
}
glEnd();
glPopMatrix();
glPopAttrib();
glLineWidth(1.0); // Set The Line Width
}
}

[/code]

Draw a line...
[code]
void DrawLine(GLpoint a, GLpoint b, float R, float G, float B)
{
glPushMatrix();
glDisable(GL_LIGHTING);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_LINES);
glColor3f(R, G, B);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
glEnd();
glPopMatrix();
}

[/code]
0

Share this post


Link to post
Share on other sites
Seems like you're emitting vertices in immediate mode, so I'm not surprised it's slow! The best thing I can do is [url="http://www.songho.ca/opengl/gl_vbo.html"]point you towards a vertex buffer object tutorial[/url], or Google, because there are quite a few out there.
-1

Share this post


Link to post
Share on other sites
Also, keep in mind you change the [color=#000000][font=Times][size=1]glPolygonMode to [/size][/font][/color][color=#000000][font=monospace][size=1]GL_LINE[/size][/font][/color][color=#000000][font=Times][size=1] and then you might not have to write a whole bunch of new rendering code. :D[/size][/font][/color]
1

Share this post


Link to post
Share on other sites
If you ever venture into geometry shaders you may be interested in http://cgg-journal.com/2008-2/06/index.html

or (sorry for the long google link)

http://www.google.com/url?sa=t&rct=j&q=solid%20wirframe%20nvidia&source=web&cd=1&ved=0CDsQFjAA&url=http%3A%2F%2Fdeveloper.download.nvidia.com%2Fwhitepapers%2F2007%2FSDK10%2FSolidWireframe.pdf&ei=bxZqT871JqGe2gWK-5HvCA&usg=AFQjCNEk0nXCt_9NKuarJ5JdlMSXfIY3lw&cad=rja
0

Share this post


Link to post
Share on other sites
A VBO is not likely to help so much here as your data looks to be dynamic and your code is nasty - see further down for help with this; you certainly won't see jumps from 15fps to 60 or more (immediate mode is slow but it's not [i]that[/i] slow). I really wish people would stop recommending "use a VBO" as if it's some kind of magic dust that you can just sprinkle on bad or slow code to make it good or fast - it's not.

There are a few things in your code that are hurting you and that you can fix Right Now. VBO or no VBO, these are your primary problems and need to be addressed.

glLineWidth (2.0) - values other than 1 may not be hardware accelerated. Try setting it to 1, if performance jumps dramatically then it's a reasonably decent indication that your driver is falling back on some form of software emulation (perhaps faking lines by using solid quads, perhaps something else).

I expect it won't jump because of...

State changes. The way you're handling these is almost a textbook case of the worst possible way to do it (sorry, but it's true). You've a whole heap of state changes inside of a loop that could easily be moved outside of it, you've a glPushMatrix and glPopMatrix that do absolutely nothing at all (since you don't do any transforms between them) - again inside of the same loop, and you've a second inner glBegin/glEnd pair inside of your first glBegin/glEnd pair (GL_LINE isn't even a valid param for glBegin).

Your drawline function could and should be reduced to this:
[code]void DrawLine(GLpoint a, GLpoint b, float R, float G, float B)
{
glColor3f(R, G, B);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
}[/code]
The state changes go outside the for loop in RenderModelMeshAsLines, which then looks like this:
[code]void RenderModelMeshAsLines (GLpoint *P, GLFace *T, int nbF)
{
if (nbF > 0)
{
GLfloat r = 0.0f, g = 0.0f, b = 0.0f;

glLineWidth (2.0);
glPushAttrib (GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT);

glDisable (GL_LIGHTING);
glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin (GL_LINES);

for (int i = 0; i < nbF; i++)
{
DrawLine (P[T[i].v1], P[T[i].v2], r, g, b);
DrawLine (P[T[i].v2], P[T[i].v3], r, g, b);
DrawLine (P[T[i].v3], P[T[i].v1], r, g, b);
}

glEnd ();
glPopAttrib ();
glLineWidth (1.0);
}
}[/code]
Just this basic clean-up and correction should be enough to see your performance go back up to where you want it to be. If it's still not enough then look at VBOs or geometry shaders, but not before. Correct your code and get it well-behaving first.
0

Share this post


Link to post
Share on other sites
If you're using the depth buffer, make sure you turn on glPolygonOffset to avoid z-fighting. [url="http://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm"]http://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm[/url]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0