Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: trying to render a cube in java

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    5

    trying to render a cube in java

    I am experimenting with vertices in Java. I tried to make a cube, but on the forward face it looks like a quarter piece is missing, I'm not sure what I'm doing wrong. since the code that renders is not mine and does work when the proper vertices and indices are given, I know it is something with my vertices or and/or indices.

    I generated the vertices and indices from a wavefront OBJ file. Am I missing a set of indices??


    this is the original OBJ file:

    Code :
    # Exported from Wings 3D 1.5.1
    mtllib cube.mtl
    o Cube1
    #8 vertices, 6 faces
    v -1.00000000 -1.00000000 -1.00000000
    v -1.00000000 -1.00000000 1.00000000
    v -1.00000000 1.00000000 -1.00000000
    v -1.00000000 1.00000000 1.00000000
    v 1.00000000 -1.00000000 -1.00000000
    v 1.00000000 -1.00000000 1.00000000
    v 1.00000000 1.00000000 -1.00000000
    v 1.00000000 1.00000000 1.00000000
    vn -0.57735027 -0.57735027 -0.57735027
    vn -0.57735027 -0.57735027 0.57735027
    vn -0.57735027 0.57735027 -0.57735027
    vn -0.57735027 0.57735027 0.57735027
    vn 0.57735027 -0.57735027 -0.57735027
    vn 0.57735027 -0.57735027 0.57735027
    vn 0.57735027 0.57735027 -0.57735027
    vn 0.57735027 0.57735027 0.57735027
    g Cube1_default
    usemtl default
    s 1
    f 1//1 5//5 6//6 2//2
    f 2//2 4//4 3//3 1//1
    f 2//2 6//6 8//8 4//4
    f 3//3 7//7 5//5 1//1
    f 4//4 8//8 7//7 3//3
    f 5//5 7//7 8//8 6//6


    this is the vertices and indices code I am using in java.

    Code :
    final short[] _indicesArray = { 0,4,5, 4,5,1, 1,3,2, 3,2,0, 1,5,7, 5,7,3, 2,6,4, 6,4,0, 3,7,6, 7,6,2, 4,6,7, 6,7,5 };
     
            final float[] vertices =
                {
                   -1.00000000f,-1.00000000f,-1.00000000f,//0
                   -1.00000000f,-1.00000000f, 1.00000000f,//1
                   -1.00000000f, 1.00000000f,-1.00000000f,//2
                   -1.00000000f, 1.00000000f, 1.00000000f,//3
                    1.00000000f,-1.00000000f,-1.00000000f,//4
                    1.00000000f,-1.00000000f, 1.00000000f,//5
                    1.00000000f, 1.00000000f,-1.00000000f,//6
                    1.00000000f, 1.00000000f, 1.00000000f//7
                };

    This is what I see when it renders. I wasn't allowed to display a screen shot so I had to draw it in text.

    Code :
    ************************
    *                      *
    *                      *
    *                      *
    *                      *
    *                      *
    *          **          *
    *        **  **        *
    *      **      **      *
    *   ***          ***   *
    ****                ****
    Last edited by Dratikus; 12-05-2013 at 03:55 PM.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    5
    edit.


    I've been messing around with the vertices. for some reason the order of the vertices is wrong.

    These vertices seem to work.
    Code :
            final float[] vertices =
                {
                    -1.00000000f,-1.00000000f, 1.00000000f,//0
                    -1.00000000f, 1.00000000f, 1.00000000f,//1
                     1.00000000f,-1.00000000f, 1.00000000f,//2
                     1.00000000f, 1.00000000f, 1.00000000f//3
                    -1.00000000f,-1.00000000f, -1.00000000f,//4
                    -1.00000000f, 1.00000000f, -1.00000000f,//5
                     1.00000000f,-1.00000000f, -1.00000000f,//6
                     1.00000000f, 1.00000000f, -1.00000000f//7
                };

    but these vertices do not
    Code :
            final float[] vertices =
                {
                     -1.00000000f, -1.00000000f, -1.00000000f,//0
                     -1.00000000f, -1.00000000f,  1.00000000f,//1
                     -1.00000000f,  1.00000000f, -1.00000000f,//2
                     -1.00000000f,  1.00000000f,  1.00000000f,//3
                      1.00000000f, -1.00000000f, -1.00000000f,//4
                      1.00000000f, -1.00000000f,  1.00000000f,//5
                      1.00000000f,  1.00000000f, -1.00000000f,//6
                      1.00000000f,  1.00000000f,  1.00000000f//7
                };

    I can't figure out why the order is getting messed up. It seems like I have everything exactly as in the OBJ file. What else do I need to do to make it work?
    Last edited by Dratikus; 12-05-2013 at 05:04 PM.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    5
    In over 3 months, no one has responded. This means either no one uses OpenGL, or the OpenGL community does not help anyone trying to learn OpenGL which, of course, leads to no one using OpenGL.

    For anyone reading this, I would also point out that DirectX does not have the issue I described in my other posts. Perhaps that is why no one uses OpenGL. Quid pro quo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •