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

  • Home
  • SEARCH
  • 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 6038717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:15:46+00:00 2026-05-23T06:15:46+00:00

I’m doing my first steps in OpenGL for Android, for developing Augmented Reality apps

  • 0

I’m doing my first steps in OpenGL for Android, for developing Augmented Reality apps and I’m having a bad time integrating OpenGL shapes in front of the camera image. The program is supposed to draw a square in the XZ plane (assuming that Z axis is pointing up) over the camera image, but I’m getting two squares and they are smaller than if I don’t use the camera.

Here’s a bit of code.

In the main activity, I set the views and sensors like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Create an Instance with this Activity
    glSurface = new GLSurfaceView(this);
    //Set our own Renderer
    MyRenderer renderer = new Lesson02();
    glSurface.setRenderer(renderer);
    glSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT);

    //Set the GLSurface as View to this Activity
    setContentView(glSurface);

    mCameraView = new CameraView(this);
    addContentView(mCameraView, new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    List<Sensor> listSensors = mSensorManager
            .getSensorList(Sensor.TYPE_ACCELEROMETER);
    if (listSensors.size() > 0) {
        mSensorManager.registerListener(renderer,
                listSensors.get(0), SensorManager.SENSOR_DELAY_UI);
    }

    listSensors = mSensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    if (listSensors.size() > 0) {
        mSensorManager.registerListener(renderer,
                listSensors.get(0), SensorManager.SENSOR_DELAY_UI);
    }
}

The onDraw method of my renderer do something like this:

public void onDrawFrame(GL10 gl) {
    // Get rotation matrix from the sensor
    SensorManager.getRotationMatrix(rotationMatrix, null,
                                    mAccelerometerValues, mMagneticValues);
    // As the documentation says, we are using the device as a compass in
    // landscape mode
    SensorManager.remapCoordinateSystem(rotationMatrix,
                                        SensorManager.AXIS_Y, 
                                        SensorManager.AXIS_MINUS_X,
                                        remappedRotationMatrix);

    //Clear Screen And Depth Buffer
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Load remapped matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    //Reset The Current Modelview Matrix
    gl.glLoadIdentity();    
    gl.glLoadMatrixf(remappedRotationMatrix, 0);

    // Draw square
    gl.glTranslatef(-1.2f, 18.0f, 0.0f);
    //gl.glTranslatef(0.0f, -1.2f, -6.0f);  //Move down 1.2 Unit And Into The Screen 6.0
    square.draw(gl);                        //Draw the square
}

Finally, I inicialize everything within the onSurfaceCreated method like this:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {       
    gl.glShadeModel(GL10.GL_SMOOTH);            //Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);            //Black Background
    gl.glClearDepthf(1.0f);                 //Depth Buffer Setup
    gl.glEnable(GL10.GL_DEPTH_TEST);            //Enables Depth Testing
    gl.glDepthFunc(GL10.GL_LEQUAL);             //The Type Of Depth Testing To Do

    /*
     * By default, OpenGL enables features that improve quality but reduce
     * performance. One might want to tweak that especially on software
     * renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here probably based
     * on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
}

If I comment the line

glSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT);

within the activity it draws the square good and smooth, and only once. But when I make it translucent or even transparent, it draws two smaller squares that are not well-drawn when I spin the mobile.

If anyone knows what’s going on, it’d be very appreciated.

Thanks!!

  • 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-23T06:15:47+00:00Added an answer on May 23, 2026 at 6:15 am

    Just found out the solution looking at the demos. Within my main activity, I need to set the EGL configuration chooser. Something like this should be written in the onCreate method of the main activity (in which I add the opengl view and the camera view):

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            //Create an Instance with this Activity
            glSurface = new GLSurfaceView(this);
            // We want an 8888 pixel format because that's required for a 
            //translucent window. And we want a depth buffer. 
            glSurface.setEGLConfigChooser(8, 8, 8, 8, 16, 0);  // <-- NEW LINE ADDED
            //Set our own Renderer
            MyRenderer renderer = new MyRenderer ();
            glSurface.setRenderer(renderer);
            glSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
            //Set the GLSurface as View to this Activity
            setContentView(glSurface);
    
            mCameraView = new CameraView(this);
            addContentView(mCameraView, new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
    
                    // More code ...
    }
    

    Apparently, that line is necessary for having a translucent opengl window.

    • 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
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.