pokkelipoo
04-07-2004, 04:56 AM
I'm doing a small 2D-game which constantly displays 64*45 number of tiles. Re-drawing those 2880 tiles every frame is too slow. The good thing is that about 95% of the tiles are static and do not need to updated every frame. So I basically want to render only the tiles that need to be rendered (the ones that are changed).
I tried to create an empty texture buffer of the size of my level and use glCopyTexSubImage2D() every time a tile needs to be rendered, but for some reason it didn't work and just displayed a blank, white texture. I doing it somehow like this:
for each tile in level
{
if tile needs to be rendered
{
bind "gameimages" texture
render tile as textured quad
bind "buffer" texture
GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, tile.x, tile.y, tile.x, tile.y, TILE_WIDTH, TILE_HEIGHT);
}
}
finally render the "buffer" textureThe most annoying thing in this method, is that I have to bind the "gameimages" texture for every tile again and again.
Am I doing something totally wrong?
What do you think about this method generally?
Could someone show a quick example code how I should do this. Any better ideas than using an extra buffer for this?
btw. Is it a good idea to generally have glClear() at the beginning of (lowest level) render()-method?
Thanks.
I tried to create an empty texture buffer of the size of my level and use glCopyTexSubImage2D() every time a tile needs to be rendered, but for some reason it didn't work and just displayed a blank, white texture. I doing it somehow like this:
for each tile in level
{
if tile needs to be rendered
{
bind "gameimages" texture
render tile as textured quad
bind "buffer" texture
GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, tile.x, tile.y, tile.x, tile.y, TILE_WIDTH, TILE_HEIGHT);
}
}
finally render the "buffer" textureThe most annoying thing in this method, is that I have to bind the "gameimages" texture for every tile again and again.
Am I doing something totally wrong?
What do you think about this method generally?
Could someone show a quick example code how I should do this. Any better ideas than using an extra buffer for this?
btw. Is it a good idea to generally have glClear() at the beginning of (lowest level) render()-method?
Thanks.