1

I am getting started with opengl in python and i have the exact same code like that of the youtuber's , but it gives me an error :

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)

And here is my code :

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()


    

4
  • 3
    It is a typo. A , is missing in vertices. (3rd vertex) Commented Sep 29, 2020 at 11:58
  • ohhhhh , such a silly mistake !!!! Commented Sep 29, 2020 at 12:25
  • Silly or not, Thanks! I had displaced parentheses in a long array, which led me here. Commented Mar 22, 2021 at 14:29
  • Nice it helped you @Joshua Clayton Commented Mar 23, 2021 at 16:36

1 Answer 1

1

It is a typo. A , is missing in the list of vertices. (3rd vertex):

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),
           )
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.