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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:57:16+00:00 2026-05-19T04:57:16+00:00

assuming that some opengl-veterans might facepalm now :-) I am working on a tilebased

  • 0

assuming that some opengl-veterans might facepalm now 🙂

I am working on a tilebased game (2D only) on android with open gl es.

After days of introducing myself into the concepts of opengl basics, I still don’t know how to keep the relation between object and screen size.

To be concrete: My mobile display has 480×800 pixels. When I specify the simple square with its following dimensions, it fills the whole screen (?):

object-vertices:

float vertices[] = { -1.0f, -1.0f, 0.0f, // 0, Top Left
    1.0f, -1.0f, 0.0f, // 1, Bottom Left
    1.0f, 1.0f, 0.0f, // 2, Bottom Right
    -1.0f, 1.0f, 0.0f // 3, Top Right
};

short[] indices = { 0, 1, 2, 2, 3, 0 };

onSurfaceCreated:

   public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {

gl.glMatrixMode(GL10.GL_PROJECTION);

    gl.glLoadIdentity();
    gl.glEnable(GL10.GL_BLEND);

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

    GLU.gluOrtho2D(gl, 0, Shared.dm.widthPixels, Shared.dm.heightPixels, 0);

onDrawFrame:

   @Override
    public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    // Replace the current matrix with the identity matrix
    gl.glLoadIdentity();

    //Move this only
    gl.glPushMatrix();
    Log.d(Shared.LOGTAG, "X: " + offset.x + "Y: " + offset.y);
    gl.glTranslatef(offset.x, offset.y, 0);
    root.draw(gl);
    gl.glPopMatrix();
    }

Can anyone give me a hint into the right direction? I assume it has something to do with the matrices?

  • 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-19T04:57:17+00:00Added an answer on May 19, 2026 at 4:57 am

    Typical, misconception done by OpenGL newbies: They think there is some kind of “one time projection initialization”.

    You normally setup the whole requires OpenGL state anew everytime you start drawing things. This also catches mishaps like accidently overwriting projection matrices.

    onSurfaceCreated:

    public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
        // Just upload textures and shaders here.
    

    onDrawFrame:

    @Override
    public void onDrawFrame(GL10 gl) {
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    
        // set everything just right before you need it
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluOrtho2D(gl, 0, Shared.dm.widthPixels, Shared.dm.heightPixels, 0);
    
        // order in which different matrices are set is not important,
        // but order in which each matrix is manipulated is!
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
    
        // enable and configure blending on a as-needed base
        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        gl.glShadeModel(GL10.GL_FLAT);
        gl.glEnable(GL10.GL_TEXTURE_2D);
    
        //Move this only
        // make sure this is operating really on the modelview matrix
        // redundant in this rather simple example, but in large codebases
        // inevitable.
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glPushMatrix();
        Log.d(Shared.LOGTAG, "X: " + offset.x + "Y: " + offset.y);
        gl.glTranslatef(offset.x, offset.y, 0);
        root.draw(gl);
        gl.glPopMatrix();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming some logic that deals with measure units and the user is asked to
Assuming you had some kind of factory-created resource that would still belong to the
What does the following line actually do? string = @Some text; Assuming that string
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming that parsing the equation would not be a problem, how can I make
Assuming that the larger a database gets, the longer it will take to SELECT
assuming that I know the PID of a process and want to do a
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that best practices have been followed when designing a new database, how does
Assuming that I have a typedef declared in my .h file as such: typedef

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.