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

The Archive Base Latest Questions

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

I’m having a problem with texturing objects in OpenGL using texture atlases, I’m creating

  • 0

I’m having a problem with texturing objects in OpenGL using texture atlases, I’m creating a 2d game and I know how to texture a POT bitmap to an object but, I can’t seem to find a tutorial in converting my code to use a texture atlas for performance reasons, here is my code for my current working object creation and texturing implementation.

public void createTexture(Bitmap bmp, GL10 gls, int texturename)
    {
        this.gl = (GL11) gls;

        this.TextureName = texturename;
        bombBmp = bmp;

        VertexBuffer = null;
        TextureBuffer = null;
        IndexBuffer = null;

        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(12 * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        VertexBuffer = byteBuffer.asFloatBuffer();
        VertexBuffer.put(new float[] { 0, 0, 0.0f, 0, -h, 0.0f, w, 0, 0.0f, w, -h, 0.0f });
        VertexBuffer.position(0);

        byteBuffer = ByteBuffer.allocateDirect(8 * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        TextureBuffer = byteBuffer.asFloatBuffer();
        TextureBuffer.put(new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f });
        TextureBuffer.position(0);

        byteBuffer = ByteBuffer.allocateDirect(6 * 2);
        byteBuffer.order(ByteOrder.nativeOrder());
        IndexBuffer = byteBuffer.asShortBuffer();
        IndexBuffer.put(new short[] { 0, 1, 2, 1, 3, 2 });
        IndexBuffer.position(0);

        gl.glBindTexture(GL10.GL_TEXTURE_2D, this.TextureName);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bombBmp, 0);
        bombBmp.recycle();
        bombBmp = null;
    }

I generate my Texturename from genTexture and pass the POT bitmap to this function

gl.glGenTextures(1, textures, 0);
bomb.createTexture(bombBmp, gl, textures[0]);

here’s my supposed texture bitmap

bomb_atlas.png

  • 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-31T09:30:45+00:00Added an answer on May 31, 2026 at 9:30 am

    Responding to your comment, you don’t bind subImages. glTexSubImage is only used for replacing pixels in a stored texture. If your bitmap already exists as an atlas as you’ve shown, then you just load the whole texture via glTexImage2d and bind it.

    If you want to access a particular part of that image (say the yellow circle bomb 3rd from the left on the first line), then you just modify the texture coordinates that you use to access it. If that circle was in its own image you would just use (0,0) to (1,1) coordinates, but because it is part of another image you have to select just a specific part of it. In your picture there it would have texcoords of:

    (.50,.75) //bottom left
    (.75,.75) //bottom right
    (.75,1.0) //top right
    (.50,1.0) //top left
    

    If you draw a quad with these texcoords it should look exactly as if the yellow circle bomb had its own image, but you don’t have to keep rebinding textures all the time (hence the performance increase).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string

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.