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