Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Graphics > OpenGL 3D API > Re: Another Tra...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 4891 of 5041
Post > Topic >>

Re: Another Transparency Problem using png

by mi76 <mi333@[EMAIL PROTECTED] > Aug 28, 2008 at 01:01 AM

grayaii wrote:

> In a nutshell, here is what I'm doing (I'm using C# with CsGL):
> // Init my textures:
> CsGL.OpenGL.OpenGLTexture2D m_texture1;
> CsGL.OpenGL.OpenGLTexture2D m_texture2;
> m_texture1 = new OpenGLTexture2D("myImage1.PNG");
> m_texture2 = new OpenGLTexture2D("myImage2.PNG");
Check glTexImage2D function in your OpenGLTexture2D class has
RGBA/RGBA8 and not RGB/RGB8 parameters.
> 
> // Draw my textures:
> public void Render()
> {
> 	GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
> 	GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
> 
>         GL.glEnable(GL.GL_BLEND);
>         GL.glDisable(GL.GL_DEPTH_TEST);
>         GL.glEnable(GL.GL_ALPHA_TEST);
> 
>         GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
> 
>         // Some of the different things I've tried:
>         //GL.glColor4f(1.0f, 0.0f, 1.0f, 1.0f);
> 
>         //GL.glAlphaFunc(GL.GL_GREATER, 0.0f);
>         //GL.glAlphaFunc(GL.GL_NOTEQUAL, 1.0f);
>         //GL.glDisable(GL.GL_ALPHA_TEST);
> 
>         //GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,
> GL.GL_COMBINE_ARB);
>         //GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_COMBINE_RGB_ARB,
> GL.GL_ADD);

GL_COMBINE_ARB is an extension (GL_ARB_texture_env_combine) and it is 
rather complicated. But it is very fast. You have to set up sources, 
operands and functions (up to 3, i believe) for both - color and alpha 
final values. Yor say "add colors" but what are sources and operands?
It looks like, for example
*************************************************************
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE3);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
**************************************************************

lTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
>        // Draw texture1:
>        m_texture1.Bind()
>        GL.glBegin(GL.GL_QUADS);
>        ... the ususal glTexCoord2f and glVertex2f code ...
>        GL.glEnd();
> 
>        // Draw texture2:
>        m_texture2.Bind()
>        GL.glBegin(GL.GL_QUADS);
>        ... the ususal glTexCoord2f and glVertex2f code ...
>        GL.glEnd();
> }
Without multitexture better use simply
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


> I've tried a bunch of different combinations  of glAlphaFunc,
> glTexEnvf, and glColor4f (I left some commented out...), but the
> transparent areas of the png files always show up as black.  I would
> expect that when texture2 is drawn, I'd be able to see texture1 under
> it.
> 
> I would like to take advantage of png's alpha channel, and NOT use bmp
> files. I feel I'm soooo close to a solution, but after a week of
> banging my head and trying different things I feel I need to post
> here.
> Thanks in advance!
 




 5 Posts in Topic:
Another Transparency Problem using png
grayaii <grayaii@[EMAI  2008-08-27 08:20:44 
Re: Another Transparency Problem using png
"jbwest" <jb  2008-08-27 10:40:55 
Re: Another Transparency Problem using png
grayaii <grayaii@[EMAI  2008-08-27 11:31:01 
Re: Another Transparency Problem using png
mi76 <mi333@[EMAIL PRO  2008-08-28 01:01:30 
Re: Another Transparency Problem using png
grayaii <grayaii@[EMAI  2008-08-27 18:03:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 0:07:58 CST 2008.