tags:

views:

183

answers:

3

I am using opengl in a tilemap editor. Storing the tilemap in GL_LUMINANCE32F format, then modifying it with opengl commands.

Now, I'm realising canvas size limitations are a burden for people drawing tilemaps. So how could I implement an infinite canvas? (such that expands and shrinks without user needing to explicitly trigger it to expand or shrink)

The expanding or shrinking of the canvas in need isn't hard, I can easily create another canvas, move the old canvas contents on it and remove the old canvas. Instead, what I have no clue of is that how could I get the canvas to detect when it can shrink, and how much can it shrink?

So I should detect how many rows and columns of zeroes I have in edges of my canvas.

+2  A: 

Make the infinite canvas from tiles.

graham.reeds
Ok, how do I detect the blank tiles then?
Cheery
Say you have a 1024x768 image in 256x256 tiles. That's a 4x3 tile. They expand the image by 100 pixels in the y dimension. You've now got a 1024x868 image in 4x4 tiles. You keep track of the partially shown tiles (which allows the user up to another 156 pixels expansion before allocating more tiles). The user only sees what they've expanded to.
graham.reeds
A: 

Shrinking the canvas like you suggest would not be helpful to artists. Frequently they expand the area they're working just to have area to work with. There's also spritesheets which have blank area around the models that are required to work in the target program.

My suggestion is to grow as needed, but allow the artists to tweak the sizes manually when they wish to do it.

Andrei Krotkov
It's related to tileset drawing too, but right now concentrating to tilemaps. I am thinking otherwise, artists are also removing things, especially when they experiment. Considering to let users manually drop down portions of texture they don't want, or giving a huge texture and cutting it down only when the user is saving the layer.
Cheery
+1  A: 

One idea that comes to mind is to find how much to shrink in X and Y directions separately by the following method: Render a rectangular 'margin' of, say, half the size of the canvas and use ARB_ occlusion_query to find out if it's empty. If not empty, split in half and repeat (i.e. do a binary search to find the right size). This takes log(N) steps, where N is the size (width or height) of the canvas, so it's pretty quick, if done every now and then.

TrayMan
Occlusion queries and stencils are interesting. I think I will try your binary search method at one point.
Cheery