Jump to content
  • Advertisement
Sign in to follow this  
Twinsen2

Adding more textures to tile engine +OpenGL

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all. Hey first but not last post here, i have recently started a Bachelor of Interactive entertainment majoring in games programing at QANTM College, right now at school we are learning c++ and stuff and i was wanting to get ahead, by starting 3d. Umm. i was wondering how i can possibly add a third texture to my tile game. i have an char array: char map[10][10] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; I am trying to place another texture in the middle, so i change it to char map[10][10] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 2, 2, 0, 0, 0, 1}, {1, 0, 0, 0, 2, 2, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; 1= grass "walakble Area" 2= walls "Barrier" 3= Water"Barrier" 3 is the number where the texture is stored in memory. I tried to change the id of those tiles as follows: map[4][5] = 3; map[4][4] = 3; map[5][4] = 3; map[5][5] = 3; but it comes up white, because i'm not 2 sure how to change them. heres the texture and draw loop: for (int y = 0; y < MAP_SIZEY; y++) { for (int x = 0; x < MAP_SIZEX; x++) { tile = map[y][x]; glBindTexture(GL_TEXTURE_2D, texture[tile]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x), float(y), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x + 1), float(y), 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x + 1), float(y + 1), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x), float(y + 1), 0.0f); glEnd(); } } LOL, i really am stuck been at it 4 ages. I think the problem is that the array only allows 1 and 0, and when i assign two, to some of the values it doesnt like it, so i manually assign the tiles a new id and try and bind a texture to them [Edited by - Twinsen2 on July 26, 2005 6:26:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
ok, you didn't make it extremely clear in your post, so here goes a wild stab in the old dark.

First, lets try and gain some knowledge on the whole application here (Because I see nothing wrong so far)
You have an integer array (like int texture[12] or something) that you are loading the textures (Tiles in this case) into (Be it from sub-dividing a huge texture into smaller tiles or just loading singular images as tiles. Doesn't matter either way).
Next you have your map which is a 2 dimensional array. Your code works for going through the different entries in the array, i know that.

The problem you are experiencing is white quads which generally means that you are binding jack to that quad. I'm not sure what you mean by assigning those different values
Quote:

1= grass "walakble Area"
2= walls "Barrier"
3= Water"Barrier"


but I assume that according to your map format you are calling an address in an array so when it says one, you are binding texture[1]. The only problem that I can see is that you are calling texture[3] which will contain no data since arrays start at texture[0]. So instead if you bound texture[2] to the quad it should work.
I'm not really sure what you are doing with the said 1= walkable area ... but in theory if you are following normal arrays it should be:
map[4][5] = 2;
map[4][4] = 2;
map[5][4] = 2;
map[5][5] = 2;

Like you had in the map format.

muh, I'm a bit confused by the way you have stated your problem but it should be easy to fix.

Share this post


Link to post
Share on other sites
First of all thank you very much for the reply.
Umm i just figured out what the problem was.
Dam i'm stupid....lol.

The problem was when i copied the texture loading code to load the code for the water, i forgot to change 1 value, i had it set up so that it does load the water tile, but the barrier tile overrides the memory value, and as result displays the wrong picture.

Here was the problem:
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX,
TextureImage[1]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[1]->data);
"GL_UNSIGNED_BYTE, TextureImage[1]->data);" note the 1

glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX,
TextureImage[1]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[1]->data);
"GL_UNSIGNED_BYTE, TextureImage[1]->data);" I had this set to 1 aswell
i changed it to 2 and was really glad to see it working.
LOL, i learnt my mistake, just because you copy working code to reuse it, always go through and read it!!!!lol

Thankz once again for ur help.

hmmzzz now i need to place a charcter or a block in there that moves around the tiles...........this is gonna be the hard bit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!