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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:35:57+00:00 2026-06-01T06:35:57+00:00

I found different Stackoverflow-Questons, but I don’t see what I’m doing wrong in my

  • 0

I found different Stackoverflow-Questons, but I don’t see what I’m doing wrong in my code, because the 2D “_floorhelper” texture doesn’t show up on the screen. I would like to used it as a HUD element:

Trying to use Ortho for drawing 2D

https://stackoverflow.com/questions/9406753/android-opengl-gluortho2d-keep-original-shape-of-an-object

Android – Draw 3D then 2D with openGL ES

this is my setup:

public void gameSetup(GameActivity activity, GL10 gl) {             
      _floorhelper = new Mesh( gl, 4, false, true, false );
      _floorhelper.texCoord(1, 1);
      _floorhelper.vertex(-1, 0, 1 );
      _floorhelper.texCoord(1, 0);
      _floorhelper.vertex(1, 0, 1 );
      _floorhelper.texCoord(0, 0);
      _floorhelper.vertex(1, 0, -1 );
      _floorhelper.texCoord(0, 1);
      _floorhelper.vertex(-1, 0, -1);

    try {
        InputStream is = getResources().openRawResource(getResources().getIdentifier("levels", "raw", getPackageName()));
        levelBitmap = BitmapFactory.decodeStream(is);
        levelTexture = new Texture(gl, levelBitmap, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
    }
    catch(Exception ex){
        System.out.print(ex.getMessage());
    }


    setTractFloor(gl);

    float[] lightColor = { 1, 1, 1, 1 };
    float[] ambientLightColor = { 0.0f, 0.0f, 0.0f, 1 };
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientLightColor, 0);
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightColor, 0);
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, lightColor, 0);
}
public void gameLoop(GameActivity activity, GL10 gl) {

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, activity.getViewportWidth(), activity.getViewportHeight());

    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable( GL10.GL_CULL_FACE );   

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    float aspectRatio = (float) activity.getViewportWidth() / activity.getViewportHeight();
    GLU.gluPerspective(gl, 67, aspectRatio, 1, 100);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, _scaleFactor, 5.0f, _scaleFactor, 0.0f, 0.0f, 0.0f, 0, 1, 0);             

    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnable(GL10.GL_LIGHT0);
    float[] direction = { 1.5f, 0.5f, 0, 0 };
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, direction, 0);
    gl.glEnable(GL10.GL_COLOR_MATERIAL);

    // rotation
    gl.glRotatef(135, 0, 1, 0);

    gl.glEnable(GL10.GL_LINE_SMOOTH);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA_SATURATE, GL10.GL_ONE);
    gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST); // no visible diff
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glColor4f(1, 1, 1, 1);

    // translation
    gl.glTranslatef(-_oldTouchY, 0, _oldTouchX);

    // render
    currentTractFloor.render(); 

    // Draw 2D ontop of 3D - floorhelper
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    GLU.gluOrtho2D(gl, 0.0f, (float) activity.getViewportWidth(), 0.0f, (float)activity.getViewportHeight());

    gl.glMatrixMode(GL10.GL_MODELVIEW);

    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glDisable(GL10.GL_DEPTH_TEST);

    gl.glDisable(GL10.GL_COLOR_MATERIAL);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    levelTexture.bind();
    _floorhelper.render(PrimitiveType.TriangleFan);

    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glPopMatrix();
    gl.glMatrixMode(GL10.GL_PROJECTION);        
    gl.glPopMatrix();
}

After the Answer of Stefan Hanke I found the solution.
I’ve defined the vertices in the mesh wrong. So I always saw just the side of the mesh….

Thanks to Stefan Hanke.

//* Solution Code

public void gameSetup(GameActivity activity, GL10 gl) {
    _floorhelper = new Mesh(gl, 4, false, true, false);
    _floorhelper.texCoord(0, 1);
    _floorhelper.vertex(50, 50, 0);
    _floorhelper.texCoord(1, 1);
    _floorhelper.vertex(1000, 50, 0);
    _floorhelper.texCoord(1, 0);
    _floorhelper.vertex(1000, 1000, 0);
    _floorhelper.texCoord(0, 0);
    _floorhelper.vertex(50, 1000, 0);

    try {
        InputStream is = getResources().openRawResource(getResources().getIdentifier("levels", "raw", getPackageName()));
        levelBitmap = BitmapFactory.decodeStream(is);
        levelTexture = new Texture(gl, levelBitmap, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
    }
    catch(Exception ex){
        System.out.print(ex.getMessage());
    }

    setTractFloor(gl);

    float[] lightColor = { 1, 1, 1, 1 };
    float[] ambientLightColor = { 0.0f, 0.0f, 0.0f, 1 };
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientLightColor, 0);
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightColor, 0);
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, lightColor, 0);
}

public void gameLoop(GameActivity activity, GL10 gl) {

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, activity.getViewportWidth(), activity.getViewportHeight());
    gl.glClearColor(0.18f, 0.68f, 1.0f, 1.0f);

    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_CULL_FACE );    

    setPerspective(activity, gl);

    GLU.gluLookAt(gl, getScaleFactor(), 5.0f, getScaleFactor(), 0.0f, 0.0f, 0.0f, 0, 1, 0);     

    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnable(GL10.GL_LIGHT0);
    float[] direction = { 1.5f, 0.5f, 0, 0 };
    gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, direction, 0);
    gl.glEnable(GL10.GL_COLOR_MATERIAL);

    // rotation
    gl.glRotatef(135, 0, 1, 0);

    gl.glEnable(GL10.GL_LINE_SMOOTH);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA_SATURATE, GL10.GL_ONE);
    gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST); // no visible diff
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glColor4f(1, 1, 1, 1);


    // translation
    gl.glTranslatef(-_oldTouchY, 0, _oldTouchX);


    // render
    currentTractFloor.render();

    // levels
    setOrtho2D(activity, gl);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    levelTexture.bind();        
    _floorhelper.render(PrimitiveType.TriangleFan);

    gl.glPopMatrix();
    gl.glMatrixMode(GL10.GL_PROJECTION);        
    gl.glPopMatrix();

}

private void setPerspective(GameActivity activity, GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    float aspectRatio = (float) activity.getViewportWidth() / activity.getViewportHeight();
    GLU.gluPerspective(gl, 67, aspectRatio, 1, 100);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
}

private void setOrtho2D(GameActivity activity, GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    // set ortho view
    gl.glOrthof(0.0f,(float) activity.getViewportWidth(), 0.0f, (float)activity.getViewportHeight(), -1.0f, 1.0f);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
}
  • 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-01T06:35:58+00:00Added an answer on June 1, 2026 at 6:35 am

    Looks like the matrix setup is incorrect. The meshes vertices all have y=0. With no ModelView matrix whatsoever, you will look at the front edge of the whole mesh. If you remove the second matrix setup from the code — as you did in your comment to Vincents post — , the ModelView will be a concoction of the previous gl* calls.

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

Sidebar

Related Questions

I know this has been asked before, but I've found a different way to
After searching stackoverflow.com I found several questions asking how to remove duplicates, but none
I see a lot of people have this problem, but none answer I found
I found there is questions asked in stackoverflow regarding this topic before but i
I've searched and searched stackoverflow and www, but have found no answers to this
I've been scouring the web and StackOverflow for an answer, but I've found no
While googling I found two different sets of headers that need to be set
I found out that I can use a different theme in an C# WPF
I've found a feature on two different websites that I'd like to include on
I've found a couple of different twitter gem (for ruby-on-rails) out there: http://twitter4r.rubyforge.org/ http://twitter.rubyforge.org/

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.