Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Transparent Texture Effect

  1. #1
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Transparent Texture Effect

    the structure is of a openGL book. the book is bad and i don't believe that the transparent texture structure is good.

    glBlendFunc(GL_DST_COLOR, GL_ZERO);
    glBindTexture(..., mask);
    drawObject();

    glBlendFunc(GL_ONE, GL_ONE);
    glBindTexture(..., texture);
    drawObject();

    --> it works but i have to draw the object 2 times.
    is there a faster way?

    (mask is a texture where the transparent texels are white and the other pexels black)
    (in texture the transparent texels are black)

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Transparent Texture Effect

    What?
    use a texture with an alpha channel.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Re: Transparent Texture Effect

    which file format??? now i am using .raw files! i think most of the picture formats which support alpha channels are hard to read!

  4. #4
    Guest

    Re: Transparent Texture Effect

    You could use .raw files with 32 bit components, otherwise I find .tga files very easy to read & write.

    BMP supports 32 bit as well but not every imagine software supports that.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Re: Transparent Texture Effect

    in photoshop i cannot save a raw with alpha channels...if photoshop doesn't support this no imagine software will do this....

    how do you save 32 bit raws with alpha channel????

  6. #6
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Re: Transparent Texture Effect

    i have tried it in graphic converter and i was able to export RGBA textures - but my raw reading routine doesn't work any more.. -->clear

    are there any tutorials in reading a tga file or how can i interprete the file?

  7. #7
    Guest

    Re: Transparent Texture Effect

    Originally posted by H.Stony:
    if photoshop doesn't support this no imagine software will do this....
    Sure...

    As for .tga files there are tons of tutorials out there for example this:

    http://nehe.gamedev.net/data/lessons....asp?lesson=33

  8. #8
    Guest

    Re: Transparent Texture Effect

    First, post your RAW Loading Function so that we can tell you where to toggle the 4th channel(alpha). If you know for sure your converted RAW texture includes the ALPHA channel, then it should'nt be to hard to modify it.

    For example, when you allocate your buffer in your RAW loading function after widthTexture, heightTexture, 4 , so on... The four instructs the space to hold the 4ht Alpha channel.

    Likewise, when you read it include a 4 after the widthTexture and heightTexture parameters.

    Finally, when you build your MipMap, at the end of this function, do something like the following:

    gluBuild2DMipmaps( GL_TEXTURE_2D, 4, textureWidth,
    textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, raw_data );

    GL_RGBA instead of GL_RGB and a 4 insteadof a 3 after GL_TEXTURE_2D.

    If you dont change the previous parts you "will" get errors or worse,your compiler will freeze or crash.

    But, post your texture loading function anyways...I'm sure somebody here can jerry rig it up for you, really quick.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    153

    Re: Transparent Texture Effect

    Code :
     	GLuint   sz;    
    	FILE*    file;  
    	long     fsize; 
    	GLubyte* p;    
     
    	refimg->w = (GLuint) w;
    	refimg->h = (GLuint) h;
    	sz = (((3*refimg->w+3)>>2)<<2)*refimg->h;
    	refimg->data = new GLubyte [sz];
    	if (refimg->data == NULL) {
    		environment.error = 61;
    		sprintf(awx_temp_string,"Fehler in AWX-RAW-Loader: %s.",file_name);
    		environment.error_message=awx_temp_string;
    	}
     
     
    	file = fopen(file_name , "rb");
    	if (!file)
    	{
    			environment.error = 2;
    			sprintf(awx_temp_string,"Die Texturdatei: %s nicht gefunden.",file_name);
    			environment.error_message=awx_temp_string;
    	}
    	environment.getError();
    	fseek(file, 0L, SEEK_END);
    	fsize = ftell(file);
    	if (fsize != (long)sz) {
    		environment.error = 62;
    		sprintf(awx_temp_string,"Die Texturdatei: %s ist nicht in der richtigen Auflösung",file_name);
    		environment.error_message=awx_temp_string;
    		fclose(file);
    		environment.getError();
    	}
    	fseek(file, 0L, SEEK_SET);
    	p = refimg->data;
    	while (fsize > 0) {
    		fread(p, 1, 1, file);
    		p++;
    		fsize--;
    	}
    	fclose(file);
    i hope anybody can modify it for a 32 bit textre with alpha channel

  10. #10
    Guest

    Re: Transparent Texture Effect

    How are you building your MIpMap? Post that as well, if you can. It should pretty much be a matter of including in buildMipMap a 4 instead of a 3 and a GL_RGBA instead of a GL_RGB.

    As for the rest, meanwhile to store and read the texture try toggling a 4 insteadof a 3....and lets see if your compiler does'nt barf.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •