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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:30:47+00:00 2026-06-14T20:30:47+00:00

I am attempting to draw a 2D square on a GLSurfaceView in 2D mode.

  • 0

I am attempting to draw a 2D square on a GLSurfaceView in 2D mode. I can draw the object in 3D mode and have tested that the square is out in 3D space. I then try to configure the matrix for 2d drawing and when I attempt to draw my object nothing appears.

My GLSurfaceView instance implements GLSurfaceView.Renderer.

I’ve broken the setup into two functions:

private void prepare3Ddrawing(GL10 gl)
{
    gl.glLoadIdentity();
    gl.glViewport(0, 0, getWidth(), getHeight());
    gl.glDisable(GL10.GL_DITHER);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0f, (float)getWidth()/(float)getHeight(),0.1f,100.0f);    
}
private void prepare2Ddrawing(GL10 gl)
{
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluOrtho2D(gl,0,getWidth(), 0, getHeight());
    gl.glScalef(1, -1, 1);
    gl.glTranslatef(0, -getHeight(), 0);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
}

And here is my draw method…

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

    camera.draw(gl);
    go2d.draw(gl);

    prepare2Ddrawing(gl);
    go2d.draw(gl);

}

and finally, my go2d object is an instance of an object I created called GameObject2d. It’s draw method looks like this…

@Override
public void draw(GL10 gl)
{
    super.draw(gl);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glEnable(GL10.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL10.GL_GREATER, 0.0f);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glTexCoordPointer(2,GL10.GL_FLOAT,0,textureBuffer);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureID);

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


    gl.glFrontFace(GL10.GL_CW);
    //gl.glEnable(GL10.GL_CULL_FACE);
    gl.glCullFace(GL10.GL_BACK);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

    gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, indexBuffer);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_ALPHA_TEST);
    gl.glDisable(GL10.GL_TEXTURE_2D);   
}

Does anyone have any ideas? Again, I am still able to see the 3D rendered version of the go2D object, but I do not see the 2D version.

Thanks.

  • 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-14T20:30:49+00:00Added an answer on June 14, 2026 at 8:30 pm

    As you don’t include any data, I can only propose two methods to debug the issue.

    Step 1: try to force your 2d – perspective matrix and modelview matrix to be Identity Matrices. Then if you force your Square data vertices inside the clip space (e.g.
    x,y = +-1 or x,y= +-0.75, z=0, you should see a square appearing in the screen.

    Step 2: now that the data model is correct, check what your model view and perspective matrices do: multiply each of your square vertices (x,y,z, w=1) with ModelView Matrix * CameraMatrix * PerspectiveMatrix. What do you get? Are the x,y,z much outside |w| ?

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

Sidebar

Related Questions

I'm attempting to draw to screen with a bunch of colors that I have
So, I have a CIImage that I'm attempting to draw in an NSView 's
Attempting to do SetData() on Texture2D that has been recently Draw()-n by SpriteBatch leads
I'm attempting to change RenderTargets at runtime, so I can draw some elements at
My program is attempting to draw grammars in C# & WPF. I have: 1
I am attempting to draw a sidebar for a project that I am working
Using OpenGL I'm attempting to draw a primitive map of my campus. Can anyone
So, i'm attempting simple card game. I have player class with draw function, and
I am attempting to draw the 3 arrows below. I can draw the top
I have a PDF file that I want to draw in outline form. I

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.