pygame / pygame

🐍🎮 pygame (the library) is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.
https://www.pygame.org
7.45k stars 3.32k forks source link

Add code to gl_cube example showing how to create a 3.2 or 4.1 Core Profile context #85

Closed illume closed 4 years ago

illume commented 13 years ago

Originally reported by: René Dudfield (Bitbucket: illume, GitHub: illume)


Need to investigate how to create a 3.2 or 4.1 Core Profile context in pygame's set_display_mode.

Asked on the SDL mailing list if it is possible with SDL 1.2.

Need to report back findings on PyOpenGL mailing list.


MyreMylar commented 4 years ago

Is this issue to support more modern OpenGL versions on pygame 1 or just to support setting the Open GL version in pygame more generally?

From what I can tell SDL 2 supports this fairly straightforwardly, but no support for it has ever been added to SDL 1.2.

Setting OpenGL version in SDL2:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

Is the library going to let users set this when using OpenGL, in the normal way that you can set SDL variables, or is it going to do it for them as this issue implies. If it's doing it for them, don't we still need some way for them to select a version anyway (e.g. 2.1, 3.2 or 4.1).

illume commented 4 years ago

There's a pygame.display.gl_set_attribute now (and a get). See it documented here: docs/reST/ref/display.rst

It's not used in examples/ though.

robertpfeiffer commented 4 years ago

So what's needed for this is an example? It looks like @einarf is already using the feature in production.

einarf commented 4 years ago

Yup. Works like a charm cross platform (win/osx/linux) : https://github.com/moderngl/moderngl-window/blob/de6b5c0134ef078984418c0e87f8ff04e21eb2ce/moderngl_window/context/pygame2/window.py#L30-L35

MyreMylar commented 4 years ago

So what's needed for this is an example? It looks like @einarf is already using the feature in production.

Add something like this to the start of examples/glcube.py

def main():
    "run the demo"
    # initialize pygame and setup an opengl display
    pg.init()

    gl_version = (3, 2)  # GL Version number (Major, Minor)
    pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, gl_version[0])
    pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, gl_version[1])
    pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK,
                                pg.GL_CONTEXT_PROFILE_CORE)

    fullscreen = True
    pg.display.set_mode((640, 480), pg.OPENGL | pg.DOUBLEBUF | pg.FULLSCREEN)

    init_gl_stuff()

   ...

?

MyreMylar commented 4 years ago

This is now merged and will be available in 2.0.0.dev10.