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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:28:15+00:00 2026-05-24T08:28:15+00:00

I am having a problem adapting and or I guess understanding the vertices/indices/faces in

  • 0

I am having a problem adapting and or I guess understanding the vertices/indices/faces in an OBJ file. I want to eventually parse a OBJ file programmatically but first I need to understand how to do it manually. I am using an adaptation of the example from GLWallpaperService(provided by a dev on the web) to do this.

The problem I am having is it seems to work fine with the code he provided to produce a generic cube with different colored faces which he had to implement and draw individually. My adjusted code below trying to draw just a basic cube from the coords I exported from blender and plugged in values.

public class GLCube {
private final int _nrOfVertices = 8;

private FloatBuffer _vertexBuffer;
private FloatBuffer _normalBuffer;
private ShortBuffer _indiceBuffer;

public GLCube() {
    this.init();
}

private void init() {
    // 3 is the number of coordinates to each vertex.
    _vertexBuffer = BufferFactory.createFloatBuffer(_nrOfVertices * 3);
    _normalBuffer = BufferFactory.createFloatBuffer(18);
    _indiceBuffer = BufferFactory.createShortBuffer(72);

    // Coordinates for the vertexes of the cube.
    float[] vertexCoords = {
            /*
            1f,  1f,  0f,
            0f,  1f,  0f, 
            0f,  0f,  0f, 
            1f,  0f,  0f, 
            1f,  0f, -1f, 
            1f,  1f, -1f, 
            0f,  1f, -1f, 
            0f,  0f, -1f,
            */
            2.195671f, -0.176713f, -1.292541f,
            2.195671f, -0.176713f,  0.707459f,
            0.195671f, -0.176713f,  0.707459f,
            0.195672f, -0.176713f, -1.292542f,
            2.195672f,  1.823287f, -1.292541f,
            2.195671f,  1.823287f,  0.707460f,
            0.195671f,  1.823287f,  0.707459f,
            0.195671f,  1.823287f, -1.292541f
    };

    short[] indicesArray = {/*
            0, 1, 2,   0, 2, 3,
            3, 4, 0,   4, 5, 0,
            7, 2, 6,   6, 2, 1,
            4, 7, 5,   7, 6, 5,
            1, 0, 6,   6, 0, 5,
            2, 7, 3,   7, 4, 3
            */
            1,1,2, 1,3,1,
            1,1,3, 1,4,1,
            5,2,8, 2,7,2,
            5,2,7, 2,6,2,
            1,3,5, 3,6,3,
            1,3,6, 3,2,3,
            2,4,6, 4,7,4,
            2,4,7, 4,3,4,
            3,5,7, 5,8,5,
            3,5,8, 5,4,5,
            5,6,1, 6,4,6,
            5,6,4, 6,8,6
            };

    //Coordinates for Normal Vector. Used for Lighting calculations
    float[] normalCoords = {/*
             0f, 0f, 1f,   0f, 0f, 1f,   
             0f, 0f, 1f,   0f, 0f, 1f,   
             0f, 0f, 1f,   0f, 0f, 1f,   
             1f, 0f, 0f,   1f, 0f, 0f,   
             1f, 0f, 0f,   1f, 0f, 0f,   
             1f, 0f, 0f,   1f, 0f, 0f,   
            -1f, 0f, 0f,  -1f, 0f, 0f,  
            -1f, 0f, 0f,  -1f, 0f, 0f,  
            -1f, 0f, 0f,  -1f, 0f, 0f,  
             0f, 0f,-1f,   0f, 0f,-1f,   
             0f, 0f,-1f,   0f, 0f,-1f,   
             0f, 0f,-1f,   0f, 0f,-1f,   
             0f, 1f, 0f,   0f, 1f, 0f,   
             0f, 1f, 0f,   0f, 1f, 0f,   
             0f, 1f, 0f,   0f, 1f, 0f,  
             0f,-1f, 0f,   0f,-1f, 0f,   
             0f,-1f, 0f,   0f,-1f, 0f,   
             0f,-1f, 0f,   0f,-1f, 0f   
             */
             0f, -1f,  0f,
             0f,  1f,  0f,
             1f, -0f,  0f,
            -0f, -0f,  1f,
            -1f, -0f, -0f,
             0f,  0f, -1f
    };

    _vertexBuffer.put(vertexCoords);
    _normalBuffer.put(normalCoords);
    _indiceBuffer.put(indicesArray);

    _indiceBuffer.position(0);
    _vertexBuffer.position(0);
    _normalBuffer.position(0);

}

public void draw(GL10 gl) {
    // 3 coordinates in each vertex
    // 0 is the space between each vertex. They are densely packed in the array, so the value is 0
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);

    // 0 is the space between each vertex. They are densely packed in the array, so the value is 0
    gl.glNormalPointer(GL10.GL_FLOAT, 0, _normalBuffer);

    gl.glColor4f(1.0f, 0f, 0f, 1f);     //Red
    gl.glDrawElements(GL10.GL_TRIANGLES, 72, GL10.GL_UNSIGNED_SHORT, _indiceBuffer);
}
}

This is the Obj file and maybe I’m just not putting the values in the correct arrays but I have been trying to figure this out for awhile and honestly just don’t have any background working with OpenGL so this is my first project trying to work with it.

# Blender v2.58 (sub 1) OBJ File: ''
# www.blender.org
v 2.195671 -0.176713 -1.292541
v 2.195671 -0.176713 0.707459
v 0.195671 -0.176713 0.707459
v 0.195672 -0.176713 -1.292542
v 2.195672 1.823287 -1.292541
v 2.195671 1.823287 0.707460
v 0.195671 1.823287 0.707459
v 0.195671 1.823287 -1.292541
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 1.000000 -0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
usemtl (null)
s off
f 1//1 2//1 3//1
f 1//1 3//1 4//1
f 5//2 8//2 7//2
f 5//2 7//2 6//2
f 1//3 5//3 6//3
f 1//3 6//3 2//3
f 2//4 6//4 7//4
f 2//4 7//4 3//4
f 3//5 7//5 8//5
f 3//5 8//5 4//5
f 5//6 1//6 4//6
f 5//6 4//6 8//6

Any help with this would be so greatly appreciated. I left his values commented in so you could see what works. The image I see on my screen is a completely distorted set of triangles and it appears its trying to make my cube but is just not quite getting there.

An answer containing what to change would be awesome. -=)

  • 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-24T08:28:15+00:00Added an answer on May 24, 2026 at 8:28 am

    I think you’re interpreting the .obj format in the wrong way. Have a look at this document.

    Basically the indices for your faces into the vertexCoords should be the first ints.
    Each face is defined by indices in a format like this:

    f v1/t1/n1 v2/t2/n2 v3/t3/n3
    

    Where the v’s are vertex indices, the t’s are texture coordinate indices and the n’s are normal indices.

    So for this line (which defines a single face/triangle)

    f 1//1 2//1 3//1
    

    the vertex indices would be 1,2,3and the normal indices 1,1,1.
    You have no texture coordinates, so no indices there and hence the double slash.

    Keep in mind that the indices for the vertices that make up a face and the indices of the associated normals are different. So you will have to create two sets of indices. (See my edit below about glDrawElements though)

    Another minor detail is to keep in mind that .obj files start counting with indices at 1, although that might be (an probably is) the 0th value in your array. So you’ll have to account for that (i.e. subtract 1 from all index values).

    Edit:
    Looking at your code I see you’re using glDrawElements. From what I know (but correct me if I’m wrong) this doesn’t allow you to have multiple (different) sets of indices for vertices, texcoords and normals. So you will have to change your normal data to match the same indices as you have for your vertices.

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

Sidebar

Related Questions

i'm having problem when i want to select element using querySelector <ul class=xoxo blogroll>
I having problem with file download, I am able to download file in emulator
i having problem understanding what is wrong with my inheritance. I just can not
i am having problem using Zend_Navigation here is my navigation.xml file <?xml version=1.0 encoding=UTF-8?>
I am having problem understanding the following text, 8088 supports 1 Mbyte of external
I am having problem understanding Priority Inversion Snippet from the article: Consider there is
I am having problem here with bitmaps..I want to remove the black background that
i having problem with draw image in applet. i want to display all images
I having problem using CHCSVwriter to export my arrays to CSV or excel file.
Having problem understanding Delegate error. Error says expression expected, How do I fix? Thanks

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.