0

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

try:
    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
nd
    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():
        pass

Thank you for any answears! :)

Håvard Nygård
  • 386
  • 3
  • 14

3 Answers3

1

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.

user1961169
  • 783
  • 6
  • 17
0

You should remove () from glEnd() line number 37 and code should work fine.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Shivam
  • 15
  • Hi, new contributor!! :D In general, answers have same behaviour as questions. So person who finds your answer ok, must not skip back and forth to implement your changes. Therefore answers should have copy of the code from original question with changed bad behaviour. With some commenting. Please edit the post. – Danilo Sep 04 '19 at 14:05
-1

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