Skip to main content

Pygame Shaders

wakatime Lines of code

Downloads PyPI PyPI - Format Downloads

Easily integrate shaders into your new or existing pygame projects

This project allows for GLSL shaders to easily be intergrated with either your new or existing Pygame projects without having to touch OpenGL.

import pygame
import pygame_shaders

pygame.init()

clock = pygame.time.Clock()

#Create an opengl pygame Surface, this will act as our opengl context.  
screen = pygame.display.set_mode((600, 600), pygame.OPENGL | pygame.DOUBLEBUF)

#This is our main display we will do all of our standard pygame rendering on.
display = pygame.Surface((600, 600))

#The shader we are using to communicate with the opengl context (standard pygame drawing functionality does not work on opengl displays)
screen_shader = pygame_shaders.DefaultScreenShader(display) # <- Here we supply our default display, it's this display which will be displayed onto the opengl context via the screen_shader

#This is our shader object which we can use to render the given shaders onto the screen in various ways. 
shader = pygame_shaders.Shader(pygame_shaders.DEFAULT_VERTEX_SHADER, "fragment.glsl", screen) #<- Because we plan on using this shader for direct rendering (we supply the surface on which we plan to do said direct rendering in this case, screen) 

while True:
    #Fill the display with white
    display.fill((255, 255, 255))
    
    #Standard pygame event stuff
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()

    #Render a rect onto the display using the standard pygame method for drawing rects.
    pygame.draw.rect(display, (255, 0, 0), (200, 200, 20, 20))
    
    #Render the contents of "display" (main surface) onto the opengl screen.
    screen_shader.render() 

    #Render the shader directly onto the display.
    shader.render_direct(pygame.Rect(0, 0, 100, 100)) 

    #Update the opengl context
    pygame.display.flip()
    clock.tick(60)

Release files for pygame-shaders 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygame-shaders 2.0.2
File Size Uploaded
pygame_shaders-2.0.2.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygame-shaders 2.0.2
File Interpreter ABI Platform
pygame_shaders-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / pygame_shaders-2.0.2.tar.gz

Download URL pygame_shaders-2.0.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d18235dc4e2112db9b9b7afd340b9e633829404eb0a18c0df09ff0b6f3d32c90
BLAKE2b-256 checksum
How to use checksums
54df3260e26c531219df06bc229ce0fe6172a64b810fc9b60157f62283b98218
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / pygame_shaders-2.0.2-py3-none-any.whl

Download URL pygame_shaders-2.0.2-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
828e1441512febce7c78cd82fc574dff2cc9803ac47c6aa0d28c298790b88004
BLAKE2b-256 checksum
How to use checksums
eb14d4d1cc1a42140313e0b8785874bd663b26f73401160820fd57b539649a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page