PDA

View Full Version : transparency problem



snow_master
04-04-2002, 06:22 AM
Hi,
i am drawing two objects the first one is opaque , and the second one is semi transparent on a black
background.
the alpha factor of the opaque object is 1.0 and of the transparent one is 0.5
i have the following problem :
if i use the blending functions :
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
or
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
I see only the opaque object and not the transparent one.
if i use :
glBlendFunc(GL_ONE ,GL_ONE);
both objects appear but when they are one in front of the other
the blended pixels turns white, and the transparent object turns white also in some angles when is just
against the black background.(as if it reflects to much light even that the specular component is disabled)
if i use:
glBlendFunc (GL_SRC_ALPHA, GL_SRC_COLOR);
I get good results when the transparent object is in front of the opaque object, but when the transparent
object is on the black background it disappears !!! (if i change the color of the background to white
it works great, but I need it black....)
the display function is :

GLfloat SurfaceColor[4];

// Erase last list
if (m_ListOpenGL)
if (glIsList(m_ListOpenGL))
::glDeleteLists(m_ListOpenGL,1);

// Search for a new list
m_ListOpenGL = ::glGenLists(1);
if(m_ListOpenGL == 0)
return 0;

// Start list
unsigned int NbVertex = (unsigned int)m_ArrayVertex.GetSize();
if(!NbVertex)
return 0;

unsigned int NbFace = (unsigned int)m_ArrayFace.GetSize();
if(!NbFace)
return 0;

CFace3d* pFace;
CVector3d* pVector;
CColor* pColorPrevious;

::glNewList(m_ListOpenGL,GL_COMPILE_AND_EXECUTE);

//the alph value of the mesh
if(m_fTransperentLevel< 1.0)
{
//both objects appear but when are one in fron of the
//other
//the blendind turns white, and the transparent object is
//white in some angles.
//glBlendFunc(GL_ONE ,GL_ONE);
//only the solid object appear, the transperent isn't
//glBlendFunc (GL_SRC_ALPHA, GL_ONE);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//works good but dissapear in black backround
glBlendFunc (GL_SRC_ALPHA, GL_SRC_COLOR);
glEnable(GL_BLEND);
//turn off the depth buffer
glDepthMask (GL_FALSE);
}

// Init color
pFace = m_ArrayFace[0];
pColorPrevious = pFace->GetColor();

::glBegin(GL_TRIANGLE_STRIP);
// form the first two vertices of the N-2 triangle strip.
SurfaceColor[0] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->r();
SurfaceColor[1] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->g();
SurfaceColor[2] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->b();
SurfaceColor[3] = m_fTransperentLevel;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, SurfaceColor);


pVector = pFace->v(0)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(0)->x(),pFace->v(0)->y(),pFace->v(0)->z());
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y(),pFace->v(1)->z());

for(unsigned int i=0; i< NbFace-1; i++)
{
pFace = m_ArrayFace[i];
// Normal (per face)
if(m_NormalBinding == NORMAL_PER_FACE)
{
pVector = pFace->GetNormal();
::glNormal3f(pVector->x(),pVector->y
(),pVector->z());
}
// Color (per face)
if(m_ColorBinding == COLOR_PER_FACE &&
pColorPrevious != pFace->GetColor())
pColorPrevious = pFace->GetColor();
// Normal
if(m_NormalBinding == NORMAL_PER_VERTEX)
{
pVector = pFace->v(2)->GetNormal
();
::glNormal3f(pVector->x(),pVector-
>y(),pVector->z());
}
// Color (per vertex)
if(m_ColorBinding == COLOR_PER_VERTEX &&
pColorPrevious != pFace->v(2)->GetColor())
{
SurfaceColor[0] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->r();
SurfaceColor[1] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->g();
SurfaceColor[2] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->b();
SurfaceColor[3] =
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;


}
glMaterialfv(GL_FRONT,
GL_AMBIENT_AND_DIFFUSE,
SurfaceColor);

pColorPrevious = pFace->v(2)->GetColor();
}


// Vertex
::glVertex3f(pFace->v(2)->x(),pFace->v(2)-
>y(),pFace->v(2)->z());

}
//complete the last ring triangle strip
pFace = m_ArrayFace[i-39];
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z
());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y
(),pFace->v(1)->z());
pVector = pFace->v(2)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z
());
::glVertex3f(pFace->v(2)->x(),pFace->v(2)->y
(),pFace->v(2)->z());
pFace = m_ArrayFace[i-37];
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z
());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y
(),pFace->v(1)->z());


::glEnd();


if(m_fTransperentLevel< 1.0)
{
glDepthMask (GL_TRUE);
glDisable(GL_BLEND);
}
::glEndList();

// List is done now
m_ListDone = TRUE;
m_Modified = FALSE;

return 1;

any ideas ????
thanks in advance

davepermen
04-04-2002, 08:16 AM
wow.. lovely knacky..
are you in love? or got payed holidays at work? or what?

yeah, listen to knacky he tells you all you need to know. good luck on reordering your stuff.

snow_master
04-04-2002, 08:16 AM
>>I don't mean to offend you
you didn't
>>you have to draw transparent objects >>AFTER opaque ones, and they must be drawn >>in strict order from the far plane to the >>near plane, with glDepthMask(GL_FALSE);
DA, this is the paint function of an object of type 3dMesh, and if you would bother to read the code you would have seen that of the transparency level is < 1.0 (that is the alpha level of the mesh) I transform the depth buffer to a read only mode using glDepthMask(GL_FALSE)
since there are two mesh objects I draw the
opaque one first and then the transparent one and therefore the if condition is being entered during the rendering of the second mesh.

>>Wasn't I nice, everyone?
actually Not really.

Elixer
04-04-2002, 09:03 AM
Originally posted by snow_master:
[B][snip]
and if you would bother to read the code you would have seen that ...[snip]
[B]

LOL geeze Knackered... can't you read? http://www.opengl.org/discussion_boards/ubb/wink.gif

I want that code debugged and ready to go in an hour! Get to it, before we send you to n00bie land! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

p.s. Sleep? Whats that? Dunno, but if you don't get any, it sure makes you say strange things!

snow_master
04-04-2002, 10:10 AM
>>I didn't bother to read your code because it's almost unreadable

you probably meant you couldn't understand it because things I have long forgotten regarding programming you will probably never learn....

>>and I shouldn't have even replied to you

so don't.
you bother me and spend my valuable (and very expensive) time, and except bitching you aren't being helpful, so just spare me your "wane be" smart answers.

>>You are also very ungrateful

you got to be kidding.....I should be grateful for what ?

snow_master
04-04-2002, 10:31 AM
thank god for the internet....otherwise people like you would have never had the chance to interact with people like me...I find it amusing....but you live in this sad comedy.....I pity you.
p.s
if you are such a good programmer (I hope you are because judging your inter relationship with human beans, you probably haven't got any friends....) instead of answering intelligently insulting replays...try to debug the problem and earn some respect...

gumby
04-04-2002, 10:35 AM
As a vegetarian, I object to the whole
concept of these "human beans".

Coconut
04-04-2002, 10:43 AM
Originally posted by gumby:
As a vegetarian, I object to the whole
concept of these "human beans".

It was a typo. He meant "humans and beans".

snow_master
04-04-2002, 10:49 AM
again if you would have bother to read the question and the code....you would have noticed that i tryed many blending functions (including some that are not writen) it didn't made any sence to me either why when the src factor of the blending function is src_alpha (which make sence)that the whight of the closer transparent pixel alpha value will be multiplied, but the dest factor is GL_SRC_COLOR which dosen't make sence at all, but this is the only way i got good results...(when the background isn't black), the reasnobele choise was to put ONE_MINUS_SRC_ALPHA, but as i wrote earlier this method made only the opaque object to appear.
>>God, your spelling is almost as bad as
i appologize for my bad spelling, but english isn't my first language, and actualy i speak read and write in 7 languages.(i bet you do to....)

now, dosen't any one else read this fourum ? can someone please try to be more helpfull...?...?

snow_master
04-04-2002, 11:04 AM
please do go away already !!!
now doesn't any one else can please be kind and try to suggest a solution ?

dorbie
04-04-2002, 12:44 PM
What the heck is your problem knackered?

This question is on topic and not purely beginners. His code lacks indents because of the UBB system.

Are you deliberately trying to intimidate people learning OpenGL to stop them posting here? People post here to learn, if you don't want to help them then don't intimidate them.

zeckensack
04-04-2002, 12:48 PM
I'll take the liberty to try and restore some indentation for better readability:


the display function is :

GLfloat SurfaceColor[4];

// Erase last list
if (m_ListOpenGL)
if (glIsList(m_ListOpenGL))
::glDeleteLists(m_ListOpenGL,1);

// Search for a new list
m_ListOpenGL = ::glGenLists(1);
if(m_ListOpenGL == 0) return 0;

// Start list
unsigned int NbVertex = (unsigned int)m_ArrayVertex.GetSize();
if(!NbVertex) return 0;

unsigned int NbFace = (unsigned int)m_ArrayFace.GetSize();
if(!NbFace) return 0;

CFace3d* pFace;
CVector3d* pVector;
CColor* pColorPrevious;

::glNewList(m_ListOpenGL,GL_COMPILE_AND_EXECUTE);

//the alph value of the mesh
if(m_fTransperentLevel< 1.0)
{
//both objects appear but when are one in fron of the other the blending
//turns white, and the transparent object is white in some angles.
//glBlendFunc(GL_ONE ,GL_ONE);
//only the solid object appear, the transperent isn't
//glBlendFunc (GL_SRC_ALPHA, GL_ONE);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//works good but dissapear in black backround
glBlendFunc (GL_SRC_ALPHA, GL_SRC_COLOR);
glEnable(GL_BLEND);
//turn off the depth buffer
glDepthMask (GL_FALSE);
}

// Init color
pFace = m_ArrayFace[0];
pColorPrevious = pFace->GetColor();

::glBegin(GL_TRIANGLE_STRIP);
// form the first two vertices of the N-2 triangle strip.
SurfaceColor[0] = 1.0f/255*pFace->v(0)->GetColor()->r();
SurfaceColor[1] = 1.0f/255*pFace->v(0)->GetColor()->g();
SurfaceColor[2] = 1.0f/255*pFace->v(0)->GetColor()->b();
SurfaceColor[3] = m_fTransperentLevel;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, SurfaceColor);


pVector = pFace->v(0)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(0)->x(),pFace->v(0)->y(),pFace->v(0)->z());
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y(),pFace->v(1)->z());

for(unsigned int i=0; i< NbFace-1; i++)
{
pFace = m_ArrayFace[i];
// Normal (per face)
if(m_NormalBinding == NORMAL_PER_FACE)
{
pVector = pFace->GetNormal();
::glNormal3f(pVector->x(),pVector->y
(),pVector->z());
}
// Color (per face)
if(m_ColorBinding == COLOR_PER_FACE &amp;&amp;
pColorPrevious != pFace->GetColor())
pColorPrevious = pFace->GetColor();
// Normal
if(m_NormalBinding == NORMAL_PER_VERTEX)
{
pVector = pFace->v(2)->GetNormal
();
::glNormal3f(pVector->x(),pVector-
>y(),pVector->z());
}
// Color (per vertex)
if(m_ColorBinding == COLOR_PER_VERTEX &amp;&amp;
pColorPrevious != pFace->v(2)->GetColor())
{
SurfaceColor[0] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->r();
SurfaceColor[1] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->g();
SurfaceColor[2] = (float)1 /
(float)255 * (float)pFace->v(2)->GetColor()->b();
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;


}
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,Surfa ceColor);

pColorPrevious = pFace->v(2)->GetColor();
}

// Vertex
::glVertex3f(pFace->v(2)->x(),pFace->v(2)->y(),pFace->v(2)->z());
}
//complete the last ring triangle strip
pFace = m_ArrayFace[i-39];
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z
());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y(),pFace->v(1)->z());
pVector = pFace->v(2)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(2)->x(),pFace->v(2)->y(),pFace->v(2)->z());
pFace = m_ArrayFace[i-37];
pVector = pFace->v(1)->GetNormal();
::glNormal3f(pVector->x(),pVector->y(),pVector->z());
::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y(),pFace->v(1)->z());
::glEnd();


if(m_fTransperentLevel< 1.0)
{
glDepthMask (GL_TRUE);
glDisable(GL_BLEND);
}
::glEndList();

// List is done now
m_ListDone = TRUE;
m_Modified = FALSE;

return 1;

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

Elixer
04-04-2002, 01:07 PM
Whoa, I fall asleep at the keyboard, and when I woke up, and looked at this topic again, it seems that someone had their knickers in a bunch!

That can make anyone cranky! http://www.opengl.org/discussion_boards/ubb/smile.gif


zeckensack, nice formatting!

looking at the GL docs :
"Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest."

Now, someone pass the beer and the human beans! MMM MMM http://www.opengl.org/discussion_boards/ubb/biggrin.gif

snow_master
04-04-2002, 01:23 PM
>>"Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest."

as I mentioned 3 times already primitives ARE sorted from farthest to nearest and when using the (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) I see only the opaque object but no trace of the transparent object !!!!!
and give me a break about the beans...I have spelling mistakes....big ****ing deal...I am sure each and every one fully understood what I meant.I am not an English native speaker, so I write as I phonetically hear the word, I guess that I will never get it perfect, but I am coming soon to do my masters in the states and I hope that it should do the trick...

Elixer
04-04-2002, 01:40 PM
Snow, don't know if anyone ever told you, but a http://www.opengl.org/discussion_boards/ubb/biggrin.gif means to take it as a joke. Lighten up!!

Oh, and I didn't see you say you sorted your stuff, but you DIDN'T say it 3 times...

Have a nice day!

Coconut
04-04-2002, 01:47 PM
What you saw can be explained when the source has an alpha of 0.0

Also, snow_master, you did not paste the whole code in your display function. In one line, half of the statement is missing.

dorbie
04-04-2002, 01:52 PM
I suspect that m_fTransperentLevel is zero or some other source fragment alpha is zero messing up your transparency. Check texture alpha, material alpha etc, and make sure it's not getting set to zero somewhere.

Relax, some of the hostile comments were unfair, especially since your code clearly indicates you sort etc. Anyone with a clue knows you weren't randomly trying alpha functions, it is sensible to try a few options just to see if you are getting fragments and your blending hardware & code is working. Don't feed the trolls.

zeckensack
04-04-2002, 01:52 PM
Well, well, well.

If the only way to make your transparent object seen is multiplying it with a white background (glBlendFun(whatever,GL_SRC_COLOR); ) I'd conclude that your alpha value is zero or very close to it.

Have you tried to extract the actually used alpha values out of the rendering function?

No, wait, I don't see any glColor* calls anywhere ... where do you set your alpha values? Only with the glMaterialfv call?

Ok, another suggestion: try glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); again, but insert [B]glColor4f(1.0f,1.0f,1.0f,0.5f); somewhere before rendering the transparent objects. See if this helps.

snow_master
04-04-2002, 01:52 PM
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.)

snow_master
04-04-2002, 02:03 PM
m_fTransperentLevel is 1.0 in the opaque and 0.5 in the transparent object, I double checked it, this was my first guess too...

>>No, wait, I don't see any glColor* calls anywhere ... where do you set your alpha values? Only with the glMaterialfv call?

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 ?
any how I tried also using the glColor4v and got the same results.

Coconut - in what line ?


dorbie - thanks.

Coconut
04-04-2002, 02:07 PM
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.

Coconut
04-04-2002, 02:08 PM
Originally posted by snow_master:
[B]

Coconut - in what line ?


B]

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

zeckensack
04-04-2002, 02:10 PM
Originally posted by snow_master:
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 ?
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.

snow_master
04-04-2002, 02:14 PM
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;
}

zeckensack
04-04-2002, 02:18 PM
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.

snow_master
04-04-2002, 02:26 PM
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...(- http://www.opengl.org/discussion_boards/ubb/smile.gif , 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.

snow_master
04-04-2002, 02:32 PM
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)

zeckensack
04-04-2002, 02:54 PM
Originally posted by snow_master:
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)

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_cl ose); 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_color*whatever_maybe_zero+whi te*fragment_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.

Zeno
04-04-2002, 03:15 PM
This is hilarious! I think the problem may be that you're only explicitly scoping every other gl call http://www.opengl.org/discussion_boards/ubb/wink.gif

-- Zeno

snow_master
04-04-2002, 03:18 PM
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_color*whatever_maybe_zero+whi te*fragment_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.

snow_master
04-04-2002, 03:20 PM
Zeno,
please explain I didn't understood what you meant.

dorbie
04-04-2002, 05:05 PM
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).]

knackered
04-04-2002, 11:08 PM
I take offense to the criticism aimed at me. I am not a troll, Dorbie http://www.opengl.org/discussion_boards/ubb/smile.gif
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.

Eric
04-04-2002, 11:40 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif).

Regards.

Eric

dorbie
04-05-2002, 03:13 PM
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 :-).

knackered
04-06-2002, 10:00 AM
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.

davepermen
04-06-2002, 11:01 AM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif

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..

Nutty
04-07-2002, 01:01 AM
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!

[CODE]
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).]

davepermen
04-07-2002, 01:14 AM
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.

dorbie
04-07-2002, 02:33 AM
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).]

davepermen
04-07-2002, 02:40 AM
dorbi, you're talking bull****.
it IS the same. it is defined as the same. there is NO difference between those two lines of code. you should reread some c++-specs really..
or simply test it http://www.opengl.org/discussion_boards/ubb/smile.gif

and i dont have the compiler from god, i got it from billy..

Nutty
04-07-2002, 03:15 AM
Dorbie, provided you write the accessor functions correctly, then accessing XYZ, via..

vec_class->x();

compiles down to the same as

vec_struct->x;

Personally, I prefer just to make my vector member variables public, and access them directly, but you can go through functions, and it compiles to exactly the same.

Nutty

knackered
04-07-2002, 05:34 AM
I speak from experience, it doesn't work using classes, but does work with structs. If you're saying otherwise, Nutty and dave, then I stand corrected, and I shall try again. No need to get so arsey! http://www.opengl.org/discussion_boards/ubb/wink.gif

davepermen
04-07-2002, 05:57 AM
the problem is not using a class but using memberfunctions to access the data, thats all.

in the end it doesn't really mather

knackered
04-07-2002, 06:00 AM
BTW, I've only tried this with the intel compiler - maybe the vc one is better in some ways, although it can't handle template classes very well.

snow_master
04-07-2002, 07:19 AM
knackered:
the thing that made angry the most is the way you dismissed my question even that it was obvious from your answer that you haven't completely read it.
I posted the same question in the beginners forum and up until now I haven't received a single replay.
furthermore, if you would have read my original question, I think it's rather obvious that I struggled with the problem and read allot of material regarding transparency and opengl before posting the question.
if you would have post the answer that you just had post in the first place which is constructive and helpful all this "nasty" corresponded wouldn't have taken place at all.
regarding your suggestions, this function is indeed called only when the model changes and not when affine transformations are being preformed.
I didn't know the GL_COMPILE_AND_EXECUTE issue I will fix it.
regarding the float values of the colors, i meant to do it, the code isn't completely optimized yet.
regarding classes and structs, as some posts mentioned and to my knowledge it's the exact same thing for the compiler, furthermore to my knowledge if you reference a public member function in a class (or a struct) is more efficient then to call a member function UNLESS the member function
is an inline functions, which all these functions are.
I see that most of you think that the problem is with the alpha values of the object or the lighting, I am almost sure there is nothing wrong with the alpha values (I am sure about the object but not about the lighting), any how I will double check it.
Eric : I can't post the entire code because of security reasons, there are some IP algorithms in the code which I can't post, but if I wont be able to solve the problem, maybe I will make a smaller version without the critical algorithms and post it.
I won't be in the office today and tomorrow, but I will check all the mentioned issues the day after tomorrow and will let you guys know.
thanks for all the help any how.

knackered
04-07-2002, 08:01 AM
Fair enough - truce.

snow_master
04-07-2002, 08:35 AM
(-: truce.

snow_master
04-08-2002, 11:32 PM
ladies and gentlemenís, boys and girls:
I am 100% sure that the alpha values passed to glMaterial are correct 1.0 for the solid and AFTER 0.5 to the transparent (the good old TRACE confirmed it...), furthermore the lights are with alpha value 1.0
I am clueless....any ideas ?
attached is the function that init's the gl scene, maybe I am doing something wrong here ?

int CMy3DViewerCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);

if(SetWindowPixelFormat(hDC)==FALSE)
{
MessageBox("SetWindowPixelFormat Failed", "OpenGL Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

if(CreateViewGLContext(hDC)==FALSE)
{
MessageBox("CreateViewGLContext Failed", "OpenGL Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Lights properties
float ambientProperties[] = { 0.2f, 0.2f, 0.2f, 1.0f};
float diffuseProperties[] = { 0.7f, 0.7f, 0.7f, 1.0f};
float specularProperties[] = { 0.0f, 0.0f, 0.0f, 1.0f};
float Position0Properties[] = {-5.0f, 1.0f, 1.0f, 0.0f};
float Position1Properties[] = { 5.0f, 1.0f, 1.0f, 0.0f};

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLightfv(GL_LIGHT0, GL_AMBIENT, ambientProperties);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularProperties);
glLightfv(GL_LIGHT0, GL_POSITION, Position0Properties);

glLightfv(GL_LIGHT1, GL_AMBIENT, ambientProperties);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseProperties);
glLightfv(GL_LIGHT1, GL_SPECULAR, specularProperties);
glLightfv(GL_LIGHT1, GL_POSITION, Position1Properties);



glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glClearColor(m_ClearColorRed , m_ClearColorGreen , m_ClearColorBlue , 1.0f);

// Perspective
CRect rect;
GetClientRect(&rect);
double aspect = (rect.Height() == 0) ? rect.Width() : (double)rect.Width()/(double)rect.Height();
gluPerspective(45, aspect, 0.1, 1000.0);

// Default : lighting
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

glEnable(GL_DEPTH_TEST);

// Modulate : texture lighting
glEnable(GL_TEXTURE_2D);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// loads the font
switch (fontLoad("..\\Data\\Font.tga"))
{
case FONT_FILE_NOT_FOUND:
MessageBox("File not found", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_IMAGE_TYPE:
MessageBox("Color mapped image or image is not uncompressed", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_DIMENSION:
MessageBox("Dimension is not a power of 2", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_BITS:
MessageBox("Image bits is not 8, 24 or 32", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_DATA:
MessageBox("Image data could not be loaded", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
}

return 1;
}

knackered
04-09-2002, 12:09 AM
Snowmaster, I think you should upload your code (in .dsw format) onto some web space, and put a link to it here.
This is the only easy way people will be able to track down your illusive bug.

snow_master
04-09-2002, 01:45 AM
it's a problem for me to post a link to the code, however i did a smaller version of the viewer without the IP algorithms, if someone is interested and willing to help please send me an e-mail to j_einav@hotmail.com and i will replay you with the project attached.
thanks in advance.

Thaellin
04-09-2002, 03:56 AM
I don't expect to resolve the issue, but since I haven't seen the question asked:

Does it happen on other computers?

If you are truly doing everything correctly, then this would boil down to a driver or hardware issue.

I'd suggest
1. Making sure it misbehaves in the same way on a different system. If not, update your drivers and.or report a bug to the card vendor.

2. If it's got the same problem, create a minimal test case (such as the 'alpha' example from the redbook) to make sure you've got the basic procedure correct.

3. Modify your minimal test case to use lighting, materials, etc so that it's representative of your current situation.

It seems like the code you're writing is fairly involved - solving a simplified problem could give you the answer to your complex application.

Is there any chance people could go back and delete the crap posts? It is very hard to make sense of this thread with all the irrelevant personality conflict stuff. I apologize if I've missed anything which would have addressed my suggestions, above.

Perhaps a new clean thread is in order?

Have fun,
-- Jeff

ChrisBond
04-10-2002, 07:38 AM
Apologies if this is actually a reply to a secondary thread that got started, regarding the use of access functions rather than member variables... I've been lurking the boards a while now (thanks to all who have unknowingly helped me - I'd like to assure everyone that for all the people who post without searching the forum for answers first, there are many who search first and then never have to ask who you'll never know about!).

Anyway, I believe this is my first post. (I seem to have a user name and password, though, so maybe not - I'll have to look.)I've never contributed as I'm only recently an OpenGl programmer and I haven't really felt qualified. Most of my experiance has been either embedded or Win32, so I do feel qualified to weigh in on this issue. Even if it isn't strictly OpenGL, I'll argue that from what I can tell, finding good ways of representing object data is becoming increasingly important to this community. Witness the rise of Octrees, etc.

Before I try to defend access functions I'll weigh in on the struct vs. class issue: Under C++ the only difference between structs and classes is that a class's members are private by default, and a struct's are public. Take a look at the code generated and you'll see the same number of instructions generated. For reference, see The C++ Programming Language (Stroustrup, 10.2.8).
In defense of those who thought otherwise I'll mention that under C, structs are very different beasts. Also, early versions of the C++ spec. may not have realised the near-equivalency between structs and classes. Remember, it took 6 years for it to be finalised, and it was always a moving target. Every vendor had to make their "best guess" every time they released a new compiler prior to 1998. So it shouldn't be surprising that there are programmers who had bad experiances with some aspects of the language.

As a side note, the statement about Visual C++ and template classes is a perfect example. I know for a fact that prior to VStudio service pack 3 (about 1999, I think), overloaded template functions were simply unpredictable. I'm not aware of any C++ compliance issues under the current service pack, nor with Visual Studio 7, though I'd be willing to bet there are some.

Now for access functions: Yes, using access functions will result in a performance hit. However, *not* using them can result in unprotected data problems. Assume that snow_master's code is running in a multi-threaded environment. Or even if it isn't that his design is intended to accomodate that someday it will be. To protect access to shared data, the choice is between locking *all* of an objects data with a single call, or only locking the portion that is currently being accessed The difference is in the performance hit for locking the data and the potential for nasty context switches.

A single lock per object is a good choice when you will typically be accessing all of an objects data at once, because you will only have a single context switch between calls to lock(), and you will only have the overhead of one call to lock() per access. However, when you have a lot of threads, some of whom don't access all the data, then the time spent waiting for a resource to be unlocked can quickly become greater than the time you would have spent in multiple context switches/ calling lots of lock() unlock() methods.

Acess functions are a good choice when you have a logical object whose data is shared between multiple threads, but no thread requires access to the objects data in any particular order. for example, if you have a vertex object being shared among 3 threads who need to access X, Y, and Z, then coding can result in a system where X is read by thread 1, Y is read by thread 2, and Z is read by thread 3. Insert a fourth thread, and they would be waiting for X, Y, or Z to signal that it was unlocked ( See WaitForMultipleObjects(), for example).

I'm guessing that this is more convoluted than most OpenGL apps require. In fact I've seen several arguments that threading in general is bad for OpenGL.

All of this brings me to say - there are very few "right" or "wrong" ways to do things, period. I have yet to work on a system small enough to allow for a single dedicated thread rendering in an OpenGL window... too much of my data isn't available until I request it, and pausing rendering until it gets to me simply isn't an option. So I continually render the current view of the latest data while other threads are preparing new data as it arrives. This is particularly useful with shared texture resources. Don't go asking me for details just yet - I still have a lot of issues I'm working, and I'm sure there are better ways to do things. I may well be asking for help here before long, but my point is, I see a lot of statements like "Don't use threads" or "Don't use access functions", or "Don't use the STL". None of these are black & white issues, even under the constraints of OpenGL.

Whew. How's that for a first post?

-Chris Bond

knackered
04-10-2002, 10:57 AM
Very nice.
Eloquent, concise, informative, you didn't swear (always a plus point in here), with a measure of authority, without being arrogant.
I could learn a lot from you! http://www.opengl.org/discussion_boards/ubb/smile.gif
Welcome to the OpenGL Advanced Discussion Forum - full of sound and fury, signifying nothing (joke) http://www.opengl.org/discussion_boards/ubb/smile.gif

dorbie
04-10-2002, 12:08 PM
daveperman, what are you talking about?

I wasn't even discussing a diff between struct & class, but the fact you have it *at all*, and the fact that methods are used in the code.

That class to store vertex datatakes additional indirection. This was already pointed out by knackered and you completely missed the point.

I WAS saying that the accessing of the data is the issue. Nobody has even seen what is in those methods and mileage varys with different compilers. At least read the post & think before calling people names.

It takes a special kind of arrogance to say someone is "talking bull****" simply because the point out the real issue. What the heck is up around here? Is everyone taking testosterone injections or something?

Read the post by ChrisBond, learn and don't be so cheeky in future.

I still say knackered is right on some of the things he said on this. Although nobody seems to have taken to heart my point that this is building a display list so it doesn't matter much.


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

Rob The Bloke
04-10-2002, 12:32 PM
int CMy3DViewerCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);

if(SetWindowPixelFormat(hDC)==FALSE)
{
MessageBox("SetWindowPixelFormat Failed", "OpenGL Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

if(CreateViewGLContext(hDC)==FALSE)
{
MessageBox("CreateViewGLContext Failed", "OpenGL Error", MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Lights properties
float ambientProperties[] = { 0.2f, 0.2f, 0.2f, 1.0f};
float diffuseProperties[] = { 0.7f, 0.7f, 0.7f, 1.0f};
float specularProperties[] = { 0.0f, 0.0f, 0.0f, 1.0f};
float Position0Properties[] = {-5.0f, 1.0f, 1.0f, 0.0f};
float Position1Properties[] = { 5.0f, 1.0f, 1.0f, 0.0f};

// Not needed here, your display function will be called before the window
// becomes visible, this is pointless...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// ///////////////////////////////


glLightfv(GL_LIGHT0, GL_AMBIENT, ambientProperties);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularProperties);
glLightfv(GL_LIGHT0, GL_POSITION, Position0Properties);

glLightfv(GL_LIGHT1, GL_AMBIENT, ambientProperties);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseProperties);
glLightfv(GL_LIGHT1, GL_SPECULAR, specularProperties);
glLightfv(GL_LIGHT1, GL_POSITION, Position1Properties);



glShadeModel(GL_SMOOTH);

// ensuring unit length normals to begin with is more advantageous....
glEnable(GL_NORMALIZE);

// Any reason for setting the alpha in the framebuffer to 1 ?
glClearColor(m_ClearColorRed , m_ClearColorGreen , m_ClearColorBlue , 1.0f);




// WHYS THIS HERE? WOULD MAKE MORE SENSE IN AN OnSize() func
CRect rect;
GetClientRect(&amp;rect);
double aspect = (rect.Height() == 0) ? rect.Width() : (double)rect.Width()/(double)rect.Height();
gluPerspective(45, aspect, 0.1, 1000.0);

// /////////////////////////////////

// Default : lighting
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

glEnable(GL_DEPTH_TEST);

// Modulate : texture lighting
glEnable(GL_TEXTURE_2D);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);



// Are you wanting to draw font's with an orthographic projection?
// It may be worth using display lists to hold the commands to get into persp & orthographic views.
// Destroy them and then recreate them in your OnSize() func and then
// call them in your display func.
switch (fontLoad("..\\Data\\Font.tga"))
{
case FONT_FILE_NOT_FOUND:
MessageBox("File not found", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_IMAGE_TYPE:
MessageBox("Color mapped image or image is not uncompressed", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_DIMENSION:
MessageBox("Dimension is not a power of 2", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_BITS:
MessageBox("Image bits is not 8, 24 or 32", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
case FONT_BAD_DATA:
MessageBox("Image data could not be loaded", "Font File Error", MB_ICONERROR | MB_OK);
return FALSE;
}

return 1;
}

Tried to add a few initial thoughts on the code as comments. In terms of your alpha problem, it has to be due to using an alpha of 1. Could always use GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA and see if that works... (in which case your code is wrong)

The other possibility is that you either have driver issues with your hardware, or your hardware has some serious flaws (ie, very very old). Test it on a few more computers, to see if it's that, that is at fault. Realistically, it is likely to be your code that is at fault.

[This message has been edited by Rob The Bloke (edited 04-10-2002).]

WhatEver
04-10-2002, 06:56 PM
Sorry if there was an answer to this already. There was to many threads that were off topic so I skipped to my reply instead.

Blending checklist:
-Enable blending
-Set blending params
-Draw solid objects first then transparent
-Disable z writing for transparent objects
-Optional: enable front and back polys
-If you use glMaterial, call it with GL_DIFFUSE last...I'm thinking this may be part of your problem...I'm pretty sure that the last color param you enter is what glColor is effected by...at least that's how I remember it.

Did I miss anything?

Screenshot would better help us, help you.

snow_master
04-18-2002, 04:05 AM
Rob The Bloke, FINALY !!!
your suggestion about switching the src alpha and one minus src alpha worked!!!
Although, the object appears on a black background, and mostly transparent, in some angles seems opaque (when rotating the object), and even when I try to reduce (or increase) the alpha level of the transparent object, still the same.
Can you please explain me the problem since I am sure the alpha level is being passed as I wanted it to be (1.0 for the opaque and 0.5 for the transparent)
Thanks.

vs
04-19-2002, 01:25 AM
Alpha transparency in OPENGL.

In your GL setup code do the following:

1. PFD_TYPE_RGBA included in your pixelformatdescriptor //(allows alpha)

2. glEnable( GL_BLEND );
//(Turn alpha on)

3. glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ).
//(Set Alpha state)


Now in your render loop.

1. Draw all solid objects ( i.e. glColor4f( blah,blah,blah, 1.0f );

2. Depth sort all alpha objects.

3. glDepthMask( FALSE )
//turn of depth buffer

4. Draw all alpha objects in back to front order.

5. glDepthMask( TRUE )
//restore depth buffer

////////////////////////////////////
This always works. Its also in the RED book.

VS ):

mrbill
04-19-2002, 06:37 AM
Two places where things can "go wrong" as you've described.

First, during vertex processing.

Perhaps you've managed to turn on two sided lighting someplace, you need to worry about the back material properties. For debugging this case, change your glMaterial4fv(GL_FRONT,...) to glMaterial4fv(GL_FRONT_AND_BACK,...).

Second, during texturing.

Your fragment's alpha can get changed during texturing. For MODULATE with wraps, this can happen if your texture format is ALPHA, LUMINANCE_ALPHA, RGBA and the alpha is not 1.0, or for INTENSITY and the intensity is not 1.0. Turn off texturing to see if this is the issue, and then double check your glTexImage2D or glTexSubImage2d calls.

One last place to check is TEXTURE_BORDER_COLOR, just in case you managed to turn off wrap someplace. The default TEXTURE_BORDER_COLOR is 0,0,0,0.


-mr. bill

Phaedrus
04-21-2002, 09:13 AM
As far as I know, the alpha component of material diffuse reflectance is the bottom line when it comes to the transparancy of a lighted color. Put another way, only the diffuse material parameter alpha component is used in lighting calculations. I know that this is not a patch for your provided code, but hope that this detail helps to cull the list of likely suspects.

Rob The Bloke
04-21-2002, 09:36 PM
Originally posted by snow_master:
Rob The Bloke, FINALY !!!
your suggestion about switching the src alpha and one minus src alpha worked!!!
Although, the object appears on a black background, and mostly transparent, in some angles seems opaque (when rotating the object), and even when I try to reduce (or increase) the alpha level of the transparent object, still the same.
Can you please explain me the problem since I am sure the alpha level is being passed as I wanted it to be (1.0 for the opaque and 0.5 for the transparent)
Thanks.

The pixel format descriptor should have no effect in this case - it would only be of relevance if you were blending destination factors.

If changing the alpha values fails to work, then it may be your hardware. What graphics card are you using? have you tried the code on another computer? have you tried using the alpha test instead?

dorbie
04-22-2002, 06:19 AM
The conventional way to represent translucent transparent objects is source_alpha, 1-source_alpha, where alpha 0 = transparent and alpha 1 = opaque. The fact that this change works for you indicates something is up with your alpha. However I am puzzled, because the results should be decent with any reasonably transparent value. All you are really doing is inverting the alpha value.

With an alpha of say 0.5 the effects should be pretty much identical. I'm left thinking that maybe you are drawing the object multiple times or don't understand what you are seeing when alpha and depth buffer interract.

Either that or you do have a driver problem.

It realy does sound like you are drawing things more than once, otherwise this shouldn't really have worked well. Simply changing blendfunctions until it looks right is worrying to say the least. Did you try the alpha test and alpha ref suggestion I made?

You SHOULD have a firm understanding of what your alpha fragment values are by now.

How many times are you drawing the same transparent object each frame?

snow_master
04-22-2002, 07:30 AM
>>With an alpha of say 0.5 the effects >>should be pretty much identical. I'm left >>thinking that maybe you are drawing the >>object multiple times or don't understand >>what you are seeing when alpha and depth >>buffer interract.

the objects are being drawn exactly once.
first the opaque object (which is tube like) as a triangle strip with alpha value of 1.0.

then the transparent object is being drawn, which is the exact same mesh prototype just with different triangle data (like a tube around the first tube) and with alpha level of 0.5.

I have tested it on several computers with the same results, although I haven't re-tested including the one minus alpha switch and the new angles problem (on some angles the transparent object seems opaque)

I have tried the alpha test method.