2
\$\begingroup\$

I'm trying to scale a window's contents so that every pixel displays at a multiple of it's normal size. Basically I want to achieve larger pixels without scaling each and every individual sprite. This question is very similar to this one, however that only scales a single sprite. How should I go about this?

\$\endgroup\$
2
\$\begingroup\$

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 point your resolution will double, but your window will stay the same size. You can correct this easily by doubling your window's width and height. Furthermore, your textures will appear blurry, so we need to fix that. We need to set parameters for the textures in your on_draw() function:

def on_draw(self):
        self.clear() #clears the screen
        #The following two lines will change how textures are scaled.
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        self.label.draw() #blits the label to the screen

You should now have pixels displaying at double their original size.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.