| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I've been struggling with getting my texture's transparent areas to be actually transparent, but they always appear black. I've searched and tried most the suggestions here in this forum and no luck (just doing a search for "transparency" gets a bunch of hits with a bunch of good solutions, but I just can't seem to get it to work for me). 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"); // 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); // 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(); } 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! |
|
#2
| |||
| |||
| "grayaii" <grayaii@gmail.com> wrote in message news:ab7f3ae6-e147-4e76-b675-8e400bd1e588@j22g2000hsf.googlegroups.com... > Hi, > I've been struggling with getting my texture's transparent areas to be > actually transparent, but they always appear black. > I've searched and tried most the suggestions here in this forum and no > luck (just doing a search for "transparency" gets a bunch of hits with > a bunch of good solutions, but I just can't seem to get it to work for > me). > > 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"); > > // 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); > > // 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(); > } > 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! Right idea, wrong texture environment function. I think you want MODULATE GL_TEXTURE_ENV_MODE . Enabling the alpha tests will determine how "sharp" (and where) the transition from opaque to transparent is, as there will be intermediate interpolated transparances between the two (when zoomed). -jbw jbw |
|
#3
| |||
| |||
| Thanks for the info jbw! I tried out your advice, but I still get the black color where my transparency should be. I double checked the png file with photoshop and gimp to make sure all is well, and it looks ok. My render function now looks like this: GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 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); GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); .... // draw texture 1, followed by drawing texture 2 ... If the render function is ok, could it be that the textures are being loaded incorrectly? I'm a bit suspicious of the following line: m_texture1 = new OpenGLTexture2D("myImage1.PNG"); But if I put a break point right after this line and examine the image data of m_texture1, it appears all is well. I'll continue to investigate, but if you or anyone has any more advice/ ideas, I'm all ears! |
|
#4
| |||
| |||
| 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
| |||
| |||
| mi76, thank you so much. You were right on target. I downloaded the source for csgl from http://csgl.sourceforge.net/ and sure enough when I stepped into the OpenGLTexture2D class I saw this: glTexImage2D(GL_TEXTURE_2D, 0, (int)GL_RGB8, image.Width, image.Height, IsBorder ? 1 : 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, tex.Scan0); (Notice the nasty GL_RGB8!!!) I simply changed it to GL_RGBA8, per your suggestion, re-compiled, and it worked like a charm! I can now get on with my life and tackle whatever problem arises next! |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.