2

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.

Bart
  • 19,692
  • 7
  • 68
  • 77
igal k
  • 1,883
  • 2
  • 28
  • 57
  • 5
    It is a quite complicated process and graphics programming is a world full of secrets. – Jan Dragsbaek Dec 02 '11 at 08:10
  • 2
    What do you mean by "breaking to painting to small triangles"? – Stiefel Dec 02 '11 at 08:21
  • Do you mean to ask "I have a polygon mesh with a large number of polygons that I would like to supersample to create less detailed versions for viewing from far away"? – Martin Foot Dec 02 '11 at 08:45
  • hey , thanks for the comments , for this discussion , i have around 200K points , and from each point i draw a rectangular polygon built from its neighbors , so total of glvertex calls is around 1M+- , this makes my entire program works slow , one of the solution i've managed to find is using Level-of-Detail algorithms , which means breaking my vertices into small triangles , which reduces the total sum of polygons to be printed , most of the articles i've found are quite complicated , and most of the stuff written there is theoretical , and those which are implemented are very complicated – igal k Dec 02 '11 at 14:56
  • 1
    @igalk: That's because it *is* complicated, as Jan was pointing out. It can't be made simple, because it's not simple. You're just going to have to figure out how it works. If you have a specific question, you can ask. But a general question like this is not a good fit for this website. – Nicol Bolas Dec 02 '11 at 16:10

1 Answers1

5

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!

Andrew Rasmussen
  • 14,912
  • 10
  • 45
  • 81
  • Great Comment Indeed! i just wanted to mentioned that im not planning on changing my DATA every single frames , that acutally depands on the user , my program actually calculates the Mandelbrot set(see fractals) and prints a 3d model on the screen,if the user decides to zoom in every 0.3 second then data will rapidly change and then i guess VBO will be useless , but if he decides to "explorer" to set then VBO is okay... – igal k Dec 04 '11 at 06:49