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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:49:47+00:00 2026-06-05T22:49:47+00:00

I am writing a game which uses opengles. I have created my renderer class

  • 0

I am writing a game which uses opengles. I have created my renderer class and have a sample of my game working on the emulator, however none of the texures display on an actual device. I have read about the most common cause for this being the need for texture to be a factor of 2 however I have tried drawing a square (128×128) with a texture of the same size mapped to it and this only shows on the emulator. Further to that my actual game will be using rectangles so I’m unsure how I can map textures that are squares to rectangles..
This is my code so far (The game is 2d so I’m using ortho mode):
EDIT: I have updated my code, it is now correctly binding textures and using textures of size 128×128, still only seeing textures on the emulator..

    public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
    byteBuffer = ByteBuffer.allocateDirect(shape.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    vertexBuffer = byteBuffer.asFloatBuffer();
    vertexBuffer.put(cardshape);
    vertexBuffer.position(0);

    byteBuffer = ByteBuffer.allocateDirect(shape.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    textureBuffer = byteBuffer.asFloatBuffer();
    textureBuffer.put(textureshape);
    textureBuffer.position(0);

    // Set the background color to black ( rgba ).
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    // Enable Smooth Shading, default not really needed.
    gl.glShadeModel(GL10.GL_SMOOTH);
    // Depth buffer setup.
    gl.glClearDepthf(1.0f);
    // Enables depth testing.
    gl.glEnable(GL10.GL_DEPTH_TEST);
    // The type of depth testing to do.
    gl.glDepthFunc(GL10.GL_LEQUAL);
    // Really nice perspective calculations.
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    loadGLTexture(gl);
}

public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glMatrixMode(GL10.GL_PROJECTION); // Select Projection
    gl.glPushMatrix(); // Push The Matrix
    gl.glLoadIdentity(); // Reset The Matrix
    gl.glOrthof(0f, 480f, 0f, 800f, -1f, 1f);
    gl.glMatrixMode(GL10.GL_MODELVIEW); // Select Modelview Matrix
    gl.glPushMatrix(); // Push The Matrix
    gl.glLoadIdentity(); // Reset The Matrix

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glLoadIdentity();
    gl.glTranslatef(card.x, card.y, 0.0f);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, card.texture[0]); //activates texture to be used now
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
    // Sets the current view port to the new size.
    gl.glViewport(0, 0, width, height);
    // Select the projection matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // Reset the projection matrix
    gl.glLoadIdentity();
    // Calculate the aspect ratio of the window
    GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f,
            100.0f);
    // Select the modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    // Reset the modelview matrix
    gl.glLoadIdentity();
}

public int[] texture = new int[1];

public void loadGLTexture(GL10 gl) {
    // loading texture
    Bitmap bitmap;
        bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image);
        // generate one texture pointer
        gl.glGenTextures(0, texture, 0); //adds texture id to texture array
        // ...and bind it to our array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); //activates texture to be used now
        // create nearest filtered texture
        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);
        // Use Android GLUtils to specify a two-dimensional texture image from our bitmap
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        // Clean up
        bitmap.recycle();
}

Is there anything I have done wrong? Or something I haven’t done? It works perfectly fine in the emulator so I could only assume it was the power of 2 issue but like I said I tried that using a 128×128 texture on a square but it didn’t show.. any help would be appreciated..

EDIT: I have also tried setting the minsdkversion is 3, loading the bitmap via an input stream bitmap = BitmapFactory.decodeStream(is), setting BitmapFactory.Options.inScaled to false, putting the images in the nodpi folder and then trying them in the raw folder.. any other ideas?

  • 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-05T22:49:51+00:00Added an answer on June 5, 2026 at 10:49 pm

    I’m actually looking for the solution to a similar problem right now. I think I might have a temporary fix for you, however.

    The problem appears to be that on the emulator the orthographic view is flipped. To solve this, in my app we added an option in preferences to manually flip the view if nothing draws. Here’s the snippet that handles this:

    if (!flipped)
    {
        glOrthof(0, screenWidth, screenHeight, 0, -1, 1); //--Device
    }
    else
    {
        glOrthof(0, screenWidth, 0, -screenHeight, -1, 1); //--Emulator
    }
    

    Hope this helps! If anybody has a more general solution, I’d be happy to hear it!

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

Sidebar

Related Questions

I have been writing an OpenGL game engine for a while which uses SDL
I am writing a game engine/library in which I have an event dispatcher class
I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER.
I'm writing a game which uses 3D models to draw a scene (top-down orthographic
I have this game I'm writing with the jQuery Collision, and it uses keyboard
I am writing a scriptable game engine, for which I have a large number
I'm writing an Android game which uses an AsyncTask when the app starts to
I am writing a game which when given a partially filled word, searches a
I'm writing a game in which a thread - GameThread - loops forever, updating
I am writing a Facebook application that is a simple board game which I

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.