sdl2 yay
This commit is contained in:
parent
b7a21689f6
commit
bbd12beab2
1 changed files with 37 additions and 24 deletions
63
main.odin
63
main.odin
|
@ -1,41 +1,54 @@
|
|||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import gl "vendor:OpenGL"
|
||||
import "vendor:glfw"
|
||||
import "vendor:sdl2"
|
||||
|
||||
WIDTH :: 1600
|
||||
HEIGHT :: 900
|
||||
|
||||
// @note You might need to lower this to 3.3 depending on how old your graphics card is.
|
||||
GL_MAJOR_VERSION :: 4
|
||||
GL_MINOR_VERSION :: 5
|
||||
Game :: struct {
|
||||
render: ^sdl2.Renderer,
|
||||
time: f64,
|
||||
dt: f64,
|
||||
}
|
||||
|
||||
get_time :: proc() -> f64 {
|
||||
return f64(sdl2.GetPerformanceCounter()) * 1000 / f64(sdl2.GetPerformanceFrequency())
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
if !bool(glfw.Init()) {
|
||||
fmt.eprintln("GLFW failed to load!")
|
||||
assert(sdl2.Init(sdl2.INIT_VIDEO) == 0, sdl2.GetErrorString())
|
||||
defer sdl2.Quit()
|
||||
|
||||
window := sdl2.CreateWindow("Game", 0, 0, 1600, 900, sdl2.WINDOW_SHOWN)
|
||||
assert(window != nil, sdl2.GetErrorString())
|
||||
defer sdl2.DestroyWindow(window)
|
||||
|
||||
render := sdl2.CreateRenderer(window, -1, sdl2.RENDERER_ACCELERATED)
|
||||
assert(render != nil, sdl2.GetErrorString())
|
||||
|
||||
tickrate := 240.0
|
||||
ticktime := 1000.0 / tickrate
|
||||
|
||||
game := Game {
|
||||
render = render,
|
||||
time = get_time(),
|
||||
dt = ticktime,
|
||||
}
|
||||
|
||||
for {
|
||||
event: sdl2.Event
|
||||
for sdl2.PollEvent(&event) {
|
||||
#partial switch event.type {
|
||||
case .QUIT:
|
||||
return
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window := glfw.CreateWindow(WIDTH, HEIGHT, "hello", nil, nil)
|
||||
|
||||
defer glfw.Terminate()
|
||||
defer glfw.DestroyWindow(window)
|
||||
|
||||
if window == nil {
|
||||
fmt.eprintln("GLFW has failed to load the window.")
|
||||
return
|
||||
}
|
||||
|
||||
glfw.MakeContextCurrent(window)
|
||||
gl.load_up_to(GL_MAJOR_VERSION, GL_MINOR_VERSION, glfw.gl_set_proc_address)
|
||||
for !glfw.WindowShouldClose(window) {
|
||||
glfw.PollEvents()
|
||||
gl.ClearColor(1.0, 1.0, 1.0, 1.0)
|
||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||
|
||||
glfw.SwapBuffers(window)
|
||||
sdl2.SetRenderDrawColor(render, 0, 0, 0, 0)
|
||||
sdl2.RenderClear(render)
|
||||
sdl2.RenderPresent(render)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue