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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:19:46+00:00 2026-06-06T05:19:46+00:00

Previously I did a Tutorial on OpenGL-ES 1.0. For reference, this can be found

  • 0

Previously I did a Tutorial on OpenGL-ES 1.0. For reference, this can be found here:
SpaceInvaders (it’s in german though)

My goal now is to port the game to OpenGL-ES 2.0. So far, I am able to load meshes and textures and render them.

Now I would like to have a simple rectangle as my background with a texture on it. This should be rendered in Ortho-Perspective. I then change to Projection-Perspective and draw a simple box. When I now call setLookAtM(…), I get a blank sceen. Here is the code:

public void onDrawFrame(GL10 gl) {
   long currentFrameStart = System.nanoTime();
   deltaTime = (currentFrameStart - lastFrameStart) / 1000000000.0f;
   lastFrameStart = currentFrameStart;

   GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
   GLES20.glUseProgram(programHandle);
   checkGlError("glUseProgram");

   mMVPMatrixHandle = GLES20.glGetUniformLocation(programHandle, "uMVPMatrix");
   mMVMatrixHandle = GLES20.glGetUniformLocation(programHandle, "uMVMatrix");
   mLightPosHandle = GLES20.glGetUniformLocation(programHandle, "uLightPos");
   mTextureUniformHandle = GLES20.glGetUniformLocation(programHandle, "uTexture");

   mPositionHandle = GLES20.glGetAttribLocation(programHandle, "aPosition");
   mColorHandle = GLES20.glGetAttribLocation(programHandle, "aColor");
   mNormalHandle = GLES20.glGetAttribLocation(programHandle, "aNormal");
   mTextureCoordinateHandle = GLES20.glGetAttribLocation
      (programHandle,"aTexCoordinate");

   Matrix.setIdentityM(mLightModelMatrix, 0);
   Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0,    
      mLightPosInModelSpace, 0);
   Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

   Matrix.orthoM(mProjectionMatrix, 0, -width / 2, width / 2, -height / 2, height / 2, 
      0, 100);
   drawBackground();

   GLES20.glEnable(GLES20.GL_CULL_FACE);

   Matrix.setIdentityM(mProjectionMatrix, 0);
   final float ratio = (float) width / height;
   final float left = -ratio;
   final float right = ratio;
   final float bottom = -1.0f;
   final float top = 1.0f;
   final float near = 1.0f;
   final float far = 100.0f;
   Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);

   Matrix.setLookAtM(mViewMatrix, 0, 0, 6, 2, 0, 0, -4, 0, 1, 0);

   drawBlock();
}

Here the drawBackground method:

private void drawBackground() {
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, backgroundTextureHandle);
   GLES20.glUniform1i(mTextureUniformHandle, 0);

   Matrix.setIdentityM(mModelMatrix, 0);
   Matrix.setIdentityM(mProjectionMatrix, 0);

   mBackgroundPositions.position(0);
   GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, 
      false, 0, mBackgroundPositions);
   GLES20.glEnableVertexAttribArray(mPositionHandle);

   mBackgroundColors.position(0);
   GLES20.glVertexAttribPointer(mColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false, 
      0, mBackgroundColors);
   GLES20.glEnableVertexAttribArray(mColorHandle);

   mBackgroundNormals.position(0);
   GLES20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, 
      false, 0, mBackgroundNormals);
   GLES20.glEnableVertexAttribArray(mNormalHandle);

   mBackgroundTextureCoordinates.position(0);
   GLES20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORD_DATA_SIZE,   
      GLES20.GL_FLOAT, false, 0, mBackgroundTextureCoordinates);
   GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

   // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
   // (which currently contains model * view).
   Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

   // Pass in the modelview matrix.
   GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);

   // This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
   // (which now contains model * view * projection).
   Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

   // Pass in the combined matrix.
   GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

   // Pass in the light position in eye space.
   GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], 
      mLightPosInEyeSpace[2]);

   ShortBuffer buf = 
      ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asShortBuffer();
   buf.put(new short[] {0, 1, 2, 0, 2, 3});
   buf.position(0);

   // Draw the rectangle.
   GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, buf);
   checkGlError("glDrawArrays");
 }

And finally the drawBlock method:

private void drawBlocks() {
   GLES20.glUseProgram(colorProgramHandle);
   checkGlError("glUseProgram");

   mMVPMatrixHandle = GLES20.glGetUniformLocation(colorProgramHandle, "uMVPMatrix");
   mMVMatrixHandle = GLES20.glGetUniformLocation(colorProgramHandle, "uMVMatrix");
   mLightPosHandle = GLES20.glGetUniformLocation(colorProgramHandle, "uLightPos");
   mTextureUniformHandle = GLES20.glGetUniformLocation(colorProgramHandle, "uTexture");

   mPositionHandle = GLES20.glGetAttribLocation(colorProgramHandle, "aPosition");
   mColorHandle = GLES20.glGetAttribLocation(colorProgramHandle, "aColor");
   mNormalHandle = GLES20.glGetAttribLocation(colorProgramHandle, "aNormal");
   mTextureCoordinateHandle = GLES20.glGetAttribLocation(colorProgramHandle, 
       "aTexCoordinate");

   Matrix.setIdentityM(mProjectionMatrix, 0);
   Matrix.setIdentityM(mModelMatrix, 0);

   blockMesh.vertexBuffer.position(0);
   GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, 
      false, 0, blockMesh.vertexBuffer);
   GLES20.glEnableVertexAttribArray(mPositionHandle);

   blockMesh.colorBuffer.position(0);
   GLES20.glVertexAttribPointer(mColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false, 
      0, blockMesh.colorBuffer);
   GLES20.glEnableVertexAttribArray(mColorHandle);

   blockMesh.normalBuffer.position(0);
   GLES20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, 
      false, 0, blockMesh.normalBuffer);
   GLES20.glEnableVertexAttribArray(mNormalHandle);

   // This multiplies the view matrix by the model matrix, and stores the result in the 
   MVP matrix
   // (which currently contains model * view).
   Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

   // Pass in the modelview matrix.
   GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);

   // This multiplies the modelview matrix by the projection matrix, and stores the 
   result in the MVP matrix
   // (which now contains model * view * projection).
   Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

   // Pass in the combined matrix.
   GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

   // Pass in the light position in eye space.
   GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], 
      mLightPosInEyeSpace[2]);

   // Draw the cube.
   GLES20.glDrawElements(GLES20.GL_TRIANGLES, 36, GLES20.GL_UNSIGNED_SHORT, 
      blockMesh.indexBuffer);
   checkGlError("glDrawElements");
 }

I am not sure what I am missing about ortho and projection perspective. Any help is appreciated.

  • 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-06T05:19:47+00:00Added an answer on June 6, 2026 at 5:19 am

    You’re wiping the projection matrix as part of drawBlocks. I don’t think you want to do that, if you want to draw it using the perspective projection already computed.

    ...
    Matrix.setIdentityM(mProjectionMatrix, 0);   <-----
    Matrix.setIdentityM(mModelMatrix, 0);
    
    blockMesh.vertexBuffer.position(0);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this question asked previously but can not find a clear explanation
I tried to ask this question previously howver I did not recieve the correct
This question was previously asked and answered correctly, but there did not seem to
file://localhost/C:/Users/kürşat/Desktop/yeni%20site/faq%20-%20Kopya/kopya.html this is my photography tutorial page. I'm did manage to toggle on/off when
I previously did some popups / dialogs that I've now got regression error in
Please refer my previous post here . I did changes accordingly but getting error.
I am following the tutorial on the DJango site, which I previsouly did using
Previously, when I pushed my first app to heroku it did it with no
I have to remind the user about schedules which he did previously in java.
I am new to programming (previously only did html/css/design) trying to start learning RoR

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.