【问题标题】:Object disappears after updating buffer更新缓冲区后对象消失
【发布时间】:2015-05-31 01:04:08
【问题描述】:

我尝试实现三角形细分算法,但我遇到了如果我用更大的数组更新缓冲区,几何图形就会消失。如您所见,我正在使用glBufferData() 来更新缓冲区。如果我使用相同大小(或更小)的数组更新缓冲区,它会起作用。它应该可以工作,但事实并非如此。

glGetString(GL_VERSION) -> 3.1.0 - Build 9.17.10.3517
glGetString(GL_VENDOR) -> Intel
glEnableClientState(GL_VERTEX_ARRAY) -> DONE
glEnableClientState(GL_INDEX_ARRAY) -> DONE
glEnable(GL_NORMALIZE) -> DONE
glEnable(GL_DEPTH_TEST) -> DONE
glDisable(GL_CULL_FACE) -> DONE
glCullFace(Off) -> DONE
glDepthFunc(LessOrEqual) -> DONE
glBindBuffer(VertexArray, -1) -> DONE
glBindBuffer(ElementArray, -1) -> DONE
glBindTexture(Texture2D, -1) -> DONE
glActiveTexture(0) -> DONE
glClientActiveTexture(0) -> DONE
glViewport(0, 0, 800, 600) -> DONE

// Initializing
glGenBuffers() -> 1
glBindBuffer(VertexArray, 1) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=9 cap=9], Static) -> DONE
glGenBuffers() -> 2
glBindBuffer(VertexArray, 2) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=6 cap=6], Static) -> DONE
glGenBuffers() -> 3
glBindBuffer(VertexArray, 3) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=9 cap=9], Static) -> DONE
glGenBuffers() -> 4
glBindBuffer(ElementArray, 4) -> DONE
glBufferData(ElementArray, java.nio.DirectIntBufferU[pos=0 lim=3 cap=3], Static) -> DONE

glClear(ColorAndDepth) -> DONE
glLoadIdentity() -> DONE
glMatrixMode(Projection) -> DONE
glLoadIdentity() -> DONE
gluPerspective(60.0, 1.3333334, 0.001, 999999.0) -> DONE
glMatrixMode(ModelView) -> DONE
glBindBuffer(VertexArray, -1) -> DONE
glBindBuffer(ElementArray, -1) -> DONE

glPushMatrix() -> DONE
    glTranslatef(0.0, 0.0, 0.0) -> DONE
    glScalef(1.0, 1.0, 1.0) -> DONE
    glMultMatrix(java.nio.DirectFloatBufferU[pos=0 lim=16 cap=16]) -> DONE

    glPolygonMode(FrontAndBack, Line) -> DONE
    glColor3f(1.0, 0.0, 0.0) -> DONE
    glBindBuffer(VertexArray, 1) -> DONE
    glVertexPointer(3, Float, 0, 0) -> DONE
    glBindBuffer(VertexArray, 3) -> DONE
    glNormalPointer(Float, 0, 0) -> DONE
    glBindBuffer(ElementArray, 4) -> DONE
    glDrawElements(Triangles, 3, UnsignedInt, 0) -> DONE
glPopMatrix() -> DONE
// Cycle end

// Updating
glBindBuffer(VertexArray, 1) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=18 cap=18], Static) -> DONE
glBindBuffer(VertexArray, 2) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12], Static) -> DONE
glBindBuffer(VertexArray, 3) -> DONE
glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=18 cap=18], Static) -> DONE
glBufferData(ElementArray, java.nio.DirectIntBufferU[pos=0 lim=6 cap=6], Static) -> DONE

glClear(ColorAndDepth) -> DONE
glLoadIdentity() -> DONE
glMatrixMode(Projection) -> DONE
glLoadIdentity() -> DONE
gluPerspective(60.0, 1.3333334, 0.001, 999999.0) -> DONE
glMatrixMode(ModelView) -> DONE
glPolygonMode(FrontAndBack, Fill) -> DONE
glBindBuffer(VertexArray, -1) -> DONE
glBindBuffer(ElementArray, -1) -> DONE

glPushMatrix() -> DONE
    glTranslatef(0.0, 0.0, 0.0) -> DONE
    glScalef(1.0, 1.0, 1.0) -> DONE
    glMultMatrix(java.nio.DirectFloatBufferU[pos=0 lim=16 cap=16]) -> DONE

    glPolygonMode(FrontAndBack, Line) -> DONE
    glColor3f(1.0, 0.0, 0.0) -> DONE
    glBindBuffer(VertexArray, 1) -> DONE
    glVertexPointer(3, Float, 0, 0) -> DONE
    glBindBuffer(VertexArray, 3) -> DONE
    glNormalPointer(Float, 0, 0) -> DONE
    glBindBuffer(ElementArray, 4) -> DONE
    glDrawElements(Triangles, 6, UnsignedInt, 0) -> DONE
glPopMatrix() -> DONE

0 - 这是我想要的结果。它在使用新缓冲区设置时有效。
1 - 这是一个源三角形。


【问题讨论】:

    标签: opengl 3d rendering lwjgl


    【解决方案1】:

    好的!我终于找到了问题的根源。细分过程后,所有索引都变为0。谢谢!并且不要忘记检查您发送的实际数据!

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 2012-04-24
      相关资源
      最近更新 更多