Texture Blending
I cant seem to get texture blending to work right. Im using SDL to load in a .tga file. The problem is I have to pass the file format to a gl function. The file formats are represented by #defines. (for instance GL_RGBA). After alot of tinkering and frustration I figered that the file format for my .tga would be GL_ARGB but I searched my include file and couldnt find it. There was a GL_ABGR_EXT which worked the best but still screwed up my colors when I tried it.
So my question is is there anyway to use texture blending without having alpha values in the file? If that were the case I could just use .bmp (which I perfer).
Or mabey theres a quick and easy way to reformat my .tga?
Im new to graphics programming and Opengl so my problem may not be what I think it is. I would post source code but Im not home at the moment. Thanks for the help.
there is a way to add transparancy to a certain color by loading a tga or bitmap or any 24bit color format, but as you read the bitmap you would have to convert the entire bitmap into 32bit and add the alpha value for specific colors you want.
this is how I made 255 0 255 color 100% transparent when loading a 24-bit bitmap...
I think it would all be much easier to do all this by just loading a png with all the alpha values already there.
this is how I made 255 0 255 color 100% transparent when loading a 24-bit bitmap...
#define rgb32bit(r,g,b,a) (a<<24) | (r<<16) | (g<<8) | (b)for(index = 0; index < BFsize; index+=3){ BYTE alpha = 255; BYTE red = buffer[index]; BYTE green = buffer[index+1]; BYTE blue = buffer[index+2]; if( red == 255 && blue == 255 ) alpha = 0; bitmap_file->buffer[index32] = rgb32bit(red, green, blue, alpha); index32++;}
I think it would all be much easier to do all this by just loading a png with all the alpha values already there.
Quote:Original post by NegativeGeForce
I think it would all be much easier to do all this by just loading a png with all the alpha values already there.
But for what I have in mind I might need to change the alpha values dynamiclly for fading and stuff. If I wanted a texture to fade away Id have to do it that way right?
the alpha data in the image (first or last 8 bits) just specifies the initial transparency. You can use the OpenGL blending functions to actually make the entire image fade in and out without the alpha values from the bitmap. The OpenGL blending options are very complex and you can do alot of combinations with them, but the most widely used method to make the foreground object your drawing transparent or mix to the background colors goes something like this...
this draws a textured quad...before calling this code you have to bind a texture first.
if your not to familar with all these functions and options...the opengl red book has decent explainations on everything.
http://fly.srk.fer.hr/~unreal/theredbook/
this draws a textured quad...before calling this code you have to bind a texture first.
glEnable(GL_BLEND);/* this function sets how opaque you want the colors, including the alpha value witch can be 0-1.0, 1.0 being fully opaque, 0.5 is 50% transparency*/glColor4f(1.0f,1.0f,1.0f,alpha); /* this function sets the blending equation. GL_SRC_ALPHA reads from the colorsu specified from glColor4f() as the source. GL_ONE_MINUS_SRC_ALPHA basiclyasumes 1.0 as alpha then subtracts the values from glColor4f(). This specifieshow much you need to take from the background pixels. Example: if source pixel alpha is .25, then the OpenGL will copy .75 from the background pixels.*/glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// draw quad with uvglPushMatrix();glTranslatef(x, y, -1);glRotatef( angle, 0.0f, 0.0f, 1.0f );glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2d( -width, -height); // width and height can be any values you specify glTexCoord2f(1.0f, 0.0f); glVertex2d( width, -height); glTexCoord2f(1.0f, 1.0f); glVertex2d( width, height); glTexCoord2f(0.0f, 1.0f); glVertex2d( -width, height);glEnd();glPopMatrix();// disable blendingglDisable(GL_BLEND);
if your not to familar with all these functions and options...the opengl red book has decent explainations on everything.
http://fly.srk.fer.hr/~unreal/theredbook/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement