Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement display.gl_get_proc #3285

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yunline
Copy link
Contributor

@yunline yunline commented Jan 8, 2025

Trys to fix #3284

Example:

import pygame
import ctypes

win = pygame.Window(opengl=True)

GL_VENDOR = 0x1F00
GL_RENDERER = 0x1F01
GL_VERSION = 0x1F02
GL_EXTENSIONS = 0x1F03

glGetString = pygame.display.gl_get_proc("glGetString")
glGetString.restype = ctypes.c_char_p
glGetString.argtypes = (ctypes.c_int,)
print(glGetString(GL_VENDOR))

# prints b'ATI Technologies Inc.' on my computer

WARNING
This PR introduces a new dependency: ctypes

This PR is experimental. If you have better idea, feel free to open another PR.

- SDL3 compat
- Use WINFUNCTYPE (stdcall) on win32
- Use ctypes._FuncPointer in stubs
@Starbuck5
Copy link
Member

Thoughts:

Maybe it would be simpler to import ctypes instead of a custom module into display.c, and then use PyObject_call stuff and ifdef WIN32 to do the same logic as the custom ffi.py module

Maybe we should give the pointer only, and let the user worry about ctypes, since they're going to need to worry about ctypes anyway to extract any value (as I understand it). Plus it makes it simpler code for this seemingly-niche use case.

@yunline yunline added opengl New API This pull request may need extra debate as it adds a new class or function to pygame labels Jan 9, 2025
- Import ctypes directly in display.c
- Don't use SDL_GetError when SDL_GL_GetProcAddress returns NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New API This pull request may need extra debate as it adds a new class or function to pygame opengl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose SDL_GL_GetProcAddress
2 participants