Created
December 3, 2013 03:21
-
-
Save tylereaves/7763368 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
| import sdl | |
| import sdl_image | |
| const SCREEN_WIDTH = 640 | |
| const SCREEN_HEIGHT = 480 | |
| const SCREEN_BPP = 32 | |
| var screen: PSurface = nil | |
| var image: PSurface = nil | |
| proc load_image(filename: string): PSurface = | |
| echo(filename) | |
| #var loadedImage = sdl_image.IMG_Load(filename) | |
| var loadedImage = sdl.LoadBMP("x.bmp") | |
| echo(loadedImage == nil) | |
| if (loadedImage != nil): | |
| let optimizedImage = SDL.DisplayFormat(loadedImage) | |
| sdl.FreeSurface(loadedImage) | |
| return optimizedImage | |
| return nil | |
| proc apply_surface(x,y: int16, source, destination: PSurface) = | |
| var offset = SDL.Rect(x: x, y: y) | |
| discard sdl.BlitSurface(source, nil, destination, addr(offset)) | |
| proc init(): bool = | |
| if sdl.Init(sdl.INIT_EVERYTHING) == -1: | |
| return false | |
| screen = sdl.SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,sdl.SWSURFACE) | |
| if (screen == nil): | |
| return false; | |
| sdl.WM_SetCaption("Event test", nil) | |
| return true | |
| proc load_files(): bool = | |
| image = load_image("x.jpg") | |
| if (image == nil): | |
| return false | |
| return true | |
| proc clean_up() = | |
| sdl.FreeSurface(image) | |
| sdl.Quit() | |
| proc main(): int = | |
| echo("In main") | |
| var event : sdl.TEvent | |
| var quit : bool = false | |
| discard init() | |
| if load_files() == false: | |
| return 1 | |
| apply_surface(0,0, image, screen) | |
| if sdl.Flip(screen) == -1: | |
| return 1 | |
| while quit == false: | |
| while sdl.PollEvent(addr(event)) == 1: | |
| if event.kind == sdl.QUITEV: | |
| quit = true | |
| clean_up() | |
| return 0 | |
| return 0 | |
| programResult = main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment