On 07/30/2011 05:44 PM, Benoît Minisini wrote:
Le Samedi 30 Juillet 2011 00:19:41, Kevin Fishburne a écrit :
I've been researching this for hours and nothing I try works. The image
used for the texture has an alpha channel, but it is displayed as black
instead of transparent. I'm starting to think that the line:

Gl.TexImage2D(t1)

isn't passing the presence of an alpha channel to OpenGL, but that's
just a guess. Normally you specify the image format there, but those
parameters aren't supported yet in the gb3 implementation.

The project is attached. You can move the little wizard around with the
ASDW keys and rotate with the QE keys. Any help appreciated...I'm going
crazy and am calling it quits for the night

This is what i do in the sdl component to get alpha blending:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

So it should be in gambas3 code:

Gl.Enable(Gl.GL_BLEND)
Gl.BlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA)

++


If, in GltextureMapping.c:238:

        glTexImage2D(GL_TEXTURE_2D, VARGOPT(Level, 0), 3, image->width,
                image->height, VARGOPT(Border, 0), format, GL_UNSIGNED_BYTE,
                image->data);

I replace the "3" by "4", as it is in line 225, I get the transparency.

According to the documentation, this number is the number of color components
in the texture, which should be 4 for RGBA.

I suggest that this number should be 3 if the image format is RGB or BGR, and
4 if the image format is RGBA, RGBX, BGRA, tec.

Another point. I opened the file GLUtextureImage.c (searching for
GL.TexImage2D), and I noticed that GLUBUILD1DMIPMAPS use IMAGE_get to read its
image argument (which does error checking), but not GLUBUILD2DMIPMAPS, which
should lead to possible segfaults...

Interesting observations Benoît. I did get a segfault using Glu.Build2DMipmaps(), though I corrected it by moving the call. Was a strange error among many, which I'm still trying to correct. Mostly I think it's my faulty logic.

Tomek, who is having some trouble mailing the mailing list lately, helped me get the alpha channel working correctly. I don't understand the logic, but enabling the gb.opengl.glu component and adding the line "Glu.Build2DMipmaps(t1)" to the end of the texture setup code enabled the alpha channel. The final code looks like this:

‘ Set up texture.
Gl.BindTexture(Gl.GL_TEXTURE_2D, textures[0])
Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR)
Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR)
Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP)
Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP)
Gl.TexImage2D(t1)
Glu.Build2DMipmaps(t1)

No idea why the segfault occurred, but am glad I could work around it.

I attached my revised example project. I hope it can be included with the others in the OpenGL example compilation you mentioned. I added the appropriate comments at the beginning of the project, and further commented important lines throughout so it would be easy to understand. Enabling the alpha channel on a simple OpenGL 2D "blit" is a common requirement of many games.

--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: [email protected]
phone: (770) 853-6271

Attachment: gb3_opengl_texture_with_alpha_channel.tar.gz
Description: GNU Zip compressed data

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to