Jump to content
  • Advertisement
Sign in to follow this  
Chris528

OpenGL How do you triangulate faces?

This topic is 1805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, after quite a bit of work I've been able to calculate all the points for all brushes from a source engine .vmf. For each face I have a set of verts but I'm not sure how to load this into a vbo.

If I'm not mistaken I should create a function that takes in the points of a face and outputs a list of triangles? Also I need this to work with cylinders, as my test map has a cylinder with 32 sides, which means both the top and bottom face each have 32 verts.

How would I go about doing that? I've messed around with quite a few opengl 3.3+ tutorials, but never worked on something this involved before.

Thanks, Chris528

Share this post


Link to post
Share on other sites
Advertisement

If all faces are convex (they usually are), just turn them into the equivalent of triangle fans, i.e. the first triangle is vertices 0-1-2, the next is 0-2-3, the next 0-3-4, then 0-4-5, and so on.

 

Alternatively, just import it into an editor and make it triangulate the faces for you =P

Share this post


Link to post
Share on other sites

I was typing a reply at the same time as Sik, so I'll delete what I was saying and just post the diagram that goes with his explanation of the fans ;)

8l4C4yv.png

 

Also, vmf files are not meant to be rendered directly (except in the editor). In Valve's engine/tools, the "brushes" from the map files are fed into a CSG algorithm, which produces the final geometry data.

Share this post


Link to post
Share on other sites

Also, vmf files are not meant to be rendered directly (except in the editor). In Valve's engine/tools, the "brushes" from the map files are fed into a CSG algorithm, which produces the final geometry data.


My immediate goal is to make a simple vmf viewer. In my first post I said I'd already parsed the vmf and calculated all the points from the planes. I'm just looking to split all the faces up into triangles. Edited by Chris528

Share this post


Link to post
Share on other sites

If all faces are convex (they usually are), just turn them into the equivalent of triangle fans, i.e. the first triangle is vertices 0-1-2, the next is 0-2-3, the next 0-3-4, then 0-4-5, and so on.


Hey, thanks for your help.

I was thinking of doing the exact same thing before I asked here but couldn't figure it out, even after working on it for hours.

After messing around with the code a bit this morning I used your suggestion, and finally got a working loop that calculates all the triangles.(even for 32 sided cylinders) Edited by Chris528

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!