Created
November 22, 2010 15:01
-
-
Save greymouser/710077 to your computer and use it in GitHub Desktop.
SDL_Test.go bad
This file contains 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 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