Pregunta

I am new in jogl and try to render rectangle by using VBO. There are given two array: first arrey is

float vertex[] = {-2.0f, -2.0f, -2.0f,
            2.0f, -2.0f, -2.0f,
            -2.0f, -2.0f, 2.0f,
            2.0f, -2.0f, 2.0f
        };

second array is

float colors[] = {1.0f, 0.0f, 0.0f,
            0.0f, 1.0f, 0.0f,
            0.0f, 0.0f, 1.0f,
            1.0f, 1.0f, 0.0f
        };

and then I try to initialize vertex buffers

        pointsbf = Buffers.newDirectFloatBuffer(vertex.length);
        colorsbf = Buffers.newDirectFloatBuffer(colors.length);
        pointsbf.put(vertex);
        colorsbf.put(colors); 
        pointsbf.rewind();
        colorsbf.rewind();

the code above has been written in INIT() function; The code bellow has been written in DISPLAY() function;

     gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

    gl.glVertexPointer(3, GL.GL_FLOAT, 0, pointsbf);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsbf);

    gl.glDrawArrays(GL.GL_TRIANGLES, 0, totalNumVerts);

    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL2.GL_COLOR_ARRAY);

but the code after running shows just black screen(((

¿Fue útil?

Solución

Have you modified the projection matrix and the model view matrix? If your vertices aren't in the view frustum, you won't see them.

You can use my example and modify it to use VBOs: http://en.wikipedia.org/wiki/Java_OpenGL#Code_example

Keep in mind that the official JogAmp forum is a better place to get answers about JOGL.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top