Jump to content
  • Advertisement
Sign in to follow this  
aneves

OpenGL Gridmap with openGL/SDL

This topic is 3081 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

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)





Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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é

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!