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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:29:23+00:00 2026-05-25T21:29:23+00:00

I was experimenting with opengles, and made some simple squares moving around the screen:

  • 0

I was experimenting with opengles, and made some simple squares moving around the screen:

    //inside my renderScreen() method, called from onDrawFrame()
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    if (gameObjects != null) {
        // iterate and draw objects
        for (GameObject obj : gameObjects) {
            if (obj != null) {
                gl.glLoadIdentity();
                gl.glTranslatef(obj.posX, obj.posY, 0.0f);
                obj.doDraw(gl);
            }

Just simple, draws objects to the screen (still working). Now I wanted to like drag around the screen by translating the projection matrix based on touch input. I added this code above my previous code (before drawing the objects)

//change projection matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glTranslatef(-cameraX, -cameraY, 0.0f); //cameraX and cameraY set in updateGame()  

updateGame is just gets those from MyPanel.getDiffX() where DiffX is just how much your finger moved:

// Inside MyPanel Class
public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                startingX = event.getX();
                startingY = event.getY();
                MyRenderer.addObject(new GameSquare(event.getX(), v
                        .getHeight() - event.getY())); // Y is inverted!
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                diffX = (event.getX() - startingX) / 100;
                //diffY = (event.getX() - startingY) / 1000;
                Log.d("diffX" ,Float.toString(diffX));
            }
            return true;
        }

Now if I use the code to translate the projection Matrix, I don’t get to see any objects on my screen anymore (just the glClear color). Does anyone know what’s going on ? Am I using the matrices wrong ?

  • 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-25T21:29:23+00:00Added an answer on May 25, 2026 at 9:29 pm

    What happens when you set cameraX and cameraY to 0? By changing the projection matrix, are you sure you’re not overwriting some previously set values?

    Aside from that, you should be translating by -cameraX and -cameraY. Think about it, if you want your camera to be at position (10, 10), then anything at (10, 10) should be at the origin after transforming by the camera, the logical translation would be (-10, -10). You’re not translating the camera in the world, but you’re translating the world around the camera.

    EDIT: let me suggest an alternative method of doing this, that doesn’t change the projection matrix.

    //inside my renderScreen() method, called from onDrawFrame()
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glTranslate(-cameraX, -cameraY, 0); //Apply the camera here
    if (gameObjects != null){
        // iterate and draw objects
        for (GameObject obj : gameObjects) {
            if (obj != null) {
                gl.glPushMatrix(); //Note this line here, we 'push' a matrix onto the top
                gl.glTranslatef(obj.posX, obj.posY, 0.0f);
                obj.doDraw(gl);
                gl.glPopMatrix(); //Here we remove our modified matrix to get the original one
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In experimenting with pickle, I've put together some code for a (very) simple blog.
While experimenting with pixel shaders in WPF I decided to draw some pixels onto
While experimenting with some stuff on the REPL, I got to a point where
While experimenting a bit with C++ templates I managed to produce this simple code,
Experimenting with Cocos2D collection detection and have some questions. First, some background: This is
Experimenting with JsHelper in CakePHP 2.0, I got a Request method to update the
Experimenting with new features of T-SQL, I've run into a puzzle. Here is some
I've been experimenting with the standard python math module and have come across some
im experimenting in getting camel to do some file operations and pass them through
I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to

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.