We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

8

At the request of commenters... Warning to Pyglet professionals: There may be a nice Pyglet way to do this, and this isn't it. It's a nice OpenGL way. You have been warned! You can do this in OpenGL by first binding the texture, then calling glTexParameteri or similar varients. You can do this in Pyglet by importing OpenGL: from pyglet.gl import * You ...


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

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.


4

I use my own sprite class, which has an timer variable which accumulates the dtime in the update_frames() message. By this you have an exact timestamp and can easily change the image based on certain timings.I do not have a source available but I will add this later, if needed Update: Here is a small piece of code: It loads two frames and displays flip flop ...


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.


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

Ended up figuring out the answer myself through trial and error, solution follows. You need to import openGL to get access to the scaling function: from pyglet.gl import * Next, toss in the following code after your game's window has been initialized: #These arguments are x, y and z respectively. This scales your window. glScalef(2.0, 2.0, 2.0) At this ...


2

I would recommend PyGlet, it has both GL and GLU built in, you can also use PyOpenGL(if you're ready to type a million OpenGL calls) for the best result, download it at CheeseShop: http://pypi.python.org/pypi


2

There were no normals, so nothing was displaying. I updated the git repo to warn on missing normals. Unfortunately, I have no ground-breaking debugging techniques to report. I opened up the working .obj file and the "broken" .obj file, and by comparing them I noticed that one of the files had normals, and the other one didn't.


2

I tried out billboards a while back. I just created a quad that faced the camera. Using the position I want the object at and the up and right vectors (normalized) of the camera, you can set the four corners of the quad like so: a = position - ((right + up) * scale); b = position + ((right - up) * scale); c = position + ((right + up) * scale); d = position -...


2

To support drawing tile-based map of arbitrarily large bounds, you want to take the approach of not rendering every tile all the time. You only need to attempt to draw what the player could see, any other draw attempts are a waste of processing time and resources. This is an API-agnostic approach and it doesn't matter whether you are using Pygame, cocos2d, ...


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,...


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 (...


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

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 ...


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