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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:26:19+00:00 2026-05-27T18:26:19+00:00

I’m trying to render a simple square in OpenGl on Android. The same code

  • 0

I’m trying to render a simple square in OpenGl on Android. The same code behaves correctly on real devices, but on the emulator the square is deformed. This only happens when I use high zFar value (in this example it’s zNear = 80000, zFar = 80100) and does not depend on distance between zNear and zFar. Depth test is disabled, so I don’t think it has anything to do with the depth buffer.

This is how it looks on a real device:

http://imgur.com/9246P

And this is how it looks on an emulator.

http://i.imgur.com/L0IKv.png

When the square is rotating the deformations become more visible, and at some point the square disappears and then reappears again.

I know that the emulator uses a different implementation of OpenGl, maybe it’s a bug?
Does anybody know why it’s behaving like this?

public class SquareTestActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        GLSurfaceView glView = new GLSurfaceView(this);
        glView.setRenderer(new SquareRenderer());

        setContentView(glView);
    }

    public class SquareRenderer implements Renderer {
        private final float[] verts = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f };
        private final int nrOfVerts = verts.length / 3;
        private FloatBuffer vertBuf;

        private float rotation;

        public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
            gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

            gl.glDisable(GL10.GL_DEPTH_TEST);

            gl.glColor4f(1, 0, 0, 1);

            ByteBuffer byteBuffer = ByteBuffer.allocateDirect(verts.length * Float.SIZE / 8);
            byteBuffer.order(ByteOrder.nativeOrder());
            vertBuf = byteBuffer.asFloatBuffer();
            vertBuf.put(verts);
            vertBuf.position(0);
        }

        public void onSurfaceChanged(GL10 gl, int width, int height) {
            gl.glViewport(0, 0, width, height);

            gl.glMatrixMode(GL10.GL_PROJECTION);
            gl.glPushMatrix();
            gl.glLoadIdentity();
            GLU.gluPerspective(gl, 90, (float) width / height, 80000, 80100);
            gl.glMatrixMode(GL10.GL_MODELVIEW);
        }

        public void onDrawFrame(GL10 gl) {
            gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

            gl.glLoadIdentity();
            GLU.gluLookAt(gl, 0, 0, 80050, 0, 0, 0, 0, 1, 0);
            gl.glRotatef(rotation, 0, 0, 1);
            gl.glScalef(80000, 80000, 1);

            gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuf);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, nrOfVerts);

            rotation ++;
        }
    }
}

Thanks in advance.

  • 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-27T18:26:20+00:00Added an answer on May 27, 2026 at 6:26 pm

    I reproduced the effect from your code, and the problem goes away if you divide all of those 80000-ish numbers by 10. I suspect that the emulator’s OpenGL implementation is using fixed-point arithmetic internally, which would cause it to struggle with numbers that big. If it uses the glFixed format (S15.16), it will not be able to handle numbers greater than 32768.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
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 need to clean up various Word 'smart' characters in user input, including but

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.