从VBO显示失败

时间:2014-07-07 15:03:35

标签: java opengl jogl vbo

我正在使用vbos来显示多维数据集。这是我的代码:

//创建VBO&#39>

                vertices = cb.getVertices();
                colors = cb.getColors();
                outlinesColors = cb.getOutlinesColors();
                indices = cb.getIndices();

                // vertex buffer
                gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferVertices);
                gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity() * Buffers.sizeOfBufferElem(vertices), vertices,
                        GL.GL_STATIC_DRAW);

                // color and outlines color buffer
                gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferColors);
                gl.glBufferData(GL.GL_ARRAY_BUFFER, colors.capacity() * Buffers.sizeOfBufferElem(colors) + outlinesColors.capacity() * Buffers.sizeOfBufferElem(outlinesColors), null,
                        GL.GL_STATIC_DRAW);
                gl.glBufferSubData(GL.GL_ARRAY_BUFFER,0, colors.capacity() * Buffers.sizeOfBufferElem(colors),
                        colors);

                gl.glBufferSubData(GL.GL_ARRAY_BUFFER,colors.capacity() * Buffers.sizeOfBufferElem(colors), outlinesColors.capacity() * Buffers.sizeOfBufferElem(outlinesColors),
                        outlinesColors);

                // indices buffer
                gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, cb.gpuBufferIndices);
                gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * Buffers.sizeOfBufferElem(indices), indices,
                        GL.GL_STATIC_DRAW);

注意:cb是缓冲区列表中的缓冲区,其中包含多维数据集的数据

这是渲染的代码:

for (CellQuadBuffer cb : listBuffers) {
        vertices = cb.getVertices();
        colors = cb.getColors();
        outlinesColors = cb.getOutlinesColors();
        indices = cb.getIndices();

        if (vboEnabled) {
            //rendering the cubes
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferVertices);
            gl.glVertexPointer(CellQuadBuffer.NB_COORDINATES_PER_VERTEX, GL.GL_FLOAT, 0, 0);

            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferColors);
            gl.glColorPointer(CellQuadBuffer.NB_COLORS_PER_VERTEX, GL.GL_UNSIGNED_BYTE,0 ,0);


            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, cb.gpuBufferIndices);

            gl.glDrawElements(GL2.GL_QUADS, cb.getNbIndices(), GL.GL_UNSIGNED_INT, 0);

            // rendering the outlinesColors of the cubes
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cb.gpuBufferColors);
            gl.glColorPointer(CellQuadBuffer.NB_COLORS_PER_VERTEX, GL.GL_UNSIGNED_BYTE, 0,colors.capacity() * Buffers.sizeOfBufferElem(colors));

            gl.glDrawElements(GL2.GL_LINES,  cb.getNbIndices(), GL.GL_UNSIGNED_INT, 0);



        }

现在我跑的时候显示器出现了问题:一些立方体根本没有显示,显示轮廓颜色有问题,我想因为我使用相同的vbo颜色和轮廓颜色,可能有一个错误在指定glBufferSubData或glColorPointer的偏移量时,我无法弄明白。

0 个答案:

没有答案
相关问题