Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:03:22+00:00 2026-05-24T05:03:22+00:00

I’m porting a game from WP7 XNA to Android; everything was working using Canvas

  • 0

I’m porting a game from WP7 XNA to Android; everything was working using Canvas but it was too slow so I’ve switched to OpenGL ES, following the examples of Replica Island and SpriteMethodTest.

My problem is that my textures aren’t being coloured or made transparent when I set glColor immediately before drawing the texture – it is completely ignored and the texture is drawn in the state it was loaded. All the colour and transparency information inherent in the texture itself is applied correctly. I’m also generating some bitmaps programatically using setPixels and I have exactly the same issue there.

I’m still at the “OpenGL is just magic spells” stage of understanding 🙁 which makes following the existing documentation, which seems to be aimed at mid- or high-level coders, rather frustrating. I’d hoped that copy/pasting from those samples would work, but I must have missed something and I can’t work out what it is. I’ve got to the point where I’m code-blind and can’t tell the difference between their code and mine.

glColor4 clearly works in Replica Island, when I run that in the same emulator all the text fades in and out when the opacity changes, just as it should. But it doesn’t work in my code 🙁

Here is my GL initialisation code:

surfaceCreated:

    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
    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.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

sizeChanged:

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(0.0f, width, 0.0f, height, 0.0f, 1.0f);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glShadeModel(GL10.GL_FLAT);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL10.GL_TEXTURE_2D);

I commented out disabling Dither and Lighting in case that was it… but no. It makes no difference.

Bitmaps are loaded from resources thus:

    gl.glGenTextures(1, mTextureNameWorkspace, 0);
    textureName = mTextureNameWorkspace[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, srcBitmap, 0);

And finally my draw code:

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, crop(src), 0);
    gl.glColor4f(tint.R(), tint.G(), tint.B(), tint.A());
    ((GL11Ext) gl).glDrawTexfOES(dst.left, screenHeight - dst.bottom, 0.0f, dst.width(), dst.height());

The range of the tint members is 0.0..1.0 as it should be. If I set an invalid texture:

    gl.glBindTexture(GL10.GL_TEXTURE_2D, -1);

…then OpenGL obligingly draws rectangles of the right shade and opacity in the right location.

I must have tried every combination of possible parameters for glBlendFunc – some of them partly affect the transparency, but none of them work properly and none of them cause the glColor tint to have any effect.

All I’m trying to do is the equivalent of:

    PorterDuff.Mode mode = PorterDuff.Mode.MULTIPLY;
    if (tint.A() < 1.0f && tint.R() == 1.0 && tint.G() == 1.0
            && tint.B() == 1.0)
        mode = PorterDuff.Mode.DST_IN;
    Paint paint = new Paint();
    PorterDuffColorFilter cf = new PorterDuffColorFilter(tint, mode);
    paint.setColorFilter(cf);
    canvas.drawBitmap(texture.bitmap, srcRect, dstRect, Paint(tint));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:03:22+00:00Added an answer on May 24, 2026 at 5:03 am

    Instead of using GL_REPLACE, change the third argument of your glTexEnvf() function to GL_MODULATE.

    I’ll refer to my earlier answer from today.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.