Sign in to follow this  

Texturing A Quad

This topic is 3866 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
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[i];
p->data[i] = 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

This topic is 3866 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this