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

  • Home
  • SEARCH
  • 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 3602476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:45:03+00:00 2026-05-18T20:45:03+00:00

I am new to OpenGL and am currently trying to render a cube with

  • 0

I am new to OpenGL and am currently trying to render a cube with four faces, each with a different texture.

As you all know, having a separate texture for each face type is very memory intensive and makes the application slow.

At the moment I am trying to use a texture sheet for the sprite. I have the graphic file with each texture 16×16 pixels with 256 sprites arranged in a square (16×16).

I know that

GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(1.0f, 1.0f,  1.0f);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(0.0f, 1.0f, 1.0f);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(0.0f, 0.0f, 1.0f);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(1.0f, 0.0f, 1.0f);

gives me a rectangle with the whole sprite sheet so u and v of glTexCoord2f have to be less than 1.0f.

What I need now is a formula which will calculate the u and v of any sprite id in the texture.

The IDs go as following in the texture bitmap:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 16 20 21 22 23 24...

and I’d like to have a u and v for any of these IDs. The last bit isn’t explained very well, so I’ll explain it better if you would like.

Thank you in advance!

  • 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-18T20:45:04+00:00Added an answer on May 18, 2026 at 8:45 pm

    The locations of the sprites’ texture in the image are in a 16 x 16 array, so the location of a texture (if you count the first one as 0) are:

    row = texNo / 16;
    col = texNo % 16;
    

    The coordinates are then:

    u0 = row / 16;
    u1 = (row + 1) / 16;
    
    v0 = col / 16;
    v1 = (col + 1) / 16; 
    

    Then replace 1.0f with u1 or v1 as appropriate and 0.0f with u0 or v0 in the glTexCoord2Df calls.

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

Sidebar

Related Questions

I'm new to OpenGL. I have written a programm before getting to know OpenGL
I am completely new to opengl and need some help in drawing a texture
I'm currently trying to follow the OpenGL intro guide here . I've pulled the
I'm very new to creating games (and working in OpenGL in general). I'm trying
I'm currently using OpenGL ES 2.0 under GLKView on the new iPad. It seems,
I'm quite new to openGL and I have been trying out some sample codes
I'm trying to integrate MyGUI 3.2.0 into my OpenGL 3 engine, but I'm having
I'm new to U/I programming, and I'm trying to get started with OpenGL. When
I'm trying to render a simple square in OpenGl on Android. The same code
I'm very new to an Android platform and currently trying figure out why things

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.