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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:31:37+00:00 2026-05-30T12:31:37+00:00

I am currently trying to make a game in Android. I have this piece

  • 0

I am currently trying to make a game in Android.
I have this piece of code and I’m trying to display the square at one corner of the screen.
I’ve tried to use GLU.gluOrtho2D but every time I use it I get a blank screen.
Can someone tell me how to move the square from the center of the screen to one of the corners?

This is my code:

public class OpenGLRenderer implements Renderer {

private TexturedSquare element;
private float angle; 

public OpenGLRenderer(Context context) {
    // Initialize things
    int[] bilder = {R.drawable.first};
    element = new TexturedSquare(context, 1f, 1, bilder);
    angle = 0.5f;
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    // Set the background color to black ( rgba )
    gl.glClearColor(1f, 1f, 1f, 1f);
    // Enable Smooth Shading, default not really needed
    gl.glShadeModel(GL10.GL_SMOOTH);// OpenGL docs
    // Depth buffer setup.
    gl.glClearDepthf(1.0f);
    // Enables depth testing.
    gl.glEnable(GL10.GL_DEPTH_TEST);
    // The type of depth testing to do.
    gl.glDepthFunc(GL10.GL_LEQUAL);
    // Really nice perspective calculations.
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
                      GL10.GL_NICEST);
    // NEW
    element.loadTexture(gl);             // Load images into textures (NEW)
    gl.glEnable(GL10.GL_TEXTURE_2D);
}


public void onDrawFrame(GL10 gl) {

    // Clears the screen and depth buffer.
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    // Replace the current matrix with the identity matrix
    gl.glLoadIdentity();
    // Translates 4 units into the screen.
    gl.glTranslatef(0f, 0f, -4f);
    // What is to be drawn on the screen
    //gl.glRotatef(-angle*20f, 0f, 0f, 1f); // Rotate the element around 3 axes
    //gl.glRotatef(angle, 0f, 1f, 0f);
    //gl.glRotatef(angle, 0f, 0f, 1f);
    element.draw(gl);
    angle++;
}


public void onSurfaceChanged(GL10 gl, int width, int height) {

    // Sets the current view port to the new size.
    gl.glViewport(0, 0, width, height);
    // Select the projection matrix
    gl.glMatrixMode(GL10.GL_PROJECTION);
    // Reset the projection matrix
    gl.glLoadIdentity();// OpenGL docs.
    // Calculate the aspect ratio of the window
    GLU.gluPerspective(gl, 45.0f,
                               (float) width / (float) height,
                               0.1f, 100.0f);
    // Select the modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    // Reset the modelview matrix
    gl.glLoadIdentity();
}
}

This is the draw method the square class uses:

public void draw(GL10 gl) {
  gl.glFrontFace(GL10.GL_CCW);

  gl.glFrontFace(GL10.GL_CCW); // OpenGL docs
    // Enable face culling.
  gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs
    // What faces to remove with the face culling.
  gl.glCullFace(GL10.GL_BACK); // OpenGL docs

  gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
  gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuffer);

  gl.glPushMatrix();
  gl.glTranslatef(0f, 0f, cubeHalfSize);
  gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[0]);
  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
  gl.glPopMatrix();

  gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}

Any help?

  • 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-30T12:31:38+00:00Added an answer on May 30, 2026 at 12:31 pm

    Look at gl.glTranslatef(0f, 0f, cubeHalfSize);

    if cubeHalfSize a positive value the cube won’t display.

    You already have a “glTranslatef” in your OpenGLRenderer class so try commenting out “glTranslatef” in your square class:

      gl.glPushMatrix();
      gl.glTranslatef(0f, 0f, cubeHalfSize);
      gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[0]);
     // gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
      gl.glPopMatrix();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm trying to make a flowchart, this is the code I've got so
I'm trying to make my first android game and to do this I made
I am currently trying to make a sectioned table like this: Section 1: Entry
I'm currently trying to make a RPG game and I'm running into some trouble.
Im trying to make an 2D online game (with Z positions), and currently im
I am trying to make a game for android. It is based on a
I'm trying to make a Tetris-like game in XNA, and currently I'm thinking of
i am trying to make a very simple game where i have 7 positions
I'm trying to make an NDK-based game work on Android ICS. It worked fine
Hy, I am currently trying to make a first person game.what i was able

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.