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

The Archive Base Latest Questions

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

Im having trouble with texturing a cube with different textures per face. I can

  • 0

Im having trouble with texturing a cube with different textures per face. I can draw the cube with one texture on all the faces, but when I try use multiple textures it fails. The way im trying to do it is like so:

//my indexing array located in a header file
#define NUM_IMAGE_OBJECT_INDEX 36
static const unsigned short cubeIndices[NUM_IMAGE_OBJECT_INDEX] =
{
    0, 1, 2,   2, 3, 0,      // front
    4, 5, 6,   6, 7, 4,      // right
    8, 9,10,  10,11, 8,      // top
    12,13,14,  14,15,12,     // left
    16,17,18,  18,19,16,     // bottom
    20,21,22,  22,23,20      // back
};

now in my rendering function, this currently works for drawing the cube with a single texture

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iconTextureID);

glDrawElements(GL_TRIANGLES, NUM_IMAGE_OBJECT_INDEX, GL_UNSIGNED_SHORT, 0);

this does not work

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iconTextureID);

glDrawElements(GL_TRIANGLES, NUM_IMAGE_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*)&cubeIndices[0]);

which should equate to the same thing, from looking at some other examples. Ultimately I would like to be doing this something like this:

for(int i = 0; i < 6; i++){

    iconTextureID = textureID[i];                
    glBindTexture(GL_TEXTURE_2D, iconTextureID);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const GLvoid*)&cubeIndices[i*6]); //index 0-5 use texture 1, 6-11 use texture 2, etc

}

does anyone know what could be wrong with this indexing? ive basically copy pasted this code from an android project (which works), currently trying to do this on ios.

  • 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-14T18:37:31+00:00Added an answer on June 14, 2026 at 6:37 pm

    In OpenGL ES 2.0, index data can come from either buffer objects or pointers to client memory. Your code is obviously using a buffer object. Though you don’t show the creation of this buffer object, where you upload your client array of pointers, or where you call glBindBuffer(GL_ELEMENT_ARRAY_BUFFER) before rendering with it. It must be there or your code would have crashed. When a buffer is bound to GL_ELEMENT_ARRAY_BUFFER, OpenGL expects the “pointer” given to glDrawElements to be a byte offset into the buffer object, not a client-memory pointer.

    This is why copy-and-paste coding is a bad idea. Where you copied from was probably using client memory; you are not.

    If you want your looping code to work, you need to do the pointer arithmetic yourself:

    for(int i = 0; i < 6; i++)
    {
        iconTextureID = textureID[i];                
        glBindTexture(GL_TEXTURE_2D, iconTextureID);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, reinterpret_cast<void*>(i * 6 * sizeof(GLushort)));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with an .htaccess file on WAMP. Works on the live server, but
Having trouble getting the following code to work. Calling swapLevel() directly works fine, but
having trouble coming up with search parameters for this issue, so I can't find
Having trouble with pattern and replacement. How can I make the replacement echo a
Having trouble getting my POST arrays to show all checkbox values from my form.
Having trouble with Codekit/Compass. Know lots of people have had issues with this but
Having trouble grouping active forum sum results by wildcards. Ultimately, I want all the
Having trouble with this -- a couple of other related posts out there, but
Having trouble getting one portion of my code to work. Building a rudimentary linked
Having trouble with this..I'm sure I'm missing something simple but I simply want the

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.