glEnd error in PyOpenGL error = 1282 - python
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! :)
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.
You should remove () from glEnd() line number 37 and code should work fine.
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
Related
Python Arcade: TypeError: "Chunk" object is not iterable
As a small project I wanna continue working on, I decided to create a simple platformer following the guide from here: https://arcade.academy/examples/platform_tutorial/index.html# Everything works up to the point where I have to add a code to draw a map (https://arcade.academy/examples/platform_tutorial/index.html#draw-a-level) My code at the point where I have to process layers is similar and/or almost identical. Some of the code for referencing: class Platformer(arcade.Window): # Class initializer def __init__(self): # Call the parent class and setup the window super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # We use lists to keep track of our sprites. Every sprite should have its own list self.coin_list = None self.wall_list = None self.player_list = None # Variable used for holding player sprite self.player_sprite = None # Main game setup (when called the game resets) def setup(self): # Create the sprite lists self.player_list = arcade.SpriteList() self.wall_list = arcade.SpriteList(use_spatial_hash = True) self.coin_list = arcade.SpriteList(use_spatial_hash = True) # Specify the player image source player_image_source = "images/Player/player.png" self.player_sprite = arcade.Sprite(player_image_source, SPRITE_SCALING) # Set the X and Y coordinates to where the player will spawn self.player_sprite.center_x = 64 self.player_sprite.center_y = 192 # Append the player sprite to the player list self.player_list.append(self.player_sprite) # ------------------Load a map from map.tmx------------------ # # Name of map file to load map_name = "Maps/map.tmx" # Get layer names platforms_layer_name = "Platforms" coins_layer_name = "Coins" # Read the map my_map = arcade.tilemap.read_tmx(map_name) # Platforms self.wall_list = arcade.tilemap.process_layer(map_object = my_map, layer_name = platforms_layer_name, scaling = SPRITE_SCALING) # Coins self.coin_list = arcade.tilemap.process_layer(map_object = my_map, layer_name = coins_layer_name, scaling = SPRITE_SCALING) # Set background color if my_map.background_color: arcade.set_background_color(my_map.background_color) # Create physics engine self.physics_engine = arcade.PhysicsEnginePlatformer(self.player_sprite, self.wall_list, GRAVITY) # ----------------------------------------------------------- # Here is the code where error is thrown: # Here is the part of the code where ERROR IS THROWN self.wall_list = arcade.tilemap.process_layer(map_object = my_map, layer_name = platforms_layer_name scaling = SPRITE_SCALING) self.coin_list = arcade.tilemap.process_layer(map_object = my_map, # it stops right here layer_name = coins_layer_name scaling = SPRITE_SCALING) And here is their code: # -- Platforms self.wall_list = arcade.tilemap.process_layer(map_object=my_map, layer_name=platforms_layer_name, scaling=TILE_SCALING, use_spatial_hash=True) # -- Coins self.coin_list = arcade.tilemap.process_layer(my_map, coins_layer_name, TILE_SCALING) TRACEBACK: Traceback (most recent call last): File "C:/Users/canus/Documents/GitHub/Platformer/Platformer/2D Platformer.py", line 221, in <module> main() File "C:/Users/canus/Documents/GitHub/Platformer/Platformer/2D Platformer.py", line 215, in main window.setup() File "C:/Users/canus/Documents/GitHub/Platformer/Platformer/2D Platformer.py", line 101, in setup scaling = SPRITE_SCALING) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\arcade\tilemap.py", line 457, in process_layer return _process_tile_layer(map_object, layer, scaling, base_directory) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\arcade\tilemap.py", line 404, in _process_tile_layer for column_index, item in enumerate(row): TypeError: 'Chunk' object is not iterable Why is this happening? Any feedback is appreciated!!
TypeError: 'module' object is not callable in pygame
I'm new in pygame and I have that error please help me. backgrounf_image_filename = 'ubisoft.jpg' mouse_image_filename = 'cursor.png' import pygame from pygame.locals import * from sys import exit pygame.init() screen = pygame.display.set_mode((640, 480), 0, 32) pygame.display.set_caption("Hello World!") background = pygame.image.load(backgrounf_image_filename).convert() mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() and I have that error: Traceback (most recent call last): File "C:/Users/ziyaa/PycharmProjects/pygame/helloworld.py", line 13, in <module> mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() TypeError: 'module' object is not callable Process finished with exit code 1
You're doing: background = pygame.image.load(backgrounf_image_filename).convert() mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() In the second instruction, you forgot to load your image, resulting in calling the module instead of the function. Just do: mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
Your problem is your for event.get loop. I use a similar one for my games, and its the right approach however you have your next few lines indented wrong x, y = pygame.mouse.get_pos() x -= mouse_cursor.get_width()/2 y -= mouse_cursor.get_height()/2 screen.blit(mouse_cursor, (x, y)) needs to be unidented or moved back
turtle.TurtleGraphicsError not registering?
I have this code running: import random import turtle turtle.speed(0) def jump(x,y): turtle.penup() turtle.goto(x,y) turtle.pendown() #end def def random_walk(n_steps): turtle.goto(0,0) for i in range(n_steps): leftright = random.randint(0,10) if leftright<5: turtle.left(random.randint(0,359)) turtle.forward(random.randint(8,12)) elif 5<leftright: turtle.right(random.randint(0,359)) turtle.forward(random.randint(8,12)) #end for #end def step = int(input("How far would you like your turtle to move?")) while True: try: color = input("And what color would you like your turtle to be?") break except turtle.TurtleGraphicsError: print('Oops! i dont recognize taht color, try another!') turtle.pencolor(color) random_walk(step) my plan was to have the code stop an error from occurring when an invalid color string was implemented however the shell still returns this error: And what color would you like your turtle to be?redf Traceback (most recent call last): File "/Users/sgomena/Desktop/122/project 5/project5d.py", line 35, in <module> turtle.pencolor(color) File "<string>", line 1, in pencolor File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 2252, in pencolor color = self._colorstr(args) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 2696, in _colorstr return self.screen._colorstr(args) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 1158, in _colorstr raise TurtleGraphicsError("bad color string: %s" % str(color)) turtle.TurtleGraphicsError: bad color string: redf >>> I have looked into it and it seems as though I should be getting a different error if the code was running properly. Thanks in advance for any help!
It´s very simple! You need to insert the line where you set the pen color of your turtle (turtle.pencolor(color)) in your try/except block. Otherwise, the exception turtle.TurtleGraphicsError occurs when you pass a invalid color to the turtle.pencolor() method, but there is no try/except block which handles this. step = int(turtle.numinput("Choose a distanc", "How far would you like your turtle to move?", minval=0, maxval=10)) while True: try: print(turtle.pencolor()) color = turtle.textinput("Choose a color", "What color would you like your turtle to be?") turtle.pencolor(color) # Must be inside the try/except block break except turtle.TurtleGraphicsError: print('Oops! i dont recognize taht color, try another!') I also recommend to use turtles input methods (textinput() and numinput()) to pop up a dialog window for the input of a string or a floating-point number (see the code above). For more information visit the documentation site.
PySDL2 issue with SDL_Surface / LP_SDL_Surface
Im running win7 with python 3.3 and PySDL2 0.5. When creating surfaces (no matter what method) i get an LP_SDL_Surface instead of a SDL_Surface. The LP_SDL_Surface lacks any of the methods and attribute you would expect it to have. Here is the issue using example code from the documentation: import os os.environ["PYSDL2_DLL_PATH"] = os.path.dirname(os.path.abspath(__file__)) import sys import ctypes from sdl2 import * def main(): SDL_Init(SDL_INIT_VIDEO) window = SDL_CreateWindow(b"Hello World", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 592, 460, SDL_WINDOW_SHOWN) windowsurface = SDL_GetWindowSurface(window) image = SDL_LoadBMP(b"exampleimage.bmp") SDL_BlitSurface(image, None, windowsurface, None) print(image.h) SDL_UpdateWindowSurface(window) SDL_FreeSurface(image) running = True event = SDL_Event() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break SDL_DestroyWindow(window) SDL_Quit() return 0 if __name__ == "__main__": sys.exit(main()) and the traceback is: Traceback (most recent call last): File "C:/.../test.py", line 35, in <module> sys.exit(main()) File "C:/.../test.py", line 17, in main print(image.h) AttributeError: 'LP_SDL_Surface' object has no attribute 'h' A google search for "LP_SDL_Surface" brings 0 (!) results.
If you work with the lower level SDL methods (e.g. sdl2.SDL_LoadBMP) you will have to deal with ctypes conversions, referencing(byref) and dereferencing of pointers (.contents, .value). So for the specific question, as you've already commented, using print(image.contents.h) would be enough. There are some higher level classes and methods provided by pysdl2 (sdl2.ext), however, that could do most of those conversions for you, if desired. The code below achieves the same goal without having to touch ctypes: import os os.environ["PYSDL2_DLL_PATH"] = os.path.dirname(os.path.abspath(__file__)) import sys import sdl2 import sdl2.ext def main(): sdl2.ext.init() window = sdl2.ext.Window( title="Hello World!", size=(592, 460), flags=sdl2.SDL_WINDOW_SHOWN, position=(sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED)) window.show() renderer = sdl2.ext.Renderer(window) factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer) spriterenderer = factory.create_sprite_render_system(window) image = factory.from_image("exampleimage.bmp") print(image.size[1]) # image.size = (w, h) running = True while running: for event in sdl2.ext.get_events(): if event.type == sdl2.SDL_QUIT: running = False break spriterenderer.render(image) sdl2.ext.quit() return 0 if __name__ == '__main__': sys.exit(main()) It also makes use of texture rendering, using hardware acceleration, instead of surface blitting (software based). Finally, using the higher level sdl2.ext you could also instantiate classes (instead of having to write a whole new sprite class yourself) like sdl2.ext.sprite.TextureSprite, and implement a h property: class TextureSprite(sdl2.ext.TextureSprite): #property def h(self): """The height of the TextureSprite.""" return self.size[1] #property def w(self): """The width of the TextureSprite.""" return self.size[0]
Interactive input in Python for a nethack/pong game hybrid
Basically I am trying to build a game of pong that plays in the shell. So far the thing stopping me is the user input. The code has to respond to key presses without having to press Return afterwards. I have tried using msvcrt but it does not yield the result I need. Is it possible to be done without having to code and event listener? Here is the code: import os import msvcrt #fixed parameters here resolution_x=16 resolution_y=8 line_position = 4 char_position = 4 def line_draw(char_position, line_length): #draws a line with # in it marking the ball line = "" if char_position == 0: for i in range(line_length): line+="_" print(line) if char_position: for i in range(char_position-1): line+="_" line+="#" for j in range(line_length-char_position): line+="_" print(line) def scr_draw(num_lines, line_position, char_position, line_length): # draws the court with the ball # line by line with line_draw() for i in range(line_position): line_draw(0,line_length) line_draw(char_position, line_length) for i in range(num_lines-line_position): line_draw(0, line_length) def draw_paddle(line_length, paddle_position): # this is the paddle positioning padline="" for i in range(paddle_position-3): paddline+="-" paddline+="===" for i in range(line_length-paddle_position): paddline+="-" print(paddline) while 1: #this loop draws everything, then erases it #so it can draw it again with updates scr_draw(resolution_y, line_position, char_position, resolution_x) # draw os.system("CLS") # clears the screen in a really stupid way , to be changed