Tutorial 8 (blending)
I am currently attempting my own blending examples and I have come up on a problem. I can get the textures to come up fine with
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[ctr]->sizeX, TextureImage[ctr]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[ctr]->data);
but, when I change the GL_RGB to GL_RGBA to load the alpha I get a garbled texture.
Am I not loading the Image correctly? I cannot for the life of me figure this out.
I am trying to blend the green out of my texture, do you have to save the image somehow with the green labeled as the alpha and if so how do you do this?
The third parameter should be 4 as you are using the alpha channel. In fact, I'm pretty sure you should be using GL_RGB and GL_RGBA (for correctness) even though 3 and 4 are accepted.
--
Cheers,
Darren Clark
Cheers,
Darren Clark
Thanks for correction, but I still get the same results. It looks like a bad video card crash.
It might be because TextureImage[ctr]->data doesn't contain any alpha.
or you ignored the fact that you need to use it like this for it to work
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextureImage[ctr]->sizeX, TextureImage[ctr]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[ctr]->data);
or you ignored the fact that you need to use it like this for it to work
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextureImage[ctr]->sizeX, TextureImage[ctr]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[ctr]->data);
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
I think it is something about the data you pass as the last argument that are not in the correct format. Remember to add an exstra byte for each 3 bytes to store the alpha value.
And if i have understood it correctly you should pass GL_RGBA8 (not GL_RGBA or 4) as your 3rd argument (i am not totally sure about this).
And if i have understood it correctly you should pass GL_RGBA8 (not GL_RGBA or 4) as your 3rd argument (i am not totally sure about this).
Thanks for the replies guys. Tried everything you posted changed every value in the glTexImage2D() function that I could. It doesn't crash, it just looks like a bad video card crash still. I can move the image and everything, just doesn't look like it should.
Can you post your loading code, some screen shots, and the texture you are trying to load? I dont think your texture contains an alpha channel.
Why are you trying to do this? Why not remove the green from the texture before you load it?
Cheers,
- llvllatrix
Quote: I am trying to blend the green out of my texture, do you have to save the image somehow with the green labeled as the alpha and if so how do you do this?
Why are you trying to do this? Why not remove the green from the texture before you load it?
Cheers,
- llvllatrix
Quote: Original post by inmysights
Thanks for the replies guys. Tried everything you posted changed every value in the glTexImage2D() function that I could. It doesn't crash, it just looks like a bad video card crash still. I can move the image and everything, just doesn't look like it should.
Yes this is because your image data doesn't contain any alpha data, your data only contains red, green and blue values or 3 bytes per pixel, but openGl expects 4, so the color bytes will get offset for every pixel, thus resulting in what looks like a corrupt gfx memory.
to fix this you need to either load a image with the right amount of bytes per pixel, or add an extra byte per pixel, it's a bit complicated but it will work.
About screenshots
1. hit print screen while running the program.
2. paste the image in psp photoshop or paint, crop it acordingly and save it.
3. go to http://www.imageshack.us/ and upload the image there.
4. paste the image url into a post here, you can use an html image tag (don't use bbcode style tags -> [img])
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
ok here are the 2 images.
http://img142.imageshack.us/img142/7191/mario12pv.png correct one.
http://img234.imageshack.us/img234/9162/mario29ep.png what it lookes like after alpha turned on.
here is my code im using
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[6]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/Mario Stand Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[1]=LoadBMP("Data/Mario Stand Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[2]=LoadBMP("Data/Mario Run Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[3]=LoadBMP("Data/Mario Run Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[4]=LoadBMP("Data/Mario Crouch Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[5]=LoadBMP("Data/Mario Crouch Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
// Set The Status To TRUE
glGenTextures(6, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
for(int ctr = 0; ctr <= 5; ctr++)
{
glBindTexture(GL_TEXTURE_2D, texture[ctr]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextureImage[ctr]->sizeX, TextureImage[ctr]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[ctr]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
for(ctr = 0; ctr <= 5; ctr++)
{
if (TextureImage[ctr]) // If Texture Exists
{
if (TextureImage[ctr]->data) // If Texture Image Exists
{
free(TextureImage[ctr]->data); // Free The Texture Image Memory
}
free(TextureImage[ctr]); // Free The Image Structure
}
}
return Status; // Return The Status
}
Thank you
http://img142.imageshack.us/img142/7191/mario12pv.png correct one.
http://img234.imageshack.us/img234/9162/mario29ep.png what it lookes like after alpha turned on.
here is my code im using
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[6]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/Mario Stand Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[1]=LoadBMP("Data/Mario Stand Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[2]=LoadBMP("Data/Mario Run Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[3]=LoadBMP("Data/Mario Run Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[4]=LoadBMP("Data/Mario Crouch Left.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
if (TextureImage[5]=LoadBMP("Data/Mario Crouch Right.bmp"))
{
Status=TRUE; // Set The Status To TRUE
}
// Set The Status To TRUE
glGenTextures(6, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
for(int ctr = 0; ctr <= 5; ctr++)
{
glBindTexture(GL_TEXTURE_2D, texture[ctr]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextureImage[ctr]->sizeX, TextureImage[ctr]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[ctr]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
for(ctr = 0; ctr <= 5; ctr++)
{
if (TextureImage[ctr]) // If Texture Exists
{
if (TextureImage[ctr]->data) // If Texture Image Exists
{
free(TextureImage[ctr]->data); // Free The Texture Image Memory
}
free(TextureImage[ctr]); // Free The Image Structure
}
}
return Status; // Return The Status
}
Thank you
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement