View Full Version : Transparency
Having read all transparency-subjects at the forum, I can still not solve my problem. The thing is, I have my own font class with bitmaps, black/blue. Now, I'd like to make the black color transparent, making it possible to use background images. Any suggestions or pseudocodes that I might use?
07-03-2001, 05:52 AM
look up blending, that´s what you need...
first you draw the background and later on draw your text with glColor4f(r,g,b,alpha) the alpha value gives you the transparency...
and enable the blending with glEnable(GL_BLEND);
ok...but it still doesn't work...
I tried this:
glColor4f(0.0f, 0.0f, 1.0f, 0.0f);
shouldn't that make the blue color transparent?
i also tried glColor4f(0.0f, 0.0f, 0.0f, 0.0f) which I thought would make the black color transparent, but instead nothing was visible...
further help, grodslukaren???
07-03-2001, 06:12 AM
Ok, first of all you said you were using bitmaps for your font? Do you mean a true bitmap (0-bit off 1-bit on) or do you mean a BMP file for a texture. If you mean a true bitmap then the color used to display the 1-bits will be the current color, which is set with glColor*. The 0-bits are not drawn. So... if you want the font to be blended you set the current color to something with an alpha value. You seem to be under the impression that using glColor4f will assign an alpha value to that color. That is not the case. It simply sets the current color that will be used for drawing. One other thing that's important to note is that if you are using lighting, the current color is not used. With lighting enabled, the current material properties are used. If you enable GL_COLOR_MATERIAL you can have the current color track one of the material properties, but it is still basically using materials.
07-03-2001, 06:15 AM
first you should draw your opaque objects, or the bitmap you want as background, then turn on:
glColor4f(0.0f, 0.0f, 1.0f, 0.5f); //0.5 makes it 50% transparent
glBegin("your transparent stuff")...
<<shouldn't that make the blue color <<transparent?
<<i also tried glColor4f(0.0f, 0.0f, 0.0f, <<0.0f) which I thought would make the black <<color transparent, but instead nothing was <<visible...
you have to set the alpha value to something between 0 and 1, zero is totally transparent and 1 is totally opaque... with zero the object is there, but you can´t see it...
hope it helps...
hmmm...i use BMP files...
Is the code diffícult to write? Would it be possible to send you the code by mail, and you might just comment it...what should be written where and so on?
Gee, was that a lazy one or what? http://www.opengl.org/discussion_boards/ubb/wink.gif
That code snippet made the hole bitmap 50% transparent, not only the blue color...
07-03-2001, 06:40 AM
as far as i know you can't simply make a certain color transparent (well you actually can make blue transparent using register combiners). So why don't just make give your bitmaps fonts a transparent part, its much easier than letting your opengl programm transform anything.
Ok...does that mean that I can't use BMP? I have a LoadJPG class...will the transparency work "automatically" if I give the fonts a transparent part or do I have to modify the class? *Feeling stupid* http://www.opengl.org/discussion_boards/ubb/smile.gif
07-03-2001, 06:49 AM
i think tiff would be the best format, because jpeg doesn't support transparency
07-03-2001, 07:10 AM
I haven´t worked with bitmaps, so I´m not sure how to do it. But I send you a part of my Render() that works with objects...
// draw dipoles if exist any, opaque
for (dipole=0; dipole<m_numNbrOfDipoles; dipole++)
glColor3f(0.3f, 0.3f, 1.0f); // dipoles drawn blue
glCallList(DIPOLE); // draws a dipole
// draw the brain, the scalp and the face from the displaylists blended to 33%
glColor4f(0.3f, 1.0f, 0.3f, 0.33f);
glColor4f(1.0f, 0.4f, 0.3f, 0.33f);
glCallList(DISP_FACE); // draws the face
glCallList(DISP_REAL_SCALP); // draws the scalp with the same color as the face
07-05-2001, 05:03 AM
Sounds like you just need to convert your image to an RGBA image from RGB. Then for any given color you can set the A (alpha channel) to anything you like to make only that color transparent. Here's a quick code snippet that should help explain what I mean.
unsigned char* pRGBImage;
unsigned char* pRGBAImage;
int width, height;
pRGBImage = GetImageData();
width = GetWidth();
height = GetHeight();
pRGBAImage = new unsigned char[width*height*4];
for (int y=0;y<height;y++)
for (int x=0;x<width;x++)
int baseindex = y*width + x;
// assign current RGB data
pRGBAImage[baseindex*4] = pRGBImage[baseindex*3];
pRGBAImage[baseindex*4+1] = pRGBImage[baseindex*3+1];
pRGBAImage[baseindex*4+2] = pRGBImage[baseindex*3+2];
// Now assign blue alpha of 128 everything else 255
if (pRGBImage[baseindex*3]==0 && pRGBImage[baseindex*3+1]==0 && pRGBImage[baseindex*3+2]==255)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.