Pyopengl 给我价值错误无法识别问题

Posted

技术标签:

【中文标题】Pyopengl 给我价值错误无法识别问题【英文标题】:Pyopengl giving me Value error not able to identify the problem 【发布时间】:2020-09-29 11:53:53 【问题描述】:

我开始在 python 中使用 opengl,我的代码与 youtuber 的代码完全相同,但它给了我一个错误:

pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last):
    File "C:/python files/Opengl/Opengl_cheatsheet.py", line 66, in <module>
    main()   File "C:/python files/Opengl/Opengl_cheatsheet.py", line 61, in main
    cube()   File "C:/python files/Opengl/Opengl_cheatsheet.py", line 39, in cube
    glVertex3fv(vertices[vertex])   File "src/latebind.pyx", line 39, in OpenGL_accelerate.latebind.LateBind.__call__
    File "src/wrapper.pyx", line 299, in OpenGL_accelerate.wrapper.Wrapper.__call__
    File "src/wrapper.pyx", line 161, in OpenGL_accelerate.wrapper.PyArgCalculator.c_call
    File "src/wrapper.pyx", line 128, in OpenGL_accelerate.wrapper.PyArgCalculatorElement.c_call
    File "src/wrapper.pyx", line 114, in OpenGL_accelerate.wrapper.PyArgCalculatorElement.c_call
    File "src/arraydatatype.pyx", line 419, in OpenGL_accelerate.arraydatatype.AsArrayTypedSizeChecked.c_call
    ValueError: ('Expected 12 byte array, got 8 byte array', (-1, 0), None)

这是我的代码:

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

#vertices for the cube tuples
vertices = ((1, -1, -1),
            (1, 1, -1),
            (-1, 1 -1),
            (-1, -1, -1),
            (1, -1, 1),
            (1, 1, 1),
            (-1, -1, 1),
            (-1, 1, 1),
            )

#edge for the cube tuples
edges = ((0,1),
         (0,3),
         (0,4),
         (2,1),
         (2,3),
         (2,7),
         (6,3),
         (6,4),
         (6,7),
         (5,1),
         (5,4),
         (5,7),
         )


def cube():

    glBegin(GL_LINES)

    for edge in edges:
        for vertex in edge:
            glVertex3fv(vertices[vertex])
            
    
    glEnd()

def main():
    pygame.init()
    display = (800, 800)
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

    gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
    glTranslatef(0.0, 0.0, -5)
    glRotatef(0, 0, 0, 0)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

        cube()
        pygame.display.flip()

        pygame.time.wait(10)

main()


    

【问题讨论】:

这是一个错字。 vertices 中缺少 ,。 (第三个顶点) ohhhhh,真是个愚蠢的错误!!!! 傻不傻,谢谢!我把括号排成一长串,导致我来到这里。 很好,它帮助了你@Joshua Clayton 【参考方案1】:

这是一个错字。顶点列表中缺少,。 (第三个顶点):

vertices = ((1, -1, -1),
           (1, 1, -1),
           (-1, 1 -1),         # <-------
           (-1, -1, -1),
           (1, -1, 1),
           (1, 1, 1),
           (-1, -1, 1),
           (-1, 1, 1),
           )

【讨论】:

以上是关于Pyopengl 给我价值错误无法识别问题的主要内容,如果未能解决你的问题,请参考以下文章

Smarty:无法识别继续标签

keil MDK 不识别 Jlink 错误提示:unknown jtag device

Core ML iOS 11 无法正确识别图像

无法识别 App Store 更新

getIntent 错误,无法识别

argparse 错误:无法识别选项