Tilemap to texture?

I need to create a tile map, but I have to avoid rendering one quad per tile.

What I need is to (once only) buffer the tiles onto a texture, and then in turn render this ONE texture to one quad. As opposed to rendering one quad for each tile, wasting polygons.

What is the best/easiest way to buffer several textures(tiles) into one new texture. I need to be able to specify coordinates and everything for the tiles before rendering them onto a texture.

The question is simple:
How do I render several small textures/tlies onto a bigger texture(-buffer) for later use.

I think glTexSubImage2D would be what you need.

I tried it once, but got a “missing extension”? Does anyone have a working example or tutorial utilizing the gltexsubimage2D ? It would help me a great deal!

Just wondering why you “have to avoid rendering one quad per tile”?

If drawing a few hundred quads on screen is causing major slowdowns for your tile engine then you have much bigger problems.

The batches you should be creating are making sure you draw all tiles with the same texture before switching textures and drawing the next batch of tiles. You could even get fancy and have multiple tile textures in a larger texture to avoid even more texture switching.

I agree with bjgil2, you should just organize your drawing such that you minimize texture switching, it sounds like you are making things a little more difficult than you need to. And your not wasting polygons, even the basic 3D cards can handle oodles of them per second.

However, if you wish to continue rendering to one big texture, I would suggest using the bitmap form of your textures, use Java2D to combine them into one bitmap, then turn your new combined image into a texture.

or…

This tutorial utilizes glTexSubImage2D, but is far from the main point and it is in c++, but should still be understandable.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=35

Also be sure to look up the opengl documentation for glTexSubImage2D. (google it)

If i anderstand ur question correctly,

u should write a small texture 4 quads and bind it to a big polygon setting the texture to wrap (GL_WRAP) on S and T.

to control the size of the quads of the texture u need to make it prop. to the object drawn it self this can be easily done by projecting using a simple ratio function.

So, I have made my tilemap-class, and the code for rendering looks like this:


    public void paintMap(GL gl)
    {
        // loop through all the tiles in the map rendering them
        for (int y = 0; y < HEIGHT; y++)
        {
            for (int x = 0; x < WIDTH; x++)
            {

                int yoffset = HEIGHT*TILE_SIZE;
                
                Vector3D tilePos = new Vector3D(player.pos.x - x * TILE_SIZE,player.pos.y + y * TILE_SIZE,0);
                if (!((Math.abs(tilePos.x) < 420)) || !((Math.abs(-yoffset+tilePos.y) < 300)))
                    continue;
                
                gl.glColor4d(1 , 1 , 1, 1);
                //TODO FIX: 16 SKAL VÆRE DYNAMISK FUNDET...... 
                int tileCol = midlayer[y][x] / 16; 
                int tileRow = midlayer[y][x] - (16 * tileCol);
                
                gl.glPushMatrix();
                gl.glTranslated(0,yoffset ,0);
                gl.glTranslated(x * TILE_SIZE, -y * TILE_SIZE, 0);
                spriteBuffer.drawFrame(gl, tileCol, tileRow);
                gl.glPopMatrix();

            }
        }
//        System.out.println("Passes calculated: "+passesCalc+"\nPasses not calculated: "+passesNotCalc);
    }

I profiled it (in netbeans) and I saw that the main problem is in the spriteBuffer.drawFrame(), which kinda sucks. I have one texture file containing all the tiles, and they are saved into separate displaylists in opengl. All rendered to squares. I only render the ones that fit in the screen, so nothing more than like 30x30 or whatever.

Does it matter that I change from one displaylist to another? Is there anything else I can do to upgrade the performance of this code?

I might have to repeat this, it is not a CPU problem, its a GPU problem. The cpu is around 30% with my game at this point. And yes I have a quite lowend graphics card, intel graphics 945GM.