Advertisement

see through texture?

Started by October 30, 2002 10:30 PM
8 comments, last by robsonde 22 years, 3 months ago
how can I make a texture that is mostly see through? I have a 32bit TGA with the image setup with the alpha chanel and such like but how do I get that in to OpenGL? BTW I am using the TGA loading code from NeHe tut 25 [edited by - robsonde on October 30, 2002 11:44:06 PM]
Try lesson 32. You are probably looking for alpha blending.

And dont forget, when you are using alpha, use glDepthMask(GL_FALSE) (i think that is the command). Basically what it does is makes the depth buffer read only so that your poly will get drawn if it''s closer that what is in there and will get blended into the back since it doesn''t overwrite whats already there. To go back to regular rendering use glDepthMask(GL_TRUE). IF you are still confused try the opengl red book - its online and free.

if you feel like alpha is a big waste of time check out my demo:

members.rogers.com/ramrajb/Downloads/IslandDemo.zip

It should change your mind (Be warned it does require quite a bit of memory and processing speed, sorry . If anything with the demo screws up email me: thereisnocowlevel@hotmail.com )
Advertisement
lol. you''re telling how to avoid depth artefacts with translucent textures, but your demo does have problems with leaves which are represented as translucent textures !
still having problems.....

I am loading a 32bpp TGA and making a texture the normal way.

when I run my code the texture that sound be a blue blob that is see through around the edge has black where i want to be able to see the poly that to behind it.

BTW:
I am rendering the alpha texture last.
my TGA is not the problem because i tested it with the TGA "explode" from lesson 32 and that did the same. (nice smoke on black not see through)


my GL_Setup code is:

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
float fogColor[4] = {0.0, 0.0, 0.0, 1.0f};
glFogi(GL_FOG_MODE, GL_EXP2);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, 0.025f);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glFogf(GL_FOG_START, 0);
glFogf(GL_FOG_END, 250.0f);
glEnable(GL_FOG);



thanks for the help




quote:

lol. you''re telling how to avoid depth artefacts with translucent textures, but your demo does have problems with leaves which are represented as translucent textures !



trust me it looks better like that. If i made the depth buffer read only when i render the leaves it produces so much clutter. If you took the time (and i have no idea why you would but hay...) to overlay the texture mask onto the leaf texture you would see that there is a whole bunch of white around the leaf. I got lazy and didnt want to edit it out so i did glDepthMask(GL_TRUE) and it reduces the problem. It really sucks when i did glDepthMask(GL_FALSE) (gotta luv my english), it looks like light is emitting from the palm tree.

Anyway, im aware of the irony.

Got to love the fake shadows produced by the alpha masks though.
well I still cant get this to work.....


where I want the texture to be see through it is black.

any help would be nice

Advertisement
||v||atrix: maybe you should try calling glAlphaFunc(GL_EQUAL, 1.0f) instead. [edit]And enable alpha testing using glEnable(GL_ALPHA_TEST)[/edit]

robsonde: The piece of code seems right. Could you post a (web) link for your picture please ?
Also, could you post the code snippet where you're initializing you texture ( calls to glTexImage, to glTexParameter, glTexEnv and everything glTex* in general ) ?

[edited by - vincoof on November 4, 2002 4:26:24 AM]
code for loading textures looks like:





int LoadGLTextures() {
int Status=FALSE;
if (LoadTGA(&textures[0], "Data/t00.tga") &&
LoadTGA(&textures[1], "Data/t01.tga") &&
LoadTGA(&textures[2], "Data/t02.tga") &&
LoadTGA(&textures[3], "Data/t03.tga") &&
LoadTGA(&textures[4], "Data/t04.tga") &&
LoadTGA(&textures[5], "Data/t05.tga") )
{Status=TRUE;
for (int loop=0; loop<=5; loop++) {
if (filter==0)
{glGenTextures(1, &textures[loop].texID);
glBindTexture(GL_TEXTURE_2D, textures[loop].texID);
glTexParameteriGL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textures[loop].width, textures[loop].height, 0, GL_RGB, GL_UNSIGNED_BYTE, textures[loop].imageData); }

if (filter==1)
{glGenTextures(1, &textures[loop].texID);
glBindTexture(GL_TEXTURE_2D, textures[loop].texID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, textures[loop].width, textures[loop].height, 0, textures[loop].type, GL_UNSIGNED_BYTE, textures[loop].imageData); }

if (filter==2)
{glGenTextures(1, &textures[loop].texID);
glBindTexture(GL_TEXTURE_2D, textures[loop].texID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, textures[loop].width, textures[loop].height, GL_RGB, GL_UNSIGNED_BYTE, textures[loop].imageData); }


if (textures[loop].imageData) {
free(textures[loop].imageData); }
}
}
return Status; }







the texture is the "explode.tga" from NeHe lession 32.

I have will use my own texture in the final version but I am using explode.tga because I know the alpha is setup right.











[edited by - robsonde on November 4, 2002 7:17:29 PM]
When you call :

glTexImage2D(GL_TEXTURE_2D, 0, 3, textures[loop].width, textures[loop].height, 0,
textures[loop].type, GL_UNSIGNED_BYTE, textures[loop].imageData);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, textures[loop].width, textures[loop].height, GL_RGB,
GL_UNSIGNED_BYTE, textures[loop].imageData);

the argument "3" represents GL_RGB. That is, you''re not loading the alpha channel into the GL. Is that what you want ?
You should try with "4" or "GL_RGBA" instead, at least for textures who have an alpha channel.
that make sence...

and it works!!



thanks lots

This topic is closed to new replies.

Advertisement