0

I have a problem when trying to run a simple Java code to render a simple triangle using shaders. While in Windows it works nice screenshot, in Linux it isn't displaying anything but a black screen.

I am using Ubuntu 14.10 and Mesa 10.1.3, and lwjgl as the framework.

Here is the code for my main drawing function:

private static void render() {
     GL20.glEnableVertexAttribArray(0);

     GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
     GL20.glVertexAttribPointer(0, 3, GL11.GL_DOUBLE, false, Vertex.BYTES, 0);

     GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);

     GL11.glDrawElements(GL11.GL_TRIANGLES, vertices.size(), GL11.GL_UNSIGNED_INT, 0);

     GL20.glDisableVertexAttribArray(0);
}

Here is a full version of the simple code for testing purposes: code.

EDIT: After running the same code various times, one of them draw this, and I haven't been able to replicate it.

1
  • Note that questions are expected to be self contained, including code. I copied the most important part of the code from your pastebin. Please keep this in mind for future questions, otherwise they tend to be closed quickly. Commented Sep 21, 2014 at 12:14

3 Answers 3

2

The biggest problem right now is that you have a core profile context but you are not using Vertex Array Objects. Why Windows is allowing this, is hard to say, but Linux is giving the behavior you would expect.

You are going to need to create and bind a Vertex Array Object at least one time in your software because this is a required step in writing 3.3 core profile software.

If you add this to Main.create (...), you will have compliant 3.3 core code:

int vao = GL30.glGenVertexArrays ();
GL30.glBindVertexArray (vao);
Sign up to request clarification or add additional context in comments.

1 Comment

By the way, this situation should be generating a GL_INVALID_OPERATION error. I would suggest you get into the habit of inserting glGetError (...) calls to trace errors, because this would have been easier to diagnose if your question included an OpenGL error code.
2

You're missing a glClear(). Add this at the start of your render() function:

GL15.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Without clearing the buffers, the content will be arbitrary data. Particularly if the depth buffer is not cleared, it might contain depth values that are all less than the depth of your triangle, and nothing will be drawn.

Another problem is that you are creating a Core Profile context:

 ContextAttribs contextAtrributes = new ContextAttribs(3, 3).withProfileCore(true);

but your code is not compliant with the Core Profile. You will need to create an use a Vertex Array Object (VAO). Setting up vertex state without using a VAO is deprecated in modern OpenGL, and not supported in the Core Profile. You will need code like this at the start of your setup:

int vao = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vao);

Not really a problem that will prevent the code from working, but I would also recommend to use float values for your coordinates. The double values you are specifying will be cast to float values by OpenGL. So you're just creating extra overhead, and using more memory, by operating with doubles.

1 Comment

Even with the glCLear() the problem is still the same, it doesn't render. I've tested other vertex/faces data and I only get a square in the top right corner of the screen (while in windows I got nice triangles)
1

First things first: Check that OpenGL is properly supported. Run the glxinfo command and post its output here; you can safely omit the lengthy list of supported framebuffer formats (GLXVisuals and GLXFBConfigs).

One possibility is, that you're running in a composited environment and don't use double buffering. Actually single buffered rendering and window composition are a match made in heaven, because the composition step acts very much like a buffer swap, but the design of the existing drivers and APIs make it hard to synchronize between finishing the rendering and composition so the double buffer swap is repurposed for that.

Comments

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.