1
votes

I'm new in pyglet, B4, I've tried to use PyOpenGL with Pygame, but PyOpenGL creates weird NuffFunctionErrors, so I've moved to Pyglet.

I've tried out this code, it runs perfectly:

from pyglet.gl import *

window = pyglet.window.Window()

vertices = [
    0, 0,
    window.width, 0,
    window.width, window.height]
vertices_gl = (GLfloat * len(vertices))(*vertices)

glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(2, GL_FLOAT, 0, vertices_gl)

@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    glDrawArrays(GL_TRIANGLES, 0, len(vertices) // 2)

pyglet.app.run()

I've tried to rewrite this to use VBOs, but I've got a black window. What's wrong with my code?

from pyglet.gl import *

window = pyglet.window.Window()

vertices = [
    0, 0,
    window.width, 0,
    window.width, window.height]
vertices_gl = (GLfloat * len(vertices))(*vertices)


glEnableClientState(GL_VERTEX_ARRAY)

buffer=(GLuint)(0)
glGenBuffers(1,buffer)
glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer)
glBufferData(GL_ARRAY_BUFFER_ARB, 4*3,
                    vertices_gl, GL_STATIC_DRAW)


glVertexPointer(2, GL_FLOAT, 0, 0)

@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    glDrawArrays(GL_TRIANGLES, 0, len(vertices) // 2)

@window.event
def on_resize(width, height):
    glViewport(0, 0, width, height)
    glMatrixMode(gl.GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, width, 0, height, -1, 1)
    glMatrixMode(gl.GL_MODELVIEW)

pyglet.app.run()
1
Not familiar with these Java bindings, but 12 bytes (second argument to glBufferData) doesn't look like it would be enough for the 6 floats you have in vertices.Reto Koradi
@RetoKoradi Thanks, it has fixed the problem.Sasszem

1 Answers

0
votes

Ok, I received the answer in comment, but the problem was that 12 bytes wan't enough 4 six floats.

Each float uses 4 byte.