-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package korlibs.sdl | ||
|
||
import korlibs.annotations.* | ||
import korlibs.ffi.* | ||
|
||
val SDLPath by lazy { | ||
//"https://github.com/libsdl-org/SDL/releases/download/release-2.30.5/SDL2-2.30.5-win32-x64.zip" | ||
//"SDL" | ||
"C:\\temp\\SDL2.dll" | ||
} | ||
|
||
@KeepNames | ||
open class SDL : FFILib(SDLPath) { | ||
companion object { | ||
const val SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000 | ||
const val SDL_WINDOWPOS_CENTERED = 0x2FFF0000 | ||
} | ||
|
||
val SDL_Init: (flags: Int) -> Int by func() | ||
val SDL_CreateWindow: (title: String, x: Int, y: Int, w: Int, h: Int, flags: Int) -> FFIPointer by func() | ||
val SDL_ShowWindow: (window: FFIPointer) -> Unit by func() | ||
val SDL_RaiseWindow: (window: FFIPointer) -> Unit by func() | ||
val SDL_PollEvent: (event: FFIPointer) -> Boolean by func() | ||
val SDL_Quit: () -> Unit by func() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package korlibs.sdl | ||
|
||
import korlibs.concurrent.thread.* | ||
import korlibs.ffi.* | ||
import korlibs.io.async.* | ||
import korlibs.time.* | ||
import kotlinx.coroutines.* | ||
import kotlin.test.* | ||
|
||
class SDLTest { | ||
@Ignore | ||
@Test | ||
fun test() = suspendTest { | ||
val sdl = SDL() | ||
try { | ||
sdl.SDL_Init(0) | ||
val window = sdl.SDL_CreateWindow("hello world", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, 300, 300, 2) | ||
sdl.SDL_ShowWindow(window) | ||
sdl.SDL_RaiseWindow(window) | ||
|
||
val event = CreateFFIMemory(1024) | ||
for (n in 0 until 1000) { | ||
event.usePointer { | ||
while (sdl.SDL_PollEvent(it)) { | ||
println(it.getS32(0)) | ||
} | ||
//NativeThread.sleep(1.milliseconds) | ||
delay(1.milliseconds) | ||
} | ||
} | ||
sdl.SDL_Quit() | ||
} finally { | ||
//sdl.close() // @TODO: enable after korlibs -alpha8 | ||
} | ||
} | ||
} |