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 6703085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:07:48+00:00 2026-05-26T07:07:48+00:00

I’m attempting to add an overlay to an Android opengl ES application, and am

  • 0

I’m attempting to add an overlay to an Android opengl ES application, and am currently specifying an ImageView and working off code from SurfaceViewOverlay API Demo, effectively merging two applications I wrote, one that was canvas based and one with opengl ES.

Due to merging two projects there was a large amount of copy paste involved and which lead to me accidentally using a null surface holder. Surprisingly this worked but threw a large number of warnings. Changing it to the surface holder of the opengl panel however causes the application to hang and not display either content from opengl or ImageView.

I played around with the code to make sure I wasn’t initializing anything else where and confirmed the behavior on both a HTC Desire and Samsung Galaxy (both running 2.2)

Canvas c = null;
SurfaceHolder surfaceHolder2D = null; // this works but throws occational Null Pointer exceptions on the first canvas.drawText
//SurfaceHolder surfaceHolder2D = rsurfaceHolder; // this locks the application. 
//rsurfaceHolder is initialized with getHolder() in the opengl class and this worked with both when they where separate. 
//The change to ImageView was to get around issues with multiple SurfaceViews in an application having indeterminate Z order

try
{
    if (Global.RUNNING == 1)
    {
        c = surfaceHolder2D.lockCanvas(null); // when canvas is null this line can be ommited and it still works
        synchronized (surfaceHolder2D)
        {
            rpanel2D.onDraw(c);
        }
    }
    else
        sleep(1000);
}
catch (Exception e)
{
    e.printStackTrace();
}
finally
{
    if (c != null)
    {
        surfaceHolder2D.unlockCanvasAndPost(c);
    }
}

So what on earth is going on and what would be the correct way of performing this? I’m assuming that when I’m writing to a null canvas the compiler is doing something and sending it to the correct location regardless.

Leaving it as is, is not really an option, for several reason including not trusting that this will work across multiple versions of android, it flooding the logs with a constant stream of warnings with a significant frame rate drop and it only works if onDraw is invalidated on each call.

As for the onDraw function this simply is using canvas.drawText with a this.invalidate()

Curiously creating a new canvas and drawing to that and trying to invalidate or using setImageResource (either with a new or null) throws a “CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views” but not when drawing to a null canvas. In response I moved this to be called from the openGL thread however although this works for a few seconds, soon after the ImageView stops updating. It’s on draw is still being called since a counter I placed in there to confirm it is incremented even though the display isn’t. Hiding and unhiding the overlay results in it working again for a few seconds.

Any help would be greatly appreciated. If I’m on the wrong track completely please let me know. My alternative is to render this to BMP, create a new texture and draw it to a quad, but I imagine that would cause issues with thousands of textures created a minute.

Thanks in advance. -K

  • 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-26T07:07:49+00:00Added an answer on May 26, 2026 at 7:07 am

    I am not sure what you are trying to achieve – wouldn’t it be better if both renderings were done using OpenGL? Assuming that there is no other way, I would advice to create a FrameLayout and add the two views to it (GLSurfaceView and ImageView). If you need to change UI elements you have to do it from the UI Thread, changing elements ftom the GL Thread would cause an error; so be sure and do any change inside runOnUiThread Runnable.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.