PDA

View Full Version : Displaying a transparent .tga texture



dvm
05-24-2004, 12:28 AM
Hi to everyone! My latest problem is this:
I've made a texture in gimp that includes transparency in some areas. Looking at the file properties (I'm using win2k) it reports a color depth of 96 bits. What are the proper settings for
glTexImage2D so I can display my texture properly? Before I added the transparency it displayed ok. After adding it the program loads ok, but no texture shows. My current try with the function is:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_tgaFile[0]->imageWidth,
g_tgaFile[0]->imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, g_tgaFile[0]->imageData);but nothing shows (except my untextured quad ofcourse)

mikael_aronsson
05-24-2004, 02:19 AM
Hi !

This depends on how you load the image into ram ?, OpenGL itself has no support for image loading so you must have some code yourself that takes care of that, and it all depends on how that code saves the loaded image in memory, if it is 4 pytes per pixel (red, green, blue and alpha value) your example should work, if not.... so it all depends on how the image is loaded into ram.

Mikael

dvm
05-24-2004, 05:03 AM
I've managed to load the .tga file created from gimp. In gimp the white area looks transparent but not in my program. You can see a screenshot here.
http://venus.cs.teiher.gr/~dvm/img.jpg
I just don't want the white border around the finger to show. That's all! I've tried various combinations of blending and alpha testing but none of them worked.
Also just checked the size of the image that is read from fread and gives a number that is a the result of 128x256x4 (128x256 is the size of the texture). So I must be reading in the alpha component correctly.

ZbuffeR
05-24-2004, 11:40 AM
Enable blending, use blending function GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA and it should be okay if alpha is set properly.

dvm
05-25-2004, 02:11 AM
Almost there. I've gotten rid of the border but now the image color is all black. This is what I mean:
http://venus.cs.teiher.gr/~dvm/finger.jpg

This is how the image looks in photoshop cs:
http://venus.cs.teiher.gr/~dvm/photo.jpg

and this is my source code from the init function:

glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
g_tgaFile = new TGAFILE;
LoadTGAFile("pp.tga", g_tgaFile);
glGenTextures(1, &texture); // generate texture object
glBindTexture(GL_TEXTURE_2D, texture); // enable our texture object
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_tgaFile->imageWidth,
g_tgaFile->imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, g_tgaFile->imageData);and in my display function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glColor3f(0.0, 1.0, 0.5);
glRecti(-560, -450, -200, -300);

glColor3f(0.0, 0.0, 0.0);
glRecti(200, 0, 400, 100);

glTranslatef(0.0, 0.0, 1.0);

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex2f(g_fFingerX, g_fFingerY);
glTexCoord2f(0.0, 0.0); glVertex2f(g_fFingerX, g_fFingerY - g_fFingerSize);
glTexCoord2f(1.0, 0.0); glVertex2f(g_fFingerX + (g_fFingerSize * 2.0 / 4.0), g_fFingerY - g_fFingerSize);
glTexCoord2f(1.0, 1.0); glVertex2f(g_fFingerX + (g_fFingerSize * 2.0 / 4.0), g_fFingerY);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);

glutSwapBuffers();
glutPostRedisplay();Any ideas? I'm out of luck.

ZbuffeR
05-25-2004, 03:05 AM
You can change texenv (see doc for glTexEnv):
http://pyopengl.sourceforge.net/documentation/manual/glTexEnv.3G.xml
"GL_TEXTURE_ENV_MODE defaults to GL_MODULATE and GL_TEXTURE_ENV_COLOR defaults to (0, 0, 0, 0)."

Modulate multiplies the vertex defined color and lighting by the texture. Replace only take the texture in account. If you don't need lighting, it is the preferred choice.

Have fun !

dvm
05-25-2004, 03:25 AM
I really didn't get the last post. But my problem now is that the texture is not loading. I mean the code that actually loads the file is ok. I can see the proper dimensions and color depth (using watches) but the texture is just not showing!! It can read the alpha information obviously as you can see in the last post but the image is just not showing. I'm about to go beserk!

dvm
05-25-2004, 03:39 AM
I've finally found the problem! Because the color state before drawing the textured quad was black (0.0, 0.0, 0.0) it probably multiplied the texture as well and turned it to black (through the blending function). By changing the color to white (or any other bright color I think) I finally got the result I wanted! Wow this thing pissed me off for almost 2 days. Thanks to everyone for their help!