Gridmap with openGL/SDL

Started by
3 comments, last by szecs 13 years, 9 months ago
Hi!

I'm writing a robotics interface and I want to draw a grid map of the environment. I have a matrix that stores the probability of occupation for each tile of the grid (0 for clear; 1 for occupeid).

Now, I'm drawing a sequence of GL_QUADS with the color of the occupation but it seems be slow.

for (int j=0; j<map.GetSizeY(); j++){    for (int i=0; i<map.GetSizeX(); i++){      glBegin(GL_QUADS);     	gray=1.0-map.GetProbValue(i,j,k);	glColor3f(gray,gray,gray);		glVertex2f((map.idx2x(i)-r),(map.idx2y(j)-r));	glVertex2f((map.idx2x(i)-r),(map.idx2y(j)+r));	glVertex2f((map.idx2x(i)+r),(map.idx2y(j)+r));	glVertex2f((map.idx2x(i)+r),(map.idx2y(j)-r));	      glEnd();    }  }



Is there any other way to draw the gridmap?

Thanks in advance,

André

PS: r is half of the resolution of the map (i,e. r is the size of each tile)





Advertisement
Look for information on vertex buffer objects.

But a quick speedup here would be to move the glBegin/glEnd calls outside of the loops, because they only need to be called once.
Hi,

Thanks for the fast reply. you're right about glBegin/end inside the loop. already done that but it doesn't show any improvement. I'll look up vertex buffer and i'll tell if it worked.

If anyone has any other ideia, shoot, i'm really stuck...

Thanks,
André
You could switch from QUADS to TRIANGLE_STRIPS, take a look at this You might have to do some funky stuff to get the color working for each space though
All the elements have to be drawn on the screen?
If only a portion, you should only draw that portion.
Does the map change frequently? If not: VBO. or render it to a texture if it changes. And only render a fullscreen quad with that texture, if it1s not changing.

Is it 2D or 3D?
If 2D, there's a lot of hacks you could do. The render to texture is just one.

This topic is closed to new replies.

Advertisement