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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:31:34+00:00 2026-06-14T04:31:34+00:00

I’m working on a simple pong type game to get to grips with opengl

  • 0

I’m working on a simple pong type game to get to grips with opengl and android, and seem to have hit a brick wall in terms of performance.

I’ve got my game logic on a separate thread, with draw commands sent to the gl thread through a blocking queue. The problem is that I’m stuck at around 40fps, and nothing I’ve tried seems to improve the framerate.

To keep things simple I set up opengl with:

GLES20.glDisable(GLES20.GL_CULL_FACE);
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
GLES20.glDisable(GLES20.GL_BLEND);

Set up of the opengl program and drawing is handled by the following class:

class GLRectangle {
private final String vertexShaderCode =
        "precision lowp float;" +
        // This matrix member variable provides a hook to manipulate
        // the coordinates of the objects that use this vertex shader
        "uniform lowp mat4 uMVPMatrix;" +

        "attribute lowp vec4 vPosition;" +
        "void main() {" +
        // the matrix must be included as a modifier of gl_Position
        "  gl_Position = vPosition * uMVPMatrix;" +
        "}";

private final String fragmentShaderCode =
        "precision lowp float;" +
        "uniform lowp vec4 vColor;" +
        "void main() {" +
        "  gl_FragColor = vColor;" +
        "}";

protected static int mProgram = 0;

private static ShortBuffer drawListBuffer;
private static short drawOrder[] = { 0, 1, 2, 0, 2, 3};//, 4, 5, 6, 4, 6, 7 }; // order to draw vertices

// number of coordinates per vertex in this array
private static final int COORDS_PER_VERTEX = 3;
private static final int vertexStride = COORDS_PER_VERTEX * 4; // bytes per vertex



GLRectangle(){

    int vertexShader = GameRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = GameRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram();             // create empty OpenGL ES Program
    GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);                  // creates OpenGL ES program executables

    // initialize byte buffer for the index list
    ByteBuffer dlb = ByteBuffer.allocateDirect(
    // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);  
}

protected static void Draw(Drawable dObj, float mvpMatrix[])
{   
    FloatBuffer vertexBuffer = dObj.vertexBuffer;

    GLES20.glUseProgram(mProgram);
    //GameRenderer.checkGlError("glUseProgram");

    // get handle to fragment shader's vColor member
    int mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
    //GameRenderer.checkGlError("glGetUniformLocation");

    // get handle to shape's transformation matrix
    int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    //GameRenderer.checkGlError("glGetUniformLocation");

    // get handle to vertex shader's vPosition member
    int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    //GameRenderer.checkGlError("glGetAttribLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    //GameRenderer.checkGlError("glUniformMatrix4fv");

    // Set color for drawing the quad
    GLES20.glUniform4fv(mColorHandle, 1, dObj.color, 0);
    //GameRenderer.checkGlError("glUniform4fv");

    // Enable a handle to the square vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    //GameRenderer.checkGlError("glEnableVertexAttribArray");

     // Prepare the square coordinate data
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                    GLES20.GL_FLOAT, false,
                                    vertexStride, vertexBuffer);
    //GameRenderer.checkGlError("glVertexAttribPointer");

    // Draw the square
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
                              GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
    //GameRenderer.checkGlError("glDrawElements");

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    //GameRenderer.checkGlError("glDisableVertexAttribArray");
}
}

I’ve done plenty of profiling and googling, but cant find anything to make this work faster… I’ve included a screenshot of the DDMS output:

DDMS Output

To me, it looks like glClear is causeing GLThread to sleep for 23ms… though I doubt that’s really the case.

I have absolutely no idea how I can make this more efficient, there’s nothing fancy going on. In my quest for better rendering performance I have switched to the multi-threaded approach I described, turned off alpha blending and depth testing, changed to a batched drawing approach (not applicable for this simple example), and switched everything to lowp in the shaders.

Any assistance with getting this to 60fps would be greatly appreciated!

Bruce

edit Well talk about overthinking a problem. It turns out that I’ve had the powersaving mode switched on for the past week… it seems to lock rendering to 40fps.

  • 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-06-14T04:31:36+00:00Added an answer on June 14, 2026 at 4:31 am

    This behavior occurs when Power Saving mode is switched on, using a Galaxy S3.

    It appears the power saving mode locks the framerate to 40fps. Switching it off easily achieved the desired 60fps.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.