Texturing A Quad
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);
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.
Also, on
glBindTexture (GL_TEXTURE_2D, 0);
I think your second parameter should be your texture object, not zero.
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.
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.
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 );
}
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 );
}
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement