Jump to content
  • Advertisement
Sign in to follow this  
Hacksaw2201

Texturing A Quad

This topic is 4081 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

I keep seeing everywhere that it's easy. Well it's not. Can anyone help out here? The object "file" does load a valid uncompressed tga texture. I get a nice white square on my screen as well. glEnable (GL_TEXTURE_2D); glBindTexture (GL_TEXTURE_2D, 0); glTexImage2D (GL_TEXTURE_2D, 0, file->type, file->width, file->height, 0, file->type, GL_UNSIGNED_BYTE, file->imageData); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); */ float color[4]; color[0] = 1.0f; color[1] = 1.0f; color[2] = 1.0f; color[3] = 0.0f; glBegin (GL_QUADS); glColor4fv(color); glTexCoord2f (0.0f,0.0f); glVertex3f (-256.0f, -256.0f, -1024.0f); glColor4fv(color); glTexCoord2f (0.0f, 1.0f); glVertex3f (-256.0f, 256.0f, -1024.0f); glColor4fv(color); glTexCoord2f (1.0f, 1.0f); glVertex3f (256.0f, 256.0f, -1024.0f); glColor4fv(color); glTexCoord2f (1.0f, 0.0f); glVertex3f (256.0f, -256.0f, -1024.0f); glEnd (); glDisable (GL_TEXTURE_2D);

Share this post


Link to post
Share on other sites
Advertisement
Maybe you're missing your glGenTextures call, could you show a bit more code?
Also, on
glBindTexture (GL_TEXTURE_2D, 0);
I think your second parameter should be your texture object, not zero.

Share this post


Link to post
Share on other sites
Got it!!!

glTexImage2D (GL_TEXTURE_2D, 0, file->type, file->width, file->height, 0, GL_RGB, GL_UNSIGNED_BYTE, file->imageData);

needed the GL_RGB as well.

Thanks for the tip.

Share this post


Link to post
Share on other sites
Well sort of got it. My TGA loaded in all greyscale so I did a little code tinkering. I understand that (for some increadibly odd reason) the BGR needs flipped to RGB. ( Can someone please tell me who engineered that one?!?!)

In any event, my TGA now comes out on my quad but purpleish. Doesn't matter what I do with the code. It's either blueish or purpleish. I've looked over dozens of tutorials that all do the same basic thing with the pixel byte flipping and all have the same result. Can anyone offer any ideas for this please?

Here's a pixel flip routine that I snagged out of a tutorial off NeHe.

void tgaGetImageData ( image_t *p, FILE *file )
{
unsigned char temp;

p->data = tgaAllocMem ( p->info );

/* Easy unRLE image */
if ( p->info.image_type == 1 || p->info.image_type == 2 || p->info.image_type == 3 )
{
fread ( p->data, sizeof (unsigned char), p->info.bytes, file );

/* Image is stored as BGR(A), make it RGB(A) */
for (int i = 0; i < p->info.bytes; i += p->info.components )
{
temp = p->data;
p->data = p->data[i+2];
p->data[i+2] = temp;
}
}

/* RLE compressed image */
if ( p->info.image_type == 9 || p->info.image_type == 10 )
tgaGetPackets ( p, file );
}

Share this post


Link to post
Share on other sites
Nevermind, it works fine with a texture that I used from another source other than one created with my photo/texture software. Hmm wonder what I spent the $80 for.

Share this post


Link to post
Share on other sites
I don't think my brain is cut out for this stuff anymore.

Yesterday using a compressed texture didn't work and now today it does.

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!