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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:20:31+00:00 2026-06-16T01:20:31+00:00

Overview I am having trouble rendering the texture on the sides of my cube.

  • 0

Overview

I am having trouble rendering the texture on the sides of my cube. I have successfully rendered textures on the top and bottom of my cube, but am unable to render on the sides.

What I have

I have a texture buffer full of 48 elements, (4*2 elements per face and 6 faces is 48) and they are full will good coordinates.

The cube shape is drawing is drawing, but the sides are not being rendered.
screenshot of the cube

The image I am drawing is simply a image with the numbers 1-9 as you can see from the top of the cube. The textureBuffer is the same patter over and over again…

        texture[0] = 0;
        texture[1] = 0;
        texture[2] = 1;
        texture[3] = 0;
        texture[4] = 1;
        texture[5] = 1;
        texture[6] = 0;
        texture[7] = 1;
        texture[8] = 0;
        texture[9] = 0;
        texture[10] = 1;
        texture[11] = 0;
        texture[12] = 1;
        texture[13] = 1;
        texture[14] = 0;
        texture[15] = 1;
        texture[16] = 0f;
        texture[17] = 0f;
        texture[18] = 1f;
        texture[19] = 0f;
        texture[20] = 1f;
        texture[21] = 1f;
        texture[22] = 0f;
        texture[23] = 1f;

which simply loads the texture Buffer to render the full texture.

Possible Problem##

It appears that only the first 16 texture coordinates are being drawn and used because only the top and bottom surface of the rectangle are being textured. I’ve debugged it and when I populate the TextureBuffer the size is 48 though.

Render Code

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

    //gl.glColor4f(255, 0, 0, 150);
    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_CCW);
    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,indexBuffer.capacity(),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);
    gl.glColor4f(255, 255, 255, 255);
}

Creating the variable textureBuffer

The parameter variable texture that comes in contains 48 elements

public void constructTextureBuffer(float[] texture)
{
    ByteBuffer vbb = ByteBuffer.allocateDirect(texture.length*4);
    vbb.order(ByteOrder.nativeOrder());
    textureBuffer = vbb.asFloatBuffer();
    textureBuffer.put(texture);
    textureBuffer.position(0);
}

The vertexBuffer is correctly setup and using the index buffer to render a cube. Do you know why the sides of the cube are not being rendered?

NEW!!

So I tried creating a shape by hand and I am running into the same situation with the texture buffer. I can render two faces but not the third! It appears anything past 8 texture verticies do not work.

This picture shows my new shape. Notice the horizontal extension. No matter what I do to those texture coordinates, that texture does not change. That is also the third face of my random object.

enter image description here

  • 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-16T01:20:33+00:00Added an answer on June 16, 2026 at 1:20 am

    I have yet to get index buffers and textures to work together. I’ve tried almost everything! So instead (and unfortunately) I am building lots of triangles. In order to parse the .obj file generated by blender, I wrote this function which creates the vertex buffer and texture buffer for me.

    public static Mesh createMesh(int resourceID)
        {
            Mesh m = new Mesh();
    
            Scanner s = null;
    
            BufferedReader inputStream = null;
    
            ArrayList<Float> readInVerticies        = new ArrayList<Float>();
            ArrayList<Float> readInTextures         = new ArrayList<Float>();
            ArrayList<Short> readInVertexIndicies   = new ArrayList<Short>();
            ArrayList<Short> readInTextureIndicies  = new ArrayList<Short>();
    
            int numberFaces = 0;
    
            try
            {
                inputStream = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(resourceID)));
                s = new Scanner(inputStream);
                String line = null;
    
                /*
                 * Read the header part of the file
                 */
                line = inputStream.readLine();
                line = inputStream.readLine();
                line = inputStream.readLine();
                line = inputStream.readLine();
                line = inputStream.readLine();
    
                while(line.charAt(0) == 'v' && line.charAt(1) != 't')
                {
                    s = new Scanner(line);
                    s.next();
                    readInVerticies.add(s.nextFloat());
                    readInVerticies.add(s.nextFloat());
                    readInVerticies.add(s.nextFloat());
                    line = inputStream.readLine();
                }
                while(line.charAt(0)=='v' && line.charAt(1)=='t')
                {
                    s = new Scanner(line);
                    s.next(); //read in "vt"
                    readInTextures.add(s.nextFloat());
                    readInTextures.add(s.nextFloat());
                    line = inputStream.readLine();
                }
                line = inputStream.readLine();
                line = inputStream.readLine();
    
                while(line != null && line.charAt(0) == 'f')
                {
                    s = new Scanner(line);
                    s.useDelimiter("[ /\n]");
                    String buffer = s.next();
                    short vi1,vi2,vi3,vi4;
                    short ti1,ti2,ti3,ti4;
    
                    vi1 = s.nextShort();
                    ti1 = s.nextShort();
                    vi2 = s.nextShort();
                    ti2 = s.nextShort();
                    vi3 = s.nextShort();
                    ti3 = s.nextShort();
                    vi4 = s.nextShort();
                    ti4 = s.nextShort();
    
                    readInVertexIndicies.add(vi1);
                    readInVertexIndicies.add(vi2);
                    readInVertexIndicies.add(vi3);
                    readInVertexIndicies.add(vi4);
    
                    readInTextureIndicies.add(ti1);
                    readInTextureIndicies.add(ti2);
                    readInTextureIndicies.add(ti3);
                    readInTextureIndicies.add(ti4);
    
                    numberFaces = numberFaces + 1;
                    line = inputStream.readLine();      
                }
    
                /*
                 * constructing our verticies. Use the number of faces * 6 because
                 * there are 2 triangles per face and 3 verticies on a triangle but there are
                 * also 3 coordinates per vertex.
                 * 
                 * For the texture, the same number but there are only 2 coordinates per texture
                 */
                float verticies[] = new float[numberFaces * 6 * 3];
                float textures[]  = new float[numberFaces * 6 * 2];
                for(int i=0;i<numberFaces;i++)
                {
                    verticies[i*18+0]       =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+0);
                    verticies[i*18+1]       =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+1);
                    verticies[i*18+2]       =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+2);
    
                    textures[i*12+0]        =   readInTextures.get((readInTextureIndicies.get(i*4+0)-1)*2+0);
                    textures[i*12+1]        =   readInTextures.get((readInTextureIndicies.get(i*4+0)-1)*2+1);
    
                    verticies[i*18+3]       =   readInVerticies.get((readInVertexIndicies.get(i*4+1)-1)*3+0);
                    verticies[i*18+4]       =   readInVerticies.get((readInVertexIndicies.get(i*4+1)-1)*3+1);
                    verticies[i*18+5]       =   readInVerticies.get((readInVertexIndicies.get(i*4+1)-1)*3+2);
    
                    textures[i*12+2]        =   readInTextures.get((readInTextureIndicies.get(i*4+1)-1)*2+0);
                    textures[i*12+3]        =   readInTextures.get((readInTextureIndicies.get(i*4+1)-1)*2+1);
    
                    verticies[i*18+6]       =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+0);
                    verticies[i*18+7]       =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+1);
                    verticies[i*18+8]       =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+2);
    
                    textures[i*12+4]        =   readInTextures.get((readInTextureIndicies.get(i*4+2)-1)*2+0);
                    textures[i*12+5]        =   readInTextures.get((readInTextureIndicies.get(i*4+2)-1)*2+1);
    
                    verticies[i*18+9]       =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+0);
                    verticies[i*18+10]      =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+1);
                    verticies[i*18+11]      =   readInVerticies.get((readInVertexIndicies.get(i*4+0)-1)*3+2);
    
                    textures[i*12+6]        =   readInTextures.get((readInTextureIndicies.get(i*4+0)-1)*2+0);
                    textures[i*12+7]        =   readInTextures.get((readInTextureIndicies.get(i*4+0)-1)*2+1);
    
                    verticies[i*18+12]      =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+0);
                    verticies[i*18+13]      =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+1);
                    verticies[i*18+14]      =   readInVerticies.get((readInVertexIndicies.get(i*4+2)-1)*3+2);
    
                    textures[i*12+8]        =   readInTextures.get((readInTextureIndicies.get(i*4+2)-1)*2+0);
                    textures[i*12+9]        =   readInTextures.get((readInTextureIndicies.get(i*4+2)-1)*2+1);
    
                    verticies[i*18+15]      =   readInVerticies.get((readInVertexIndicies.get(i*4+3)-1)*3+0);
                    verticies[i*18+16]      =   readInVerticies.get((readInVertexIndicies.get(i*4+3)-1)*3+1);
                    verticies[i*18+17]      =   readInVerticies.get((readInVertexIndicies.get(i*4+3)-1)*3+2);
    
                    textures[i*12+10]       =   readInTextures.get((readInTextureIndicies.get(i*4+3)-1)*2+0);
                    textures[i*12+11]       =   readInTextures.get((readInTextureIndicies.get(i*4+3)-1)*2+1);
                }
    
                m.constructVertexBuffer(verticies);
                m.constructTextureBuffer(textures);
    
    
            } 
            catch (FileNotFoundException e)
            {
                e.printStackTrace();
            } 
            catch (IOException e)
            {
                e.printStackTrace();
            }
    
            return m;
        }
    

    So if you ever have trouble parsing a .obj file, feel free to use this as a reference or guide! Blender gives you everything in faces with 4 vertices, and this turns everything into 3s and constructs 2 triangles per face.

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

Sidebar

Related Questions

I ve looked at the JSoup Selector Overview documentation but I'm still having problems.
I'm having trouble swapping Short Description (Quick Overview) with Additional Information (Attributes) Here's an
Ok so this is probably a trivial question but I'm having trouble visualizing and
I must be missing something simple here, but I'm having trouble retrieving data from
I know this has been asked a thousand times but I'm still having trouble
I'm having trouble translating all the buzzwords on the product page: http://www.oracle.com/technetwork/middleware/repository/overview/index.html Is it
Im having trouble getting this to work, here´s a quick overview of the idea.
I'm extending the UserProfile but I'm having trouble getting the new field - current_article
This is probably really easy, but I am having trouble with it. I asked
OverView I'm having problem with Ajax Tab Container ,I have added three tabs in

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.