0

I have tried following this and this to get vertex arrays from jogl to work and, although its not throwing any errors any more, it also isn't rendering anything but a blank screen. Here is the code:

public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context

    vertexArray = new float[]
            {-100f,-100f,-50f,
            100f,-100f,-50f,
            100f,100f,-50f,
            -100f,100f,-50f};

    vertexBuffer = BufferUtil.newFloatBuffer(vertexArray.length);
    for(int i=0;i<vertexArray.length;i++){
        vertexBuffer.put(vertexArray[i]);
    }
    //vertexBuffer.put(vertexArray); //neither of these versions work
    vertexBuffer.rewind();

    indexArray = new int[]{0,1,2,3,0,1,2,3,0,1,2,3};
    indexBuffer = BufferUtil.newIntBuffer(indexArray.length);
    for(int i=0;i<indexArray.length;i++){
        indexBuffer.put(indexArray[i]);
    }
    //indexBuffer.put(indexArray);
    indexBuffer.rewind();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
    gl.glLoadIdentity(); // reset the model-view matrix

    gl.glColor3f(1f, 1f, 1f);

    gl.glEnableClientState(GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL_FLOAT, 0, vertexBuffer);

    gl.glDrawElements(GL_QUADS, indexArray.length, GL_UNSIGNED_INT, indexBuffer);

    gl.glDisableClientState(GL_VERTEX_ARRAY);

    gl.glTranslatef(0f, 0f, -60f);
    GLUT glut = new GLUT();
    //glut.glutSolidTeapot(1);
}

When I uncomment the teapot code I can see that, so I'm pretty sure its specific to glDrawElements. I have around zero confidence that I'm using the correct gl.GL_TYPE constants, but none of the one's I've tried have worked.

  • Are you setting up a projection matrix somewhere in code now show here? Otherwise your coordinates are way outside the visible range, and will therefore be clipped away. – Reto Koradi Apr 03 '15 at 04:14
  • 1
    I agree with Reto, your vertex coordinates are probably outside of the view frustum. Your type seems to be correct: https://github.com/gouessej/Ardor3D/blob/master/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java#L1619 Please use the very latest version of JOGL, BufferUtil doesn't exist in JOGL 2.3.1 (latest version, April 2015), rather use Buffers.newDirectIntBuffer(): http://jogamp.org/deployment/jogamp-next/javadoc/gluegen/javadoc/com/jogamp/common/nio/Buffers.html#newDirectIntBuffer(int) Please show your whole code. – gouessej Apr 03 '15 at 11:50
  • Use this [sample](https://jogamp.org/wiki/index.php/Jogl_Tutorial#Hello_Triangle) as a starting point – elect Aug 12 '15 at 09:45

0 Answers0