Source

pysdl-cffi / testing / test_window.py

Full commit
#!/usr/bin/env pypy
from __future__ import (print_function, division, absolute_import, 
    unicode_literals)

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__),'..'))
import traceback

from sdl import *

################################################################################

def main(argv):
    try:
        assert SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) >= 0, 'Unable to initialize SDL'
    
        #SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)
        #SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2)
        
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
        
        mainwindow = SDL_CreateWindow("SDL Test Window", SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN)
        assert mainwindow, "Unable to create main window"
        
        maincontext = SDL_GL_CreateContext(mainwindow)
        SDL_GL_SetSwapInterval(1)
        
        SDL_GL_SwapWindow(mainwindow)
        import time
        time.sleep(5)
        
        SDL_GL_DeleteContext(maincontext)
        SDL_DestroyWindow(mainwindow)
        
    except:
        traceback.print_exc()
    SDL_Quit()
    
if __name__ == '__main__':
    main(sys.argv)