I need to display a huge number of rectangles on the screen. (Between 500 and 1000000)
To be more accurate, I’m implementing a viewer which shows the status of a tiled field. Each tile can be in an other state, indicated by it’s color.
The whole thing only needs to be in 2D. Therefore I chose an orthogonal projection.
Unfortunately I just faced the problem, that rectangles, which are displayed on the screen, don’t have the same size. (OK, it’s just one pixel. But especially with small tiles, this could become unacceptable).
The other problem is, that when I zoom out, that not all the gaps between the tiles are drawn (I wouldn’t mind if none of them is drawn when zooming out):
I guess, that this is because of a rounding problem inside OpenGL, isn’t?
Is there a way how I can avoid this?
On a good GL implementation, there is should be no gap and no overdraw between primitives sharing exactly the same edge (same coordinates for 2 vertices).
Can you show how you generate coords and how you draw rectangles ?
What is your hardware/drivers/OS ?
I would prefer, that the gap width depends on zoom level. If the gap width is smaller than a pixel, the gap shouldn’t be displayed anymore or, if this is possible, the color of the gap should be an average of rectangle and gap.
But the most important thing for me is, that either all the gabs are displayed or none of them. (In picture above some are and some aren’t)
You can fake it by switching to ‘contiguous rectangles, then white lines on top’ as soon as zoom level means gap is <1, and change alpha value of the lines according to the gap width (0=lines are completely transparent, 0.5 half transparent, 1=totally opaque).
There will still be a big difference when gap is 1.5 pixels, between gaps being 2 pixels wide and 1 pixel wide. In the case the best fix is to keep your current drawing method, but with multisampling on the frambuffer.
How do you currently create your OpenGL window ? Using GLUT, SDL, X or Win specific commands ?
Thank you very much, it looks pretty good with 4x multi sampling.
Although I had to do a little hack:
As I said, my OpenGL rendering context is inside an ActiveX control. The problem is, that wglChoosePixelFormat needs an OpenGl context, which has already been created, in order to find the appropriate pixel format.
But since the creation of the OpenGl context already needs a pixel format I run in a kind of doom loop.
Then it’s not possible to set the pixel format for a device context twice, so I would have to recreate the window, but this is impossible, because it’s an ActiveX control.
Do you understand what my problem is?
My temporary solution is to just pass on a constant value to the SetPixelFormat function. It’s working, but I’m not sure, whether this PixelFormat ID could change on a different system.
Well technically, your problem is the oddball OpenGL context creation on Windows platforms. But the reason you’re unable to do what a normal Windows application would do (create a window for the sole purpose of getting the WGL functions) is because you’re using ActiveX.
It’s working, but I’m not sure, whether this PixelFormat ID could change on a different system.
You can pretty much be guaranteed that it will. Particularly across ATI/NVIDIA hardware, but I wouldn’t be surprised if the pixel format indices changed even with a driver update.
So I wouldn’t consider this an adequate solution to your problem.