Skip to content

Instantly share code, notes, and snippets.

@greymouser
Created November 22, 2010 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymouser/710077 to your computer and use it in GitHub Desktop.
Save greymouser/710077 to your computer and use it in GitHub Desktop.
SDL_Test.go bad
package testC
// #include <SDL/SDL.h>
import "C"
const (
WIDTH = 640
HEIGHT = 480
BPP = 4
DEPTH = 32
)
func setpixel(screen *C.SDL_Surface, x, y int, r, g, b uint8) {
var color uint32;
color = C.SDL_MapRGB(screen.format, r, g, b);
(screen.pixels)[y + x] = color
}
func DrawScreen(screen *C.SDL_Surface, h int) {
var x, y, ytimesw int
if C.SDL_MUSTLOCK(screen) {
if C.SDL_LockSurface(screen) < 0 {
return
}
}
for y = 0; y < screen.h; y++ {
ytimesw = y*screen.pitch/BPP
for x = 0; x < screen.w; x++ {
setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h)
}
}
if C.SDL_MUSTLOCK(screen) {
SDL_UnlockSurface(screen)
}
C.SDL_Flip(screen);
}
func main() int {
var screen *C.SDL_Surface
var event *C.SDL_Event;
var keypress, h int = 0, 0
if C.SDL_Init(C.SDL_INIT_VIDEO) < 0 {
return 1;
}
if screen = C.SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, C.SDL_FULLSCREEN|C.SDL_HWSURFACE); screen != nil {
C.SDL_Quit();
return 1;
}
for {
if(1 == kepress) { break }
h++
DrawScreen(screen,h)
for C.SDL_PollEvent(&event); true
{
switch {
case event.type == C.SDL_QUIT:
keypress = 1;
break;
case event.type == C.SDL_KEYDOWN:
keypress = 1;
break;
}
}
}
C.SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment