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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:13:52+00:00 2026-05-27T23:13:52+00:00

I’ve tried a simple program that dynamically generates a texture and map it to

  • 0

I’ve tried a simple program that dynamically generates a texture and map it to a quad using NDK. Everything is fine on an emulator but failed on real devices.
Here is my code:

private static class Renderer implements GLSurfaceView.Renderer
{
    @Override
    public void onDrawFrame(GL10 gl)
    {
        nativeDrawFrame();
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height)
    {
        nativeInit(width, height);
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config)
    {
        // do nothing...
    }
}

and the native code:

const static GLfloat vertices_f[4][2] = 
{
    { 0.0f,    0.0f },
    { 100.0f,    0.0f },
    { 100.0f,    100.0f },
    { 0.0f,    100.0f }
};

const static GLfloat texCoords_f[4][2] = 
{
    { 0.0f,    0.0f },
    { 1.0f,    0.0f },
    { 1.0f,    1.0f },
    { 0.0f,    1.0f }
};

JNIEXPORT void JNICALL Java_com_sangfor_gltest_GLView_nativeInit(JNIEnv * env, jobject obj, jint width, jint height)
{
    if (!bitmap)
    {
        // allocate dynamic texture memory
        bitmap = memalign(16, 1024*1024);
        if (!bitmap)
        {
            __android_log_print(ANDROID_LOG_ERROR, "native-render", "failed allocation.");
            return;
        }
    }

    glViewport(0, 0, width, height);
    //glMatrixMode(GL_PROJECTION);
    //glLoadIdentity();
    //glOrthox(0, 0x10000, 0, 0x10000, 0x10000, -0x10000);
    //glClearColorx(0, 0, 0, 0);
    glGenTextures(1, &texture);
    __android_log_print(ANDROID_LOG_INFO, "native-render", "texture = %d", texture);
    // glVertexPointer(2, GL_FIXED, 0, vertices);
    // glTexCoordPointer(2, GL_FIXED, 0, texCoords);
    //glEnableClientState(GL_COLOR_ARRAY);
    glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glDisable(GL_ALPHA_TEST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}

JNIEXPORT void JNICALL Java_com_sangfor_gltest_GLView_nativeDrawFrame(JNIEnv * env, jobject obj)
{
    struct timeval tv;
    unsigned char color_value;

    glClear(GL_COLOR_BUFFER_BIT);

    // fill texture according to current timestamp
    gettimeofday(&tv, NULL);
    color_value = (unsigned char)(tv.tv_usec * 0.000255f);
    memset(bitmap, color_value, 1024*1024);
    __android_log_print(ANDROID_LOG_INFO, "native-render", "color_value = %d", color_value);

    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, bitmap);

    glBindTexture(GL_TEXTURE_2D, texture);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    glTexCoordPointer(2, GL_FLOAT, 0, texCoords_f);
    glVertexPointer(2, GL_FLOAT, 0, vertices_f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glFlush();
}

On an emulator it just works as I expected: an area on the screen keeps changing its color.
However, when I run it on real devices (Samsung Galaxy S 2.3.3 and Asus Transformer TF101 3.2.1), it just show a white block and texture mapping seems not working.

I tried add and comment out projection transform, enable texture mapping by calling glEnable(GL_TEXTURE_2D), disable alpha blending and testing by calling glDisable(...), move glBindTexture and glTexImage2D to init function, change texture size to 32 x 32 but none of these work.

Can anyone help me figure out why texture mapping fails just on real devices? Is there a GPU limitation or something?

EDIT: I’ve tried Spoon’s suggestion and found the real problem. No matter which texture I bind, the device uses texture named 0 to render quads, so glBindTexture(GL_TEXTURE_2D, 0) works fine but glBindTexture(GL_TEXTURE_2D, 1) and anything returned by glGenTextures(...) fails. This means I can save only one texture, but I have to use 2 or more.

  • 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-27T23:13:53+00:00Added an answer on May 27, 2026 at 11:13 pm

    White block means texturing is working but the textures haven’t loaded properly.

    If the actual mapping were a problem, you would see the textures but all the colours warped or messed up.

    Check the actual values given by glGenTextures(). I found that when using openGL-es 1.x on later versions of android (2.2+) that glGenTextures() threw out some really random numbers rather than giving id’s of 0,1,2,3 etc. It may be you have to manually supply your own ID’s and not use glGenTextures()

    Alternatively, check the pixel data is being correctly loaded from file. Blank white textures may appear if you have a filename wrong or file missing but have put in some error handling that allows the app to continue. And/or don’t forget to refresh res folders or even clean the project when you add new textures

    UPDATE:

    This is how I did it:

    public class Texture{
    
    private int textureId = -1;
    // initialise to -1
    
    public int getTextureId(){
        return textureId;
    }
    
    public void loadTexture(GL10 gl, Context context){
    
        String[] filenamesplit = filename.split("\\.");
    
        name = filenamesplit[filenamesplit.length-2];
    
        int[] textures = new int[1];
        //Generate one texture pointer...
        //GLES20.glGenTextures(1, textures, 0);             
        textures[0] = ((IridianGraphicsEngine)context).texturecount;
        ((IridianGraphicsEngine)context).texturecount++;
    
        //...and bind it to our array
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    
        //Create Nearest Filtered Texture
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    
        //Different possible texture parameters, e.g. GLES20.GL_CLAMP_TO_EDGE
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
    
        Bitmap bitmap = FileUtil.openBitmap(name, context);
    
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    
        bitmap.recycle();   
    
        textureId = textures[0];
    
    }
    }
    

    Then when drawing:

    public class Mesh{
    
    private Texture texture;
    
    public void draw(GL10 gl){
    
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    
        // Pass the vertex buffer in
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0,
                                 vertices);
    
        int textureId = texture.getTextureId();
    
        if(textureID>=0){
    
            // Enable Textures
            gl.glEnable(GL10.GL_TEXTURE_2D);
    
            // Get specific texture.
            gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID);
    
            // Use UV coordinates.
            gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    
            // Pass in texture coordinates          
            gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureCoordinates);
    
        } 
    
        // Pass in vertex normals
        gl.glNormalPointer(GL10.GL_FLOAT, 0, normals);
    
        gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    
        gl.glDrawElements(GL10.GL_TRIANGLES, numindices,GL10.GL_UNSIGNED_SHORT, indices);
    
        gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
    
        if(textureID>=0){
            // Disable buffers          
            gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        }
    
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    
    }
    

    This however is all in java and uses a weird mix of opengl-es 2.0 for texture loading and opengl-es 1.1 for drawing

    • 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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.