Hot answers tagged

7

Like this: import pyglet # Create and open a window window = pyglet.window.Window(200, 200) # Load sprites s0 = pyglet.resource.image('01.jpg') s1 = pyglet.resource.image('02.jpg') sprites = [s0, s1] # Animation anim = pyglet.image.Animation.from_image_sequence(sprites, 0.5, True) sprite = pyglet.sprite.Sprite(anim) @window.event def on_draw(): window....


4

For those like me, who are simply making a retro-style game where they want EVERYTHING scaled to be pixelated, the simple quick answer is start your code with: from pyglet.gl import * glEnable(GL_TEXTURE_2D) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) Then all your usage of sprites, etc. from there on out stay nice and pixelated.


4

The concept of a surface in this situation is simply describing a texture. To understand this better, you should also understand the rendering process. When rendering anything using modern graphics API's, the end result is always going to be the same, a buffer (texture) of color data that is presented to the screen. How you get to that buffer can vary quite ...


4

Just use the maximum height of the window for your calculations: When setting: py_Y_Value = max_Screen_Height - my_Y_Value or when getting: my_Y_Value = max_Screen_Height - py_Y_Value The best way to utilize these would be to abstract away their use in wrapper functions.


3

Literally a few seconds after posting this I found the solution(Thought of it while typing actually) after the loading of the image, but before assigning to the sprite, you change the anchor point for the image, which fixes the issue(if the width of your image is even, it works perfectly) updated code: pic_img = image.load(imgPath) pic_img....


2

The difference between the three frameworks/engines is the abstraction level. Pyglet is low level compared to the other two and is based on SDL, a popular C++ multimedia library. You'll have to use pure OpenGL functions and constants to achieve the desired result, but it also has many built-in features, such as batches. This has pros and cons too, it's much ...


2

From the documentation (link): pyglet.resource.texture is for loading stand-alone textures, and would be required when using the texture for a 3D model. pyglet.resource.image is optimised for loading sprite-like images that can have their texture coordinates adjusted. The resource module attempts to pack small images into larger textures (...


2

Yes, you can do this, but as the error tells you, you must use ctypes instead of Python types for it. RGB values are unsigned byte triplets, which means c_ubyte in ctypes, also available in pyglet.gl as GL_ubyte. So you can do this: pixels = [ 255, 0, 0, 0, 255, 0, 0, 0, 255, # RGB values range from 255, 0, 0, 255, 0, 0, 255,...


1

Found a solution at Scaling window contents in Pyglet? from pyglet.gl import * then add glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) to on_draw()


1

I was able to get what I was asking for by copying the sprite, then removing it and adding it back. I also made sure to not "add" another action on top on top of the copied sprite, as Cocos2d keeps the action on the copied sprite.


1

It turns out I need to declare a font type in the attributes of the document. I added: font_name="Times New Roman" to the attributes dictionary and voila. Frustrating that all the examples I found did not explicitly declare a font type, and yet for me this seems to be a requirement. I was just about to give up and roll my own text renderer.


1

Do you have spacing in between the sprites? You would need to use row_spacing and column_spacing for the ImageGrid in that case.


1

You need to add an event loop for your window. The following code is directly from a pyglet quickstart tutorial. You basically need a function that gets called periodically. After that you can then just ask pyglet to run the application. Here's a basic draw function: @window.event def on_draw(): window.clear() and then just call pyglet.app.run() to ...


1

vsync = True just means to wait with swapping buffers until the next vertical retrace, which is the point in time where a frame is completely drawn on the monitor, instead of somewhere halfway through, which can cause visible tearing during animations. Enabling vsync (on whatever platform) will simply tell OpenGL to wait for the next retrace. It will do ...


1

It is possible with Pyglet (even without PyOpenGL), I've successfully done it with the following code (slightly modified). However, my Pyglet version is a little behind. With the code you can create a valid Pyglet texture which you can use as a render target. Set the render target to None when you want to draw to the screen again. import pyglet, traceback, ...


1

I pursued the pyglet_obj_test solution further and got it working. So, to answer my own question, here's a complete example: Using Blender, create a mesh with a UV-mapped texture. The UV-mapping is important! If it is working properly, you will see the texture applied within Blender's 3d view. Export the mesh from Blender using the Wavefront format, ...


Only top voted, non community-wiki answers of a minimum length are eligible