Jump to content
  • Advertisement
Sign in to follow this  
korda

OpenGL 2D diagram

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

I'm not developing a game, but I haven't been able to get a satisfactory answer elsewhere and I figure this is where the graphics experts are. I need to display a large number (thousands or tens of thousands) of points in 2D space with lines connecting pairs of points. The user needs to be able to zoom (preferably "infinitely"), with the points behaving dimensionlessly and the lines behaving one-dimensionally (i.e. zooming in, the ellipses representing points get farther apart but don't get bigger, and the lines get longer but not thicker). The user also needs to be able to scroll. I tried doing this in GDI+ (iterating through a linked list of ellipses, drawing one at a time) but it was way too slow. You'd have to wait for several seconds for all the points to reload after clicking a scroll button. Drawing to bitmaps first, then displaying a bitmap solves the laggy scrolling problem but makes zooming tedious and only allows a fixed number of zoom levels. I'm guessing OpenGL or DirectX is needed. Can someone point me towards the right API and techniques? How are these problems solved in CAD or GIS applications? Are there any relevant books? The next thing I'm planning to try is OpenGL with Qt, if anyone can comment on that. Thanks a lot for your help.

Share this post


Link to post
Share on other sites
Advertisement

(thousands or tens of thousands) is n't a big number for 3D rendering, but OpenGL doesnot support 2D rendering originally. If you are sticked to OGL, you can try to extend any of the open src 3D engines. It would take several thousands of lines.

With Win Vista/7, maybe You can try the Direct2D. I just read a little of that. It's easy to use and should be of high performance.

Share this post


Link to post
Share on other sites
You need to re-think things just a bit. You need two things to do this efficiently; a spatial partitioning system, and a view-oriented rendering system instead of a world-oriented one.

First look up "quadtree". You want to put your points and lines into the quadtree, and when you render an area from the tree you want to query the tree for all points and lines that intersect with the view rectangle. This is very fast because of how a quadtree works; you only draw those lines and points that are going to be visible (more or less).

Second, once you have that information, you know the exact screen-space dimensions you want your points and lines to have, so just render them that way. Don't think of them being of a certain size in world-space; this is in fact probably exactly what you're doing right now, you just haven't noticed that zooming to any scale except 1:1 will produce separate view, screen, and world spaces, where you currently seem to be thinking in only world space.


Edit: Oh, and also; linked lists are generally for data sets that need frequent add/remove operations at arbitrary locations, but get fully iterated or searched only infrequently. Try using vectors or other dynamic-sizing array replacements.

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!