Reputation: 105
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()
Upvotes: 1
Views: 165
Reputation: 211277
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), )
Upvotes: 1