Hello Guest

Classic nothing is rendering problem

  • 3 Replies
Classic nothing is rendering problem
« on: December 21, 2015, 13:31:23 »

before I start, I am new to LWJGL but I do have some experience with OpenGL in C++.

A long time ago I wrote a very basic game engine using OpenGL in C++ now I need to write that engine from C++ to Java, I decided to use LWJGL and I am able to create my window, load all the stuff that needs loading only when rendering I have the problem that nothing is rendering which is very frustrating. The only thing I can see is the blue clear color that I've set. Thing is, I have basically the same code on the other window in C++ and it works like a charm over there. After a bit of tinkering I found out that the only obvious way for the symptom to occur is to remove the code that sends matrices to the GPU, GL20.glUniformMatrix4fv, once I remove that call from my C++ engine I get the exact same result as in my Java attempt.
The thing is, I am calling that method with what I think are correct parameters, here's the snippet.

Code: [Select]
        FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
        buffer = value.get(buffer);
        GL20.glUniformMatrix4fv(getShaderData().getUniformMap().get(uniform).location, false, buffer);

value is a Matrix4f which I got from this math library https://github.com/JOML-CI/JOML

The other obvious ways why nothing is drawing would be that the model I upload is somehow not getting uploaded but I get no errors(even with glGetError()) and everything executes fine. This is my code for binding the buffers

Code: [Select]
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, meshData.getVertexArrayBuffers().get(MeshData.POSITIONS_VB));
        FloatBuffer posBuffer = Util.vector3ListToFloatBuffer(model.getPositions());
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, posBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, meshData.getVertexArrayBuffers().get(MeshData.TEXCOORD_VB));
        FloatBuffer texBuffer = Util.vector2ListToFloatBuffer(model.getTexCoords());
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, texBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, meshData.getVertexArrayBuffers().get(MeshData.NORMAL_VB));
        FloatBuffer normalBuffer = Util.vector3ListToFloatBuffer(model.getNormals());
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, normalBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, meshData.getVertexArrayBuffers().get(MeshData.TANGENT_VB));
        FloatBuffer tangentBuffer = Util.vector3ListToFloatBuffer(model.getTangents());
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tangentBuffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 0, 0);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, meshData.getVertexArrayBuffers().get(MeshData.INDEX_VB));
        IntBuffer indicesBuffer = Util.intListToIntBuffer(model.getIndices());
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);


I really need to get this java engine going but my brain's done I am clueless.



Re: Classic nothing is rendering problem
« Reply #1 on: December 21, 2015, 13:40:09 »
Be very careful with NIO Buffers and their flip/rewind/clear methods.
JOML, for instance, *DOES NOT* alter the buffer's position, as stated in the JavaDocs, when calling any JOML method taking a NIO Buffer.
This is much unlike the relative put/get methods of the NIO Buffer classes themselves, BUT on the other hand is just like how any method handling NIO Buffers in LWJGL 3 works.
So the buffer.flip() in your first code snippet in line 3 will actually set the limit of the 'buffer' to 0 (because the buffer's position is still at 0) and therefore GL20.glUniformMatrix4fv() will not upload anything.

Re: Classic nothing is rendering problem
« Reply #2 on: December 21, 2015, 14:25:13 »
First of all thanks for the fast reply,
unfortunately removing buffer.flip(); doesn't seem to change anything the same problem still applies I did scan the code for other occurrences of JOML's .get and found none.
Btw, is there a similar application to C++'s NVIDIA Nsight out there for Java? If my problem lies somewhere in the rendering pipeline, a program like Nsight is a real help.



Re: Classic nothing is rendering problem
« Reply #3 on: December 21, 2015, 14:33:27 »
If Nvidia's Nsight does not require any program instrumentation or compiling/linking against some runtime of it, you can also use it with Java/LWJGL. If there is an option to specify the executable or even attach to it while it's running, then just specify the java.exe/javaw.exe with appropriate command line arguments to launch your application.
I used gDEBugger this way successfully.