Question

I'm trying to implement the following algorithm (breaking to painting to small triangles) but I couldn't find any tutorial over the net that explains it properly, Most of the things I've found explain it theoretically and the samples are way too complicated to understand since they contain many other things.

If you can point me how it's done or something like that I would be more than thankful.

Was it helpful?

Solution

From your comment, it looks like you are calling glVertex a million times which means you're using deprecated OpenGL functions, which is probably why your program is running so slowly.

Back in the day (not that I would really know, I'm 20), you specify vertices using glVertex, one at a time, once per frame. This is called the immediate mode. This passes the vertex information to OpenGL memory (usually graphics card) once per vertex per frame. So if you've got 200k vertices, as you said, you're doing this at least 200k times per frame (you can cut it down to exactly 200k if you use indices, but then you have to pass some other stuff to).

I doubt all of these vertices are changing every frame. I'd bet that many or even all of them stay the same over multiple frames. So what you can do is put them into something called a VBO (vertex buffer object), which means you store all of this vertex information in OpenGL memory (again, probably gfx card if you've got one), and then you don't have to transfer all of that stuff every frame.

It's kind of hard to wrap your head around at first. But essentially calling glVertex a million times is like saying this every frame: "Here's a bunch of information that I need you to draw." And you say the same thing every frame. Using Vertex Buffer Objects are like saying this once: "Here's a bunch of information", and then saying this once per frame: "Remember that information I gave you a while back? Draw it."

This is obviously way faster because you don't have to relay the information every frame.

One downside is that if you need to change the vertices, it's a little trickier because the data is no longer controlled by you. In this case, you'd have to get a memory map to the vbo's contents and modify it, rather than passing new data. Or you can always delete it and regenerate it, but if you do this every frame then there's no point in using vbo's over the immediate mode.

I won't post any code regarding VBO's because then this post would get 4 times longer than it already is. I think I've given you many keywords that you can google to find out more information. Here's a few that I would suggest starting with just to learn about the subject (search for them separately):

vertex buffer objects, indices, fixed function pipeline, shaders

If you have any problems implementing any of the stuff that I mentioned, then I suggest you open a new specific question.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top