Rectangles don't have the same size


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?

Thank you and greetings from Switzerland

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 ?

The primitives don’t share the same edge.
The thing is, that I actually want to have a gap between the rectangles. But unfortunately not all of them are visible.

Sorry, my English isn’t that good, but do you understand, what I mean?

Sorry, I though you did not want any gap between primitives.

Now, about this gap : how do you want it ?

  • always 1 pixel wide, always visible : better draw contiguous rectangles, then white lines on top.
  • gap widths in pixels depends on zoom level : what do you want to happen when gap width is equal to half a pixel ?

No problem, I really appreciate your help.

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 ?

Actually the whole thing is an ActivX control. I create the OpenGL context with: wglCreateContext

Do you know a good tutorial about multisampling on the framebuffer?

A bit terse but does cover how to do that with WGL commands :

But before I dive into multi sampling:
Does it really help to solve my problem?
If i use multi sampling, will all the lines/gaps be displayed?

The more samples, the better will be the quality.

Thank you very much, it looks pretty good with 4x multi sampling. :smiley:

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.

Any ideas?

Do you understand what my problem is?

Yes; you’re using ActiveX.

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.

Unfortunately it must be an ActiveX control… So I’m kind of trapped…

Are there any better workarounds than my solution?

Can’t you start an activex window, get the id, store it in a cookie or whatever can be used in this deadend “technology” called activex, then open a second activex window, using this id directly ?