OpenGL DrawTexture and Alpha

by Rittz » Fri, 02 Jul 2010 05:18:22 GMT


Sponsored Links
 Hello,

I've been working on moving from Canvas over to OpenGL using
GLSurfaceView and have hit a bit of a roadblock in trying to change
the alpha of a texture at runtime.  I can display the texture with
transparency just fine but changing the RGBA via glColor isn't doing
anything at all.  All I'm trying to do is fade in and out some
textures by changing the alpha value and I know it's possible because
I've seen it done before.  I get the feeling like I'm just missing one
line of code to fix this.

Here is the actual draw method for the object

public void draw(GL10 gl)
{
                gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureName);

                gl.glColor4f(1f, 1f, 1f, 0.5f); // No matter what I make these
values it doesn't change anything

                ((GL11) gl).glTexParameterfv(GL10.GL_TEXTURE_2D,
GL11Ext.GL_TEXTURE_CROP_RECT_OES, textureGrid, 0);
                ((GL11Ext) gl).glDrawTexfOES(x, y, z, width, height);
 }

and here is some of the initialization code, it's pretty much just
copied straight from the SpriteMethodTest example

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);

        gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
        gl.glShadeModel(GL10.GL_FLAT);
        gl.glDisable(GL10.GL_DEPTH_TEST);
        gl.glEnable(GL10.GL_TEXTURE_2D);

        gl.glDisable(GL10.GL_DITHER);
        gl.glDisable(GL10.GL_LIGHTING);

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT |
GL10.GL_DEPTH_BUFFER_BIT);

        // Load all the Textures
    }

    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);

        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrthof(0.0f, w, 0.0f, h, 0.0f, 1.0f);

        gl.glShadeModel(GL10.GL_FLAT);
        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA,
GL10.GL_ONE_MINUS_SRC_ALPHA);
        gl.glColor4f(1f, 1f, 1f, 1f);
        gl.glClearColor(1f, 1f, 1f, 1f);
        gl.glEnable(GL10.GL_TEXTURE_2D);
    }

Thanks in advance!

--



OpenGL DrawTexture and Alpha

by Lance Nanek » Fri, 02 Jul 2010 08:42:09 GMT


 You can try adding this:
gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Although I think it is the default and I don't see anything like this
turning it off in your posted code:
gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

Which is what I was expecting.




--


Sponsored Links


Other Threads

1. How selective are the Android Marketplace "police" in allowing our apps to be published?

There is no filter other than the terms of service (fairly standard, except
you can't gather money outside the market, or charge for updates. Give them
a read though..)





--~--~---------~--~----~------------~-------~--~----~

2. Android Silicon Valley MeetUp Ju ne 16th 鈥?Hosted by Motodev

Join us to discuss and encourage innovation on the Android platform.
Get the opportunity to explore how Android can be harnessed to build
new, enjoyable, and useful applications by exploiting the platform's
openness. Anyone from the curious to {*filter*} developers are welcome
to participate.  This event is hosted by Motodev (The Motorola
developer network) in Sunnyvale CA.

RSVP now at:  http://www.***.com/ 

Space is limited so sign up today!

Interested in presenting at this MeetUp?  Contact: atea...@gmail.com

--~--~---------~--~----~------------~-------~--~----~

3. AutoCompleteTextView in AlertDialog

4. wrong bootloader on dev G1

5. Android Market should allow app developer to respond to (unfair) comments

6. Synopsis of SearchManager

7. Listening to services