1

I am currently programming a game with PyOpenGL with PyGame, and when using Vertex Buffers, graphical glitches occur. The glitches include lines being drawn between each model when it shouldn't. I have found that alternating between Ground() and GroundVBO() does not cause any graphical glitches most of the time. Is there anything that I am missing?

global vbo
vbo = 0
def Ground():
    glBegin(GL_LINES)
    for edge in ground_edges:
        for vertex in edge:
            glVertex3fv(ground_verticies[vertex])
    glEnd()
def GroundVBO():
    for edge in ground_edges:
        for vertex in edge:
            ground_noot = glVertex3fv(ground_verticies[vertex])
    vbo = glGenBuffers(1)
    glBindBuffer (GL_ARRAY_BUFFER, vbo)
    glBufferData (GL_ARRAY_BUFFER, len(ground_verticies)*4, ground_noot, GL_STATIC_DRAW)
    glVertexPointer (3, GL_FLOAT, 0, None)
    glDrawArrays(GL_LINES, 0, 300)

2
  • I believe what was causing the problem was specifying the vertices outside the glBegin/glEnd. All I have to do now is rewrite some of the code, and it should work! Commented May 10, 2020 at 22:57
  • I have now got it to work, I was stuck on the array of numbers for the vertex pointer, as I was appending the entire vertex which had brackets around it. What I had to do was append each point individually so there were do brackets. Commented May 13, 2020 at 1:11

1 Answer 1

1

If you want to use fixed function attributes, then you have to enable the client-side capability by glEnableClientState. Specifying the vertices by glVertex3fv in a loop is superfluous. Specifying a vertex outside a glBegin/glEnd sequence results in undefined behavior.
The last parameter to glDrawArrays is the number of vertex coordinates:

def GroundVBO():

    vbo = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, vbo)
    glBufferData(GL_ARRAY_BUFFER, len(ground_verticies)*4, ground_noot, GL_STATIC_DRAW)

    glEnableClientState(GL_VERTEX_ARRAY)
    glVertexPointer(3, GL_FLOAT, 0, None)
    glDrawArrays(GL_LINES, 0, len(ground_verticies))
    glDisableClientState(GL_VERTEX_ARRAY)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.