我正在尝试遵循OpenGL编程指南(又名红皮书)
但我使用的是pyglet1.2(因为我必须在高中项目中使用Python,我更喜欢python3.4)
所以我想让the first example of the chapter 3工作
我试图使我的代码最接近示例:
import pyglet
from pyglet.gl import *
def cube(x, y, z, size):
vertices = (GLfloat * 24) (*[x, y, z,
x, y + size, z,
x, y + size, z + size,
x, y, z + size,
x + size, y, z,
x + size, y + size, z,
x + size, y + size, z + size,
x + size, y, z + size])
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, vertices)
indices = (GLubyte * 24) (*[0, 1, 2, 3,
4, 5, 6, 7,
0, 1, 5, 4,
7, 6, 2, 3,
0, 4, 7, 3,
1, 5, 6, 2])
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices)
glDisableClientState(GL_VERTEX_ARRAY)
window = pyglet.window.Window(resizable=True)
@window.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1, 1, 1)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glLoadIdentity()
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0)
glScalef(1, 2, 1)
cube(50, 50, 0, 100)
glFlush()
@window.event
def on_resize(width, height):
glViewport(0, 0, (GLsizei) (width), (GLsizei) (height) )
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(-1, 1, -1, 1, 1.5, 20)
glMatrixMode(GL_MODELVIEW)
glClearColor(0, 0, 0, 0)
glShadeModel(GL_FLAT)
pyglet.app.run()
正如你所看到的,由于没有过剩,我不得不制作我自己的立方体函数
所以这里的问题是只应用了ModelView矩阵
只有应用了glScalef
方法的正方形才会出现
我试图在on_draw
方法中移动投影矩阵的变化
它只会使正方形消失
我还试图使用glFrustum
来更改模型视图矩阵,
这并没有改变什么
如果有人知道这个错误是从哪里来的, 我很高兴听到。在
目前没有回答
相关问题 更多 >
编程相关推荐