我是pyglet的新手,B4,我尝试过在Pygame中使用PyOpenGL,但是PyOpenGL创建了奇怪的NuffFunctionErrors,所以我搬到了Pyglet。
我已经尝试过这段代码,它运行得很完美:
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()我试着用VBO重写这个,但是我有一个黑窗口。我的密码怎么了?
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()发布于 2015-10-14 21:00:42
好的,我收到了注释中的答案,但问题是,12个字节没有足够的4,6个浮动。
每个浮点数使用4字节。
https://stackoverflow.com/questions/33086942
复制相似问题