Apologies if this is a somewhat idiotic question, I'm still somewhat new to OpenGL programming. In fact, I'm not even sure if this is the right forum or if it should have been posted in Beginners!
Firstly, some background.
I currently have a basic 2D tiling engine which uses OpenGL via the OpenTK bindings. For drawing textures, the engine is currently using the somewhat obsolete vertex arrays rather than VBO's (one challenge at a time!)
Each map is a simple 2D array of tiles. I define a field size which is the visible viewport on the screen, and set up an array of vertexes which describe each tile position in the viewport. This is defined once. There is also an origin, which is simply the top/left co-ordinate of the map in relation to the player.
Then, each update, the engine cycles through the visible tiles in the current map and updates the vertex array with texture coordinates from a tile sheet texture. If the player moves and the origin changes, this is naturally handled as part of the cycle through visible tiles. It's a very simple system
So far so good.
However, the disadvantage is that it "scrolls" in full tiles. So if the character charges from one side of the screen to the other, it will jump along one block at a time.
What I wanted to do was implement a form a smooth scrolling, so that instead of jumping the entire width of a tile, it will jump a smaller increment until it has reached the desired end position.
I tried implementing smooth scrolling in a test project some months ago, and while it worked, it had one nasty drawback - on one side of the scroll you'd have a gap as technically the subsquent column wasn't visible so it wouldn't be drawn. And on the other side of the scroll you'd have an excess because it was trying to draw the last column beyond the boundaries of the view port. So assuming you had UI elements, they could be overwritten.
If I was using GDI, then I might just set a clip region and then just draw the visible tiles +/- 1 column/row and everything would be displayed without overwriting any element. Of course, that would mean extra rendering being done for no purpose which is a bit daft.
Not really sure I'm explaining this terribly well, so here's a couple of images to partially demonstrate:
In the second screen shot, the player has moved one tile to the right. As the engine currently tries to keep the player character centred in the map, it automatically scrolls it along one tile. Which is fine, as the end result - but I want to smoothly bump it along instead of it just jumping.
This third image demonstrates a test program I did which tried smoothly scrolling the background from right to left and also scrolling the water from left to right. The jagged edges at the top and bottom show how my rendering is currently flawed.
So, my questions would be:
Firstly, does OpenGL support anything like GDI's clip regions so I could draw extra tiles without them going beyond what I define as a view port. [The lazy approach I suppose]
-or-
Should I recalculate the first/last column/row and draw only the visible portion of the texture [The hurt-your-brain-with-maths approach]
-or-
Is there another technique that other developers use that I haven't thought of?
Again, apologies if this is a really dumb question, but thanks in advance for any advice that could be offered.
Regards;
Richard Moss






