我仍然试图掌握OpenGL的怪癖,但它无助于尝试在使用OpenGL 4.2 Core的OSX上学习,这可能是相关的。
我只是想做的就是复制一个从目标文件中解析出来的顶点数据数组,如果我遍历那些数据,它会很好地显示到绑定的VBO中,但是当我使用<script>
$(function () {
//when the modal is closed
$('#modal-container').on('hidden.bs.modal', function () {
//remove the bs.modal data attribute from it
$(this).removeData('bs.modal');
//and empty the modal-content element
$('#modal-container .modal-content').empty();
//remove backdrop
$('#modal-container').find('.modal-backdrop').removeClass('modal-backdrop');
});
});
$('#modal-container').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var url = button.attr("href");
var modal = $(this);
//note that this will replace the content of modal-contant ever time the modal is opened
modal.find('.modal-content').load(url);
});
</script>
时返回当前绑定的VBO的内容它显示几十行的数据然后开始显示我只能看到像这样的损坏数据......
glGetBufferSubData
即使我尝试使用全零来初始化相同或相似大小的缓冲区,也会发生这种情况,在任意数量之后它会变得奇怪。这是一个片段,看看我在做什么,但我无法想象发生了什么。
Vertex: (-0.437500, 0.328125, 0.765625)
Vertex: (0.500000, 0.390625, 0.687500)
Vertex: (-0.500000, 0.390625, 0.687500)
Vertex: (0.546875, 0.437500, 0.578125)
Vertex: (-0.546875, 0.437500, 0.578125)
-------------------vvvvv corrupts here
Vertex: (0.625000, 19188110749038498652920741888.000000, 12125095608195490978463744.000000)
Vertex: (68291490374736750313472.000000, 70795556751816250086766057357312.000000, 0.000000)
Vertex: (4360831549674110915425861632.000000, 4544202249129758853702852018176.000000, 50850084445497733730842814971904.000000)
答案 0 :(得分:1)
我看到两个问题:
glBufferData(GL_ARRAY_BUFFER, com.attrib->num_vertices*sizeof(GLfloat), 0, GL_STATIC_DRAW);
需要整个数据的字节大小。
因为每个顶点都有X,Y,Z,所以它应该是
glBufferData(GL_ARRAY_BUFFER, com.attrib->num_vertices*3*sizeof(GLfloat), 0, GL_STATIC_DRAW);
注意'3'。
分配空间并读取缓冲区时相同。
GLfloat *vertBuffer = malloc(sizeof(GLfloat) * com.attrib->num_vertices * 3);
glGetBufferSubData(GL_ARRAY_BUFFER, 0, com.attrib->num_vertices * 3 * sizeof(GLfloat), vertBuffer);