Created
April 8, 2014 19:32
-
-
Save leth/10177156 to your computer and use it in GitHub Desktop.
Example Mac OSX SDL app (avoids NSInternalInconsistencyException)
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
package main | |
/* | |
#import <dlfcn.h> | |
int | |
PreInit() { | |
void* cocoa_lib; | |
cocoa_lib = dlopen( "/System/Library/Frameworks/Cocoa.framework/Cocoa", RTLD_LAZY ); | |
void (*nsappload)(void); | |
nsappload = (void(*)()) dlsym( cocoa_lib, "NSApplicationLoad"); | |
nsappload(); | |
return 0; | |
} | |
*/ | |
import "C" | |
import "github.com/banthar/Go-SDL/sdl" | |
import "os" | |
func loadImage(name string) *sdl.Surface { | |
image := sdl.Load(name) | |
if image == nil { | |
panic(sdl.GetError()) | |
} | |
return image | |
} | |
func main() { | |
C.PreInit() | |
if sdl.Init(sdl.INIT_EVERYTHING) != 0 { | |
panic(sdl.GetError()) | |
} | |
defer sdl.Quit() | |
var screen = sdl.SetVideoMode(640, 480, 32, 0) | |
if screen == nil { | |
panic(sdl.GetError()) | |
} | |
image := loadImage(os.Args[1]) | |
sdl.WM_SetCaption("Template", "") | |
for true { | |
for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() { | |
switch ev.(type) { | |
case *sdl.QuitEvent: | |
return | |
default: | |
} | |
screen.FillRect(nil, 0x000000) | |
screen.Blit(&sdl.Rect{0,0, 0, 0}, image, nil) | |
screen.Flip() | |
sdl.Delay(25) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment