1

I am trying to find what am I doing wrong in my code. I am using JOGL.

I'd like to make two VBOs, one for vertices, other for indices, inside a given object.

There is no error inside init(GLAutoDrawable glAutoDrawable) function, but display(GLAutoDrawable glAutoDrawable) does not show my object when running the program.

Where am I making a mistake? Thank you for help.

My code:

public class Test1 implements GLEventListener {

    private int program;

    IntBuffer vao = IntBuffer.allocate(1);
    private IntBuffer buffers = IntBuffer.allocate(2);
    private float[] vertices = {
            -0.853250f, -0.136293f, -0.188932f,
             -0.129650f, 0.416492f, 0.336788f,
             -1.129635f, 0.416492f, 0.661708f,
             -1.747674f, 0.416492f, -0.188932f,
             -1.129635f, 0.416492f, -1.039572f,
             -0.129650f, 0.416492f, -0.714652f,
             -0.576865f, 1.310922f, 0.661708f,
             -1.576849f, 1.310922f, 0.336788f,
             -1.576849f, 1.310922f, -0.714652f,
             -0.576865f, 1.310922f, -1.039572f,
             0.041175f, 1.310922f, -0.188932f,
             -0.853250f, 1.863707f, -0.188932f
    };

1 Answer 1

1

There are a considerable number of things wrong.

  • Your Vertex Shader is very clearly the code for a Fragment Shader. I don't know where you copied it from, but you need to fix that.
  • gluPerspective is intended for use with the Fixed-Function-Pipeline. It has no effect when you're using programmable shaders. You need to put a uniform for a projection matrix in your vertex shader and manually pass that matrix to the GL.
  • Most Java Wrappers for OpenGL require that their Buffers be "Directly Allocated", which means the backing memory is natively allocated, as opposed to being Java-Allocated. The easiest way to do that is with ByteBuffer.allocateDirect(sizeInBytes);, which returns a ByteBuffer that can then be converted to an IntBuffer or FloatBuffer using asFloatBuffer and asIntBuffer.
Sign up to request clarification or add additional context in comments.

1 Comment

You can use com.jogamp.common.nio.Buffers.newDirectIntBuffer(int) to create direct NIO buffers for JOGL and "new GLU()" should be replaced by "GLU.createGLU(gl)". Excellent reply by the way, it deserves an upvote :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.