transparency problem

Originally posted by snow_master:
Elixer,
I am usually as light as they get, it’s just that this is the 20 replay to my original question, and except for insulting my intelligence and programming capabilities, no one had really made any real try to read the code, the question and make a wise suggestion !!!
this “beginner” question is apparently insulting the intelligence of the professional experts that read this forum.
it is so insulting that no one has a clue why the problem is occurring…
believe me that before posting the question I read the opengl doc, the open gl book, 4 articles regarding transparency and open gl and numerous code changes and transparency methods (like alpha functions instead of blending functions etc.)

Actually it makes a lot of sense if you post it on the beginner forum. People there tend to have more patience with reading code.
Believe me, review this code again 2 years from now. You will realize you are making a number of bad uses of OpenGL. That’s how I know you are not an advanced developer on OpenGL. What do you think the so-called “advanced developers” do daily? We try to reply as much as we can. It is already pissing job to read someone’s else code in the workplace, no one is going to read your code unless they have free time to do so.

Originally posted by snow_master:
[b]

Coconut - in what line ?

B]

           SurfaceColor[3] =                if(m_fTransperentLevel< 1.0)               {                           //change the transperent

Originally posted by snow_master:
[b]I do only use the glMaterialfv, the 4 th component of the color vector is the alpha value.

is that wrong just to use material ?[/b]

Not necessarily wrong. As you have lighting enabled, you just have to make sure that your light colors have non-zero alpha values. Color sum should then take care of the rest.

However, you’ve already tried setting primary color directly. So at the moment, I’m a bit stumped as well.

it’s:
SurfaceColor[3] = m_fTransperentLevel;
if(m_fTransperentLevel< 1.0)
{
//change the transperent
//object color from the
//original color
SurfaceColor[0] -= 0.4;
if(SurfaceColor[0] < 0)
SurfaceColor[0] = 0;
SurfaceColor[1] -= 0.3;
if(SurfaceColor[1] < 0)
SurfaceColor[1] = 0;
SurfaceColor[2] -= 0.1;
if(SurfaceColor[2] < 0)
SurfaceColor[2] = 0;
}

Just a thought, but did you enable GL_COLOR_MATERIAL in your app? That would prevent you from directly specifying the primary (ie non-lighting generated) color.

Elixer,
>>Actually it makes a lot of sense if you post it on the beginner forum. People there tend to have more patience with reading code.

I posted the same question in the beginner forum as well, no answers so far.

>>You will realize you are making a number of bad uses of OpenGL. That’s how I know you are not an advanced developer on OpenGL

it is true I am not an expert in open gl (if i was I would probably solved it my self…(- , but specifically the “bad use of gl” you are probably referring to is the triangle strip adjustments I had to made, because this function deals with a VRML file that is produced as a full triangles model, and for efficacy reasons I made these changes to use the triangle strip instead of the triangles(as you can see I am using in the for loop only vertex no 2 of every face where in fact all there vertexes of the face represent a full triangle as generated from our IP team in the VRML file.
if there is any other bad use of open gl I would like to know about it so I will learn from my mistakes.
thanks in advance.

my last replay was meant to Coconut and not for Elixer, sorry.

zeckensack, I am at home right now, so I don’t have the entire code infront of me, but I am almost sure that I did, actually if I didn’t so how come I can see the object in alternating colors at all ? (both objects has several colors, and I see them good in white background)

Originally posted by snow_master:
[b]my last replay was meant to Coconut and not for Elixer, sorry.

zeckensack, I am at home right now, so I don’t have the entire code infront of me, but I am almost sure that I did, actually if I didn’t so how come I can see the object in alternating colors at all ? (both objects has several colors, and I see them good in white background) [/b]

After enabling GL_COLOR_MATERIAL, you can’t directly change the primary color anymore. With further glColor* calls, you change the material. Now, if your light colors (eg glLightfv(GL_LIGHT0,GL_DIFFUSE,pointer_to_whatever_color)) are white, that will allow RGB colors to still show through. However, if that light color has an alpha of zero, it will essentially block alpha values, as the material colors get multiplied by light colors component-wise, and then some attenuation. BTW, if that wasn’t clear enough, feel free to ask again.

If this is the problem, there are some preparations that must have been met:
1)Before enabling color material, you must have called glColor4f(something,something,something,zero_or_close); or you made an equivalent glColor4… call
2)You must have specified your own light colors (search your code for GL_AMBIENT and GL_DIFFUSE) with zero alpha, the default one has full alpha.

The reason I’m thinking this might be the case:
You say, glBlendFunc(GL_whatever,GL_SRC_COLOR); makes your objects show, but only against a non-black background. In this case you have, eg
final_color=fragment_colorwhatever_maybe_zero+whitefragment_color -> visible
Which makes perfect sense.

If any of the alpha values going to the blending stage were non-zero, glBlendFunc(GL_SRC_ALPHA,GL_ZERO) would already allow you to see your objects, which is not the case.

So I’m almost certain that your alpha values get lost somewhere, and the only place I can thing of right now off the top of my head is the lighting equation.

This is hilarious! I think the problem may be that you’re only explicitly scoping every other gl call

– Zeno

zeckensack,
to my recollection the light color is white with alpha value of 1.0

>>you must have called glColor4f
I only use glMetiralfv calls no glColor calls.

>>final_color=fragment_colorwhatever_maybe_zero+whitefragment_color -> visible
Which makes perfect sense.

it does make sense why I see it, but how come it’s transparent ? does the opengl knows to render it transparent inspite the fact that the first part of the final_color is zero ?

I don’t understand another thing, the first parameter you say is not important, but this parameter indicates how to blend the source color, that is the one that is being painted on the buffer data, and the second parameter is the factor of the multiplication of the dest, that is the data that already had been painted on the buffer, but the transparent object is always the source object ! and in this case the background is the dest “object” ! so how come I see anything at all ?

>>If any of the alpha values going to the blending stage were non-zero, glBlendFunc(GL_SRC_ALPHA,GL_ZERO)

I am sure that none of the color vectors going to glMaterialfv has alpha value of zero, only 1.0 and then 0.5

>>and the only place I can thing of right now off the top of my head is the lighting equation.

I will check it Sunday morning, I hope you are right, I spent way too much time on this stupid problem…

any how it’s now 03:15 am, so I am going to sleep…

thanks for your help, I appreciate it.

Zeno,
please explain I didn’t understood what you meant.

He means the :: before your gl calls indicating global scope of those functions. This is considered safe and good practice by some but isn’t needed unless you have similar member functions in the class you are calling from, which is probably considered bad practice by the very same people.

He’s teasing you, not trying to help you. Don’t feed the trolls.

If alpha is supposed to be 0.5 test it with glAlphaFunc enabling alpha fragment testing. This way you can set the source color blend and confirm that the alpha fragments you are getting are infact 0.5 or thereabouts by testing against various reference values to see at what alpha value the object gets fragment culled.

If all else fails you may have found a bug in the OpenGL implementation. Try the same software with another graphics card & drivers, or on another platform. Or link to something like Mesa and run in software.

Good luck.

[This message has been edited by dorbie (edited 04-04-2002).]

I take offense to the criticism aimed at me. I am not a troll, Dorbie
I tried to help him, but he simply replied by insulting me. You think his code is making efficient use of opengl? That’s all I said, and I got a torrent of abuse.
I only said this is a beginners question, because it is - and didn’t labour the point. I didn’t insult him until he insulted me. Did I do wrong? Please help me to better interact with these people, for I am nothing more than a professional renderer author.

snow_master, can you make the (full compilable) source available so that I can try this here.

I must say that like some others here, I find it difficult to read code directly on the board. When the code is complete, I sometimes take the time to create a new VC++ project, paste the code in and have a look. But I have no time to do it these days.

If you had a zip file containing everything needed to run the program, I’d try to help.

Call me old fashioned, but debugging an app with a debugger is for me the best way to find a bug (now, doing board-debugging sounds funny but I am too lazy for that ).

Regards.

Eric

knackered,

you told him to go to the beginners board, but his question explained that he’d tried all the usual stuff. No offense but when you tell someone that you at least owe them the courtesy of reading the post instead of making an assumption about their question. It was all downhill from there. Maybe you meant to help and I’m too sensitive to anti-question posts. I’ve decided to improve this board (which is in danger of degenerating more than it already has) by helping more on topic posters and sticking up for them when someone seems to put them down. Help me do that, it’s the questions as well as the answers which make this board work. Can’t we all just get along :-).

Ok Dorbie, I respect your motives.
I give up, I’m broken like a horse.
I suppose it’s not for me to criticise the way he writes code. But snowman, can I suggest that you look into vertex arrays, you can use them in display lists (but remember, it will dereference the arrays at display list compile time), and also, it’s unwise to use GL_COMPILE_AND_EXECUTE, it’s more efficient to GL_COMPILE, then GL_EXECUTE in 2 steps - at least on nvidia cards.
Don’t use classes for your vertices, use typedef structs, as you can add ‘member functions’ to them in the same way as a class, but you can also create an array of them, without the compiler putting header information before each entry…therefore allowing you to pass this array straight to opengl without any extra processing/dereferencing.

SurfaceColor[0] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->r();

That is going to slow things down (divisions are bad), even though I assume you’re not doing this every frame, only when the mesh changes in some way. Either store your colours as floats, in the range of 0.0 → 1.0, or reduce this calculation down to the reciprical,
ie.

(in initialisation)
const float colour_conversion = 1.0f/255.0f;

(every update)
SurfaceColor[0] = pFace->v(0)->GetColor()->r() * colour_conversion;

Also, you should rethink this whole ‘face’ class approach, in my opinion. Keep things very simple for opengl, don’t bog it down by explicitly defining vertices every time.

Anyway, I hope this helps you in some way.
Sorry for the whole ‘pump attendant’ thing, but you did wind me up with your…in my opinion…unjustified arrogance.

hm… i really want some nice forum with nice code-presentation. to read this code online here is ****in awful and very annoying, that is true. thats why no one posts code in here. if you want to show code, post it on flipcode, and link to there

no. seriously, i did not read it and just followed the replies. all i can guess is your alpha-value is wrong. this can be because you set it wrong per vertex or you have it even perpixel set with a texture. i dont know if you’re using textures but i dont think so, because no one mentoyed it yet, but anyways… i’ll look at your problem…

Don’t use classes for your vertices, use typedef structs, as you can add ‘member functions’ to them in the same way as a class, but you can also create an array of them, without the compiler putting header information before each entry…therefore allowing you to pass this array straight to opengl without any extra processing/dereferencing.

Thats is bollocks!


class V3
{
public:
V3() {}
~V3() {}

float x, y, z;
};

typedef struct
{
float x, y, z;
}V3;

Both of these use exactly the same amount of memory, and both can be used to be passed over to rendering API's exactly.  And both can be used directly in contiguous memory arrays.

You only get extra info (V-table) included, when you start using virtual functions. 

I suggest you read some good C++ books.

Nutty

[This message has been edited by Nutty (edited 04-07-2002).]

[This message has been edited by Nutty (edited 04-07-2002).]

its a wellknown fact (because written in all the specs of c++, one of these can be found directly in the msdn-help-files) that structs and classes are the same. the only difference is that in classes, the members are per standart private, in the structs they are public.

class v { public: float x,y,z; };
and
struct v { float x,y,z; };
are completely the same.

the compiler generates for both a default constructor and default destructor, both public and they don’t do anything.

You miss the point, to address these you need additional indirection, but much worse than this, the guy is using methods to read these variables. No disrespect but knackered is right on this, unless you have the compiler from God, which doesn’t exist. On the other hand he is compiling a display list so it doesn’t matter nearly as much.

[This message has been edited by dorbie (edited 04-07-2002).]