Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Hi i get a very strange problem when running this code. I don't see how it should conflict with the OpenGL Api either. Heres the code:
import sys
sys.path.append("..\Blocks")
print sys.path
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import random
import BlockModel
except:
print "Cant Find Block Model"
def createBlock():
block = BlockModel.Block()
blockVertices = block.returnVertices()
blockEdges = block.returnEdges()
blockSurface = block.returnSurface()
glBegin(GL_QUADS)
for surface in blockSurface:
for faceVertex in surface:
glVertex3fv(blockVertices[faceVertex])
glEnd
glBegin(GL_LINES)
for edge in blockEdges:
for vertex in edge:
glVertex3fv(blockVertices[vertex])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(15, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(random.randrange(-5,5),random.randrange(-5,5), -40)
exit = False
while not exit:
pygame.time.wait(10)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
createBlock()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
main()
I get this error when trying to run the program:
C:\Users\Haavard\Desktop\MinecraftPythonProject\framework>python main.py
['C:\\Users\\Haavard\\Desktop\\MinecraftPythonProject\\framework', 'C:\\Windows\
\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python
27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\
lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', '..\\Blocks']
Traceback (most recent call last):
File "main.py", line 60, in <module>
main()
File "main.py", line 52, in main
createBlock()
File "main.py", line 37, in createBlock
glEnd()
File "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (c:
\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\src\latebind.c:1201)
File "C:\Python27\lib\site-packages\OpenGL\GL\exceptional.py", line 46, in glE
return baseFunction( )
File "C:\Python27\lib\site-packages\OpenGL\platform\baseplatform.py", line 402
, in __call__
return self( *args, **named )
File "errorchecker.pyx", line 53, in OpenGL_accelerate.errorchecker._ErrorChec
ker.glCheckError (c:\Users\mcfletch\OpenGL-dev\OpenGL-ctypes\OpenGL_accelerate\s
rc\errorchecker.c:1218)
OpenGL.error.GLError: GLError(
err = 1282,
description = 'invalid operation',
baseOperation = glEnd,
cArguments = ()
Im running on windows 7 on a hp machine.
Block Model Module looks like this:
class Block:
# initializing the basic functions of a block
def __init__(self, blockID = "0", blockType = "stone", verticesCords = ((1,-1,-1),(1,1,-1),(-1,1,-1),(-1,-1,-1),(1,-1,1),(1,1,1),(-1,-1,1),(-1,1,1)), 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)), surfaces = (((0,1,2,3),(3,2,7,6),(6,7,5,4),(4,5,1,0),(1,5,7,2),(4,0,3,6)))):
# Block Placement
self.PLACEMENT = verticesCords
# Block identity in the world
self.EDGES = edges
self.SURFACE = surfaces
self.BLOCKID = blockID
# The block type
self.BLOCKTYPE = blockType
# A function letting the framework know its placement.
def returnVertices(self):
return self.PLACEMENT
def returnEdges(self):
return self.EDGES
def returnSurface(self):
return self.SURFACE
# A function to make the block fetch its own texture.
def defineTexture():
Thank you for any answears! :)
You may have already solved this, but my guess is that you might have an odd-number of vertices in your edges. A 1282 error on the glEnd() just means there's something wrong with the whole operation. GL_LINES expects an even number of vertices to be given, as GL_LINES works in pairs of points to define each line segment, rather than an continuous string of points to make a big polyline. Double check that each edge has two points.
–
It looks like you aren't ending the GL_QUADS process properly. You're calling glEnd, rather than glEnd(). I don't know if that's the problem but that definitely is wrong. It may be that you need to specify which process you're ending if you have multiple going, e.g. glEnd(GL_LINES) or glEnd(GL_QUADS) when you have multiple currently prepared which is why the error is happening on the successful glEnd() call; you aren't telling it which should be ended.
Hope this helps
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.