Results 1 to 5 of 5

Thread: glVertex3fv() and two dimensinal array parameter?

  1. #1
    Member Newbie
    Join Date
    Jul 2009
    Posts
    33

    glVertex3fv() and two dimensinal array parameter?

    I am reading the Redbook and trying to convert this C code to Java:
    Code :
    #define X .525731112119133606 
    #define Z .850650808352039932
     
    static GLfloat vdata[12][3] = {    
       {-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},    
       {0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},    
       {Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0} 
    };
    static GLuint tindices[20][3] = { 
       {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},    
       {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},    
       {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, 
       {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
    int i;
     
    glBegin(GL_TRIANGLES);    
    for (i = 0; i < 20; i++) {    
       /* color information here */ 
       glVertex3fv(&amp;vdata[tindices[i][0]][0]); 
       glVertex3fv(&amp;vdata[tindices[i][1]][0]); 
       glVertex3fv(&amp;vdata[tindices[i][2]][0]); 
    }
    glEnd();

    The Java code would be something like:
    Code :
    final float X = .525731112119133606f;
    final float Z = .850650808352039932f;
    float vdata[][] = new float[][]{    
               {-X, 0.0f, Z}, {X, 0.0f, Z}, {-X, 0.0f, -Z}, {X, 0.0f, -Z},    
               {0.0f, Z, X}, {0.0f, Z, -X}, {0.0f, -Z, X}, {0.0f, -Z, -X},    
               {Z, X, 0.0f}, {-Z, X, 0.0f}, {Z, -X, 0.0f}, {-Z, -X, 0.0f} 
            };
    int tindices[][] = new int[][]{ 
               {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},    
               {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},    
               {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6}, 
               {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
     
    gl.glBegin(GL.GL_TRIANGLES);    
            for (int i = 0; i < 20; i++) {    
               /* color information here */ 
     
               // WHAT TO CHANGE HERE???
               gl.glVertex3fv(vdata[tindices[i][0]][0],0); 
               gl.glVertex3fv(vdata[tindices[i][1]][0]); 
               gl.glVertex3fv(vdata[tindices[i][2]][0]); 
            }
    gl.glEnd();

    The problem is that glVertex3fv() does not take a two dimensional array as parameter. C language solves that by using a reference to such an array.

    But how do we do in Java?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: glVertex3fv() and two dimensinal array parameter?

    Like this :
    [snip]

    EDIT : sorry, my post was totally wrong !

  3. #3
    Member Newbie
    Join Date
    Jul 2009
    Posts
    33

    Re: glVertex3fv() and two dimensinal array parameter?

    Thanks!

    What about these lines of code:
    Code :
    glVertex3fv(&amp;vdata[tindices[i][0]][0]); 
    glVertex3fv(&amp;vdata[tindices[i][1]][0]); 
    glVertex3fv(&amp;vdata[tindices[i][2]][0]);

    How do I rewrite them in Java?
    I mean, glVertex3fv(vdata) is not the same as the C arrays.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: glVertex3fv() and two dimensinal array parameter?

    In fact &amp;vdata[ti][0] in C is equivalent to vdata[ti] in both C and Java.
    I wonder why it was written that way in the first place ...

  5. #5
    Member Newbie
    Join Date
    Jul 2009
    Posts
    33

    Re: glVertex3fv() and two dimensinal array parameter?

    I donīt know why, I found the example here: http://www.glprogramming.com/red/chapter02.html#name6

    The problem is solved:
    Code :
     final float X = 3.525731112119133606f;
            final float Z = 3.850650808352039932f;
     
            float vdata[][] = new float[][]{
               {-X, 0.0f, Z}, {X, 0.0f, Z}, {-X, 0.0f, -Z}, {X, 0.0f, -Z},
               {0.0f, Z, X}, {0.0f, Z, -X}, {0.0f, -Z, X}, {0.0f, -Z, -X},
               {Z, X, 0.0f}, {-Z, X, 0.0f}, {Z, -X, 0.0f}, {-Z, -X, 0.0f}
            };
            int tindices[][] = new int[][]{
               {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
               {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
               {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
               {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
     
     
            gl.glBegin(GL.GL_TRIANGLES);
                for (int i = 0; i < 20; i++)
                {
                      gl.glNormal3fv(vdata[tindices[i][0]], 0);
                      gl.glVertex3fv(vdata[tindices[i][0]], 0);
                      gl.glNormal3fv(vdata[tindices[i][1]], 0);
                      gl.glVertex3fv(vdata[tindices[i][1]], 0);
                      gl.glNormal3fv(vdata[tindices[i][2]], 0);
                      gl.glVertex3fv(vdata[tindices[i][2]], 0);
     
                      System.out.println(vdata[tindices[i][0]][0]);
                }
            gl.glEnd();

Similar Threads

  1. Array of images as kernel parameter
    By pelotoescogorciao in forum OpenCL
    Replies: 0
    Last Post: 01-05-2013, 11:15 AM
  2. sized array of float as parameter to nvidia cg shader
    By siddharth.cmdz in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 10-16-2012, 10:33 PM
  3. Array of image_Xt objects as parameter?
    By grassi3000 in forum OpenCL
    Replies: 4
    Last Post: 02-29-2012, 05:39 PM
  4. glVertex3fv problem
    By leopard in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-19-2009, 03:23 PM
  5. glVertex3fv
    By kazmalak in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-05-2005, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean