Textures & Tiles in OGL

Member
Posts: 196
Joined: 2002.04
Post: #1
Hi,
I'm making tile based maps in OpenGL. I was wondering what the best and fastest way to make a tile would be. Right now I'm using this method:
Code:
for(i = 0; i < MAX_TILES; i++) {
glTranslate(xTiles[i], yTiles[i], 0.0);

                glBegin(GL_QUADS);
                    // Quads CCW
                    glVertex3f(-5.0, 5.0, 0.0);
                    glVertex3f(-5.0,-5.0, 0.0);
        
                    glVertex3f( 5.0,-5.0, 0.0);
                    glVertex3f( 5.0, 5.0, 0.0);
                glEnd();
}
For some reason this seems really slow when I've got 50 or more tiles loaded at one time. Is it possible to use glVertex3fv() and is it any faster?

Also my textures seem to flash. Is this because I'm not using mipmaping? Do I need to make my tiles 128 x 128 units
for a 128 x 128 pixel picture to avoid using mipmapping?

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 157
Joined: 2002.12
Post: #2
texturing is done automatically for you no matter what size your tiles are.

mipmapping creates duplicate textures from the original image you provide, and then uses the most appropriate one based on how close the pixels are to view.

usually flashes are caused by bad vertex data either in texture or vertex coords or maybe a bad pointer.

if you are using glLoadMatrixf() there may be something wrong in the matrix specified.

also make sure you enable texture2D.

hope it helps.
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #3
Quote:Originally posted by NYGhost

usually flashes are caused by bad vertex data either in texture or vertex coords or maybe a bad pointer.


I'm using different glColor(); schemes to shade it so it must be something to do with the vertex coordinates.

Thanks so much,
Iceman
Quote this message in a reply
Mars_999
Unregistered
 
Post: #4
Why are you translating each loop iteration? You should really try this instead

Code:
for(int y = 0; y < MAP_Y; y++)
{
for(int x = 0; x < MAP_X; x++)
{
tile = map[y][x];
glBindTexture(GL_TEXTURE_2D, texture[tile]);
glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(shift_x, shift_y, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f((shift_x + texture_x), shift_y, 0.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f((shift_x + texture_x), (shift_y + texture_y), 0.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(shift_x, (shift_y + texture_y), 0.0f);
    glEnd();
    shift_x += texture_x;
}

                shift_y += texture_y;
    shift_x = 0.0f;
}

This is code I have used in Orotho view but can be changed easily for Perspective views. HTH
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #5
Quote:Originally posted by Mars_999

Code:
tile = map[y][x];
glBindTexture(GL_TEXTURE_2D, texture[tile]);
}

Very cool I'll have to try that with the textures. Is there much of a performance boost to just use one texture and leave the glBindTexture(GL_TEXTURE_2D, texture[tile]); out of the "for" loop?

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 157
Joined: 2002.12
Post: #6
Quote:Is there much of a performance boost to just use one texture and leave the glBindTexture(GL_TEXTURE_2D, texture[tile]);


If you are using a single texture you can call it outside the loop.

performance hit is minimal when you call glBindTexture()
but it depends on how many tiles you have.
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #7
Make sure you do some clipping if you have a map that goes beyond the boundaries of the screen. In other words don't draw tiles that won't end up on the screen.

If you are just doing a still background (non-scrolling) this isn't a problem. Wink

Aaron

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #8
Yeah I learned tile clipping the hard way. Although, my game probably won't use too much of it since I want the camera views to be flexible.

Thanks,
Iceman
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #9
"my game probably won't use too much of it since I want the camera views to be flexible."

???

I would think you need to clip off tiles all the time then!

If you are looking at a small part of your map, you want to only draw the tiles that will be visible. Therefore, you need to clip all the other ones out of the drawing loop.

Maybe we're just not using the terms the same way. I just wanted to be clear. Blush

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Mars_999
Unregistered
 
Post: #10
I have to admit I don't do any clipping yet on my engines. I should but GOD it's awesome to look out over a terrain engine that has 524,000 polygons being rendered! And I would like my user to be able to see the battles in the distance taking place. e.g. explosions or gun fire! WooohooWow But in reality todays hardware is still not powerful enough to do this. Ugh. I have a PC (HEY I know waiting on a G5 next year) anyway the PC I have is a 2600+ XP with a 9700Pro 128MB card with 1GB or RAM. When rendering only 524,000 polygons and no models yet I am only getting 60fps. No AI, physics, sound, ect... And the sad part is this PCee is powerful by todays standards. I would not like to see this run on my old Mac! Now a G5 I would love to try that. I am sick of cutting corners programming using fog, clipping to save CPU/GPU cycles. Games are so alike due to this. I would like to have a larger world where more is seen and not less. But thats me. Anyway just a rant! Sorry!
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #11
Quote:Originally posted by aaronsullivan
I would think you need to clip off tiles all the time then!

If you are looking at a small part of your map, you want to only draw the tiles that will be visible. Therefore, you need to clip all the other ones out of the drawing loop.

When I said flexible I meant I can zoom in and out and be lazy at the same timeWink. Also I want the user to be able to see stuff going on a long distance away like Mars talked about. My game is still in the beginning stages, so I'm not sure exactly how much clipping/zooming I'll use.

Thanks,
Iceman
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Tiles/Sprites question Bonked 0 2,092 Dec 16, 2006 06:06 AM
Last Post: Bonked
  Using OpenGL for tiles Taxxodium 6 3,726 Mar 25, 2005 10:06 AM
Last Post: tigakub
  SDL and transparancy in tiles Taxxodium 1 2,471 Oct 7, 2003 11:44 PM
Last Post: sealfin
  Using OpenGL to make windows, tiles, etc. LongJumper 6 3,283 Oct 7, 2003 09:41 AM
Last Post: inio
  Implementation of 2D Tiles using OpenGL aaronsullivan 18 12,533 Jun 14, 2003 05:41 PM
Last Post: OneSadCookie