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. Android 2.0 Suppress local search on key event

One of my apps implements a search function which is invoked when the
user presses the Search button.
In 1.6, Android Quick Search Box can be suppressed by overriding
Activity.onKeyDown() and picking out KEY_SEARCH.
On Android 2.0, no more... Android's Quick Search pops up no matter
whether Activity.onKeyDown(), Activity.onKeyUp() is overridden, or
Activity.setDefaultKey(DEFAULT_KEYS_DISABLE) is set.

Has anybody had any luck getting rid of the Android Quick Search?

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

2. How to use external library in Android project

Eclipse provides an option to add the *.jar files in external libraries.

2009/10/29 Sj <soojung_h...@hanmail.net>



-- 
Shine bright,
(: Naveen Krishna Ch :)

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

3. Problem with writing on Bitmap

4. Why Android market is still bad news for devs ...

5. Including 3rd party jars in Android App

6. SDK r3 on Ubuntu 9.10

7. UnsatisfiedLinkError in Native Method