سؤال

I started to follow a tutorial about modern OpenGL rendering and altered the c++ code from a VBO lesson to work with LWJGL. I initialized the VBO with the following code:

int vbo = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);

"buffer" is initialized as

FloatBuffer buffer = BufferUtils.createFloatBuffer(9);

and then filled with {-0.5f, -0.5f, 0, 0.5f, -0.5f, 0, 0, 0.5f, 0} via

buffer.put(val)

My game loop looks like this:

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL20.glEnableVertexAttribArray(0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
GL11.glDrawArrays(GL11.GL_POINTS, 0, 3);
GL20.glDisableVertexAttribArray(0);
Display.update();

But all I get is a white dot in the center of the screen. I found a similar question (VBO: Array not drawn), but the solution did not fix my problem. The tutorial I used is http://ogldev.atspace.co.uk/www/tutorial02/tutorial02.html and http://ogldev.atspace.co.uk/www/tutorial03/tutorial03.html. When I try to draw GL_TRIANGLES instead of GL_POINTS, nothing is drawn onto the screen.

هل كانت مفيدة؟

المحلول 2

After wasting hours reading different tutorials, I figured out that I did not rewind() my buffer...

GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

and

GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

as suggested in VBO: Array not drawn was not necessary.

نصائح أخرى

Use glTranslate*() to set a position where you want to draw something. It can be sorta deprecated, but it works.
Here you can find a discussion about it.
Your code should look the following way:

glPushMatrix();
glTranslate*();
//draw something
glPopMatrix();

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top