Created
May 6, 2015 20:20
-
-
Save fowlmouth/f4605cc136e50b1af109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Bare-bones SDL2 example | |
import sdl2, sdl2/gfx | |
discard sdl2.init(INIT_EVERYTHING) | |
var | |
window: WindowPtr | |
render: RendererPtr | |
window = createWindow("SDL Skeleton", 100, 100, 640,480, SDL_WINDOW_SHOWN) | |
render = createRenderer(window, -1, Renderer_Accelerated or Renderer_PresentVsync or Renderer_TargetTexture) | |
var | |
pix: pointer | |
surf = loadBMP("duck.bmp") | |
formattedSurface = convertSurfaceFormat(surf, window.getPixelFormat, 0) | |
tex = createTexture(render, window.getPixelFormat, | |
SDL_TEXTUREACCESS_STREAMING, formattedSurface.w, formattedSurface.h ) | |
rect = rect(0,0, formattedSurface.w, formattedSurface.h) | |
pitch = formattedSurface.pitch | |
lockTexture(tex, rect.addr, pix.addr, pitch.addr) | |
# memcpy( mPixels, formattedSurface->pixels, formattedSurface->pitch * formattedSurface->h ); | |
copyMem(pix, formattedSurface.pixels, formattedSurface.pitch*formattedSurface.h) | |
unlockTexture(tex) | |
var | |
evt = sdl2.defaultEvent | |
runGame = true | |
fpsman: FpsManager | |
fpsman.init | |
while runGame: | |
while pollEvent(evt): | |
if evt.kind == QuitEvent: | |
runGame = false | |
break | |
let dt = fpsman.getFramerate() / 1000 | |
render.setDrawColor 0,0,0,255 | |
render.clear | |
render.copy tex, rect.addr, rect.addr | |
render.present | |
fpsman.delay | |
destroy render | |
destroy window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment