Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenLayer border issues

Credits go to Fladimir da Gorf for helping out!
This thread is locked; no one can reply to it. rss feed Print
OpenLayer border issues
Billybob
Member #3,136
January 2003

I think this may have been brought up before, but I don't remember the solution.

I'm doing a tilemap in OpenLayer 1.92. When the "camera" first shows up it's at 0, 0. The Camera thus sets Transform::SetPosition to 512, 384.
Everything looks fine there. See my attachment and look at the top picture.

Now when I scroll the map a little bit I get a grid effect. See the attachment's bottom picture. I'm assuming this puts the camera at a non-integer position and causes the blits to end up at weird places. The grid effect goes on and off as I scroll.

1void CGroundManager::Draw()
2{
3 //RETRO//Draw
4 RETROEntity::Draw();
5 //RETRO//
6
7 //Your code starts here//
8 Vector low = Camera.Position - (Vector(SCREEN_W, SCREEN_H) / 2.0);
9 Vector count(22, 17);
10
11 int minx = (int)floor(low.x / 50);
12 int miny = (int)floor(low.y / 50);
13
14 for(int y = miny; y < (miny + count.y); ++y)
15 {
16 for(int x = minx; x < (minx + count.x); ++x)
17 {
18 int type = (int)((IntNoise(x * y) + 1.0));
19
20 bmpTiles[type]->Blit(x * 50.0, y * 50.0);
21 }
22 }
23}

Bitmaps are 100x100 PNGs with no alpha (except for what OpenLayer adds).

Fladimir da Gorf
Member #1,565
October 2001
avatar

In fact those borders are actually translucent lines. The issue comes from OpenGL's way to render the quads and is "fixed" in OL2.0 so that the borders don't appear.

To fix that you could make the Bitmaps one pixel wider and high than supposed (by copying the last row and column) and then rendering those in a reversed order.

An another (and better) way would be to compile OpenLayer again with the fix, but unfortunately I've split the image loading and rendering to several parts behind the scenes to allow OpenLayer to work easier with SDL, for example. I've changed so much that I don't remember which changes were important for the fix anymore... This is the relevant code and should be placed in the Load-methods right before SendToGPU. It might not be enough, though.

1OL_MEMORY_IMG *usedBmp = bmp;
2 bool useTemp = false;
3
4 int textureH = bmp->h;
5 int textureW = bmp->w;
6
7 int bmpW = bmp->w;
8 int bmpH = bmp->h;
9
10 textureW = ToNextPowOfTwo( bmpW );
11 textureH = ToNextPowOfTwo( bmpH );
12
13 useTemp = textureW != bmpW || textureH != bmpH;
14
15 if( useTemp ) {
16 int tempW = textureW + 1;
17 int tempH = textureH + 1;
18
19 OL_MEMORY_IMG *temp = create_bitmap_ex( bitmap_color_depth( bmp ), tempW, tempH );
20
21 blit( bmp, temp, 0, 0, 0, 0, bmpW, bmpH );
22 blit( bmp, temp, bmp->w-1, 0, bmp->w, 0, 1, bmp->h );
23 blit( bmp, temp, 0, bmp->h-1, 0, bmp->h, bmp->w, 1 );
24
25 usedBmp = temp;
26
27 save_bitmap( "test.bmp", usedBmp, 0 );
28 }

PS. I'd be better if 2.0 would be ready already, but it doesn't still feel complete to me. And to consider that originally it was only going to be a really small update...

EDIT: Tried to make it clear that the old Bitmap API isn't going to change.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Billybob
Member #3,136
January 2003

Quote:

To fix that you could make the Bitmaps one pixel wider and high than supposed (by copying the last row and column) and then rendering those in a reversed order.

Could you elaborate?

Fladimir da Gorf
Member #1,565
October 2001
avatar

The problem is that the last row and column are both translucent because the invisible translucent parts in the right and bottom side of the Bitmap are blended with the opaque pixels in the edges (or so I think):

 _____________
|visible |    |
| image  |    |
|________|    |
|  invisible  |
|   borders   |
|_____________|

A Bitmap with exaggerated borders

Those borders exist to make the dimensions of the Bitmap powers of two. Some hardware support non-power-of-two images and those are supported in OL2.0 (once again ;))

However, in usual hardware when you render the image at subpixel coordinates the borders of the image aren't clipped properly if there's borders around the image.

To prevent that, make the Bitmap one pixel wider and higher than it's supposed to be. Then render the tilemap so that you can't see any overlapping - thus you need to render the tilemap from bottom to up, right to left.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Billybob
Member #3,136
January 2003

Quote:

you need to render the tilemap from bottom to up, right to left.

Naw, no need for that.

Just changing the line to:
bmpTiles[type]->BlitStretched(x * 50.0, y * 50.0, 51.0, 51.0);
fixes it and it looks fine (I'm guessing 1 pixel stretch shouldn't visually affect things noticably)

Thanks for the help. ;D

Go to: