
Simple OpenGL Texture Mapping question
This is probably a very simple question to answer, but I''ve been strugling over it for hours now. I am trying to make a simple 2D maze game and I''ve succesfully created it using plain colors (e.g. glColor3f(1.0f,1.0f,1.0f)
. Now I''m trying to use textures instead of plain color squares and I''ve been strugling with this for hours. This is what I have for the drawing part of my code. I hope someone can help me with this.
for (loop1=0; loop1<10; loop1++)
{
for (loop2=0; loop2<10; loop2++)
{
if ( field[loop1][loop2] == 0)
{
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2d(17+(loop1*60),73+(loop2*40
glTexCoord2d(60, 0);
glVertex2d(80+(loop1*60),73+(loop2*40));
glTexCoord2d(60, 40);
glVertex2d(80+(loop1*60),115+(loop2*40));
glTexCoord2d(0, 40);
glVertex2d(17+(loop1*60),115+(loop2*40));
glEnd();
}
if ( field[loop1][loop2] == 1)
{
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex2d(17+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),115+(loop2*40));
glVertex2d(17+(loop1*60),115+(loop2*40));
glEnd();
}
if ( field[loop1][loop2] == 2)
{
glColor3f(0.5f,0.5f,0.5f);
glBegin(GL_QUADS);
glVertex2d(17+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),115+(loop2*40));
glVertex2d(17+(loop1*60),115+(loop2*40));
glEnd();
}
if ( field[loop1][loop2] == 3)
{
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex2d(17+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),73+(loop2*40));
glVertex2d(80+(loop1*60),115+(loop2*40));
glVertex2d(17+(loop1*60),115+(loop2*40));
glEnd();
}
}
}
This whole thing might seem weird, so I''ll try to explain what I was doing. There are four types of squares on the field. 0 is the walking path, 1 is a wall or boundry, 2 is the entrance, and 3 is the exit. Each different square on the 10x10 field has a different value (0,1,2, or 3) and each value has it''s own color. What I was trying to do was replace the color on squares with a value of 1 with a texture. I''ve taken some base code from NeHe, so I know I have all of the file opening and setting it as a texture parts right. If you need to see them in order to help me, just ask and I''ll post that too. I would think that what I have should work, but It doesnt. It makes no change at all. The texture wont show up. It''s just the basic colored squares.
Well thanks for any help you can give me. I appreciate it a lot.
-Alexis

have you enabled texturing? (glEnable(GL_TEXTURE_2D) ?)
| - Project-X - my mega project.. close...
- | - adDeath - | - email me - |
| - Project-X - my mega project.. close...

Yes, I have. There is no change. If you would like to see the whole program, I could post a link to what I have so far.
Alex,
I had a similar problem, I was loading a TGA like you and it didn''t showed up correctly no matter what I''ve tried...
So I discovered a thing...my texture was 220x97 pixels wide and only when I transformed it to 256x256 or similar (128x128, 64x64, etc...) I could finally load it!
I think it''s worth a look at texture size...
I had a similar problem, I was loading a TGA like you and it didn''t showed up correctly no matter what I''ve tried...
So I discovered a thing...my texture was 220x97 pixels wide and only when I transformed it to 256x256 or similar (128x128, 64x64, etc...) I could finally load it!
I think it''s worth a look at texture size...
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
Holy mother of! Bruce, I can''t thank you enough. I spent almost a full 24 hours on that. To think it was as simple as changing the size of the picture. THANK YOU SO MUCH!
You''re welcome man!
Btw, does anyone knows how do I use a texture with an arbitrary width and height??? Like 220w / 97h ??? Or it cannot be done in OGL???
Btw, does anyone knows how do I use a texture with an arbitrary width and height??? Like 220w / 97h ??? Or it cannot be done in OGL???
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
it has already been discussed many many times.
- You can either scale the picture to fit to its nearest power-of-two size, which may distort the picture unfortunately,
- or you can allocate a texture that is bigger than your picture (for your 220x97 image you would allocate a 256x128 texture) and fill a subimage of that texture thanks to glTexSubImage2D (before that, you NEED to allocate the necessary memory with glTexImage2D with the ''pixels'' argument set to NULL). This last method does not distort the texture but forbids texture repetition,
- and you can also use texture rectangles, which are less flexible than traditional textures, and supported by less vendors/drivers, but are not restricted at all to the power-of-two "sizeness" of the image.
in any case, the best bet being : if you are the one who generated your images (with a picture software for instance) you may have created the image with an appropriate size, knowing that a 3D application would use it.
for more information, search the forums, google it, etc
this has really been discussed alot.
- You can either scale the picture to fit to its nearest power-of-two size, which may distort the picture unfortunately,
- or you can allocate a texture that is bigger than your picture (for your 220x97 image you would allocate a 256x128 texture) and fill a subimage of that texture thanks to glTexSubImage2D (before that, you NEED to allocate the necessary memory with glTexImage2D with the ''pixels'' argument set to NULL). This last method does not distort the texture but forbids texture repetition,
- and you can also use texture rectangles, which are less flexible than traditional textures, and supported by less vendors/drivers, but are not restricted at all to the power-of-two "sizeness" of the image.
in any case, the best bet being : if you are the one who generated your images (with a picture software for instance) you may have created the image with an appropriate size, knowing that a 3D application would use it.
for more information, search the forums, google it, etc
this has really been discussed alot.
Hi, nehes iPicture-Code does all this for you.
You can load every combination of width and height because it does everything voncoof sais.
What I've seen about iPicture was very easy to implement.
Dark
McNugget next time...
[edited by - DarkKiller on April 30, 2003 5:30:02 AM]
You can load every combination of width and height because it does everything voncoof sais.
What I've seen about iPicture was very easy to implement.
Dark
McNugget next time...

[edited by - DarkKiller on April 30, 2003 5:30:02 AM]
DarkMcNugget next time... ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement