karl2d.odin 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. package karl2d
  2. import "base:runtime"
  3. import "core:mem"
  4. import "core:log"
  5. import "core:math"
  6. import "core:math/linalg"
  7. import "core:slice"
  8. import "core:image"
  9. import "core:image/bmp"
  10. import "core:image/png"
  11. import "core:image/tga"
  12. import hm "handle_map"
  13. _ :: bmp
  14. _ :: png
  15. _ :: tga
  16. Handle :: hm.Handle
  17. Texture_Handle :: distinct Handle
  18. // Opens a window and initializes some internal state. The internal state will use `allocator` for
  19. // all dynamically allocated memory. The return value can be ignored unless you need to later call
  20. // `set_state`.
  21. init :: proc(window_width: int, window_height: int, window_title: string,
  22. allocator := context.allocator, loc := #caller_location) -> ^State {
  23. s = new(State, allocator, loc)
  24. s.allocator = allocator
  25. s.custom_context = context
  26. s.width = window_width
  27. s.height = window_height
  28. s.wi = WINDOW_INTERFACE_WIN32
  29. wi = s.wi
  30. window_state_alloc_error: runtime.Allocator_Error
  31. s.window_state, window_state_alloc_error = mem.alloc(wi.state_size())
  32. log.assertf(window_state_alloc_error == nil, "Failed allocating memory for window state: %v", window_state_alloc_error)
  33. wi.init(s.window_state, window_width, window_height, window_title, allocator)
  34. s.window = wi.window_handle()
  35. s.rb = BACKEND_D3D11
  36. rb_alloc_error: runtime.Allocator_Error
  37. s.rb_state, rb_alloc_error = mem.alloc(s.rb.state_size())
  38. log.assertf(rb_alloc_error == nil, "Failed allocating memory for rendering backend: %v", rb_alloc_error)
  39. s.proj_matrix = make_default_projection(window_width, window_height)
  40. s.view_matrix = 1
  41. s.rb.init(s.rb_state, s.window, window_width, window_height, allocator)
  42. s.vertex_buffer_cpu = make([]u8, VERTEX_BUFFER_MAX, allocator, loc)
  43. white_rect: [16*16*4]u8
  44. slice.fill(white_rect[:], 255)
  45. s.shape_drawing_texture = s.rb.load_texture(white_rect[:], 16, 16)
  46. s.default_shader = s.rb.load_shader(string(DEFAULT_SHADER_SOURCE), {
  47. .RG32_Float,
  48. .RG32_Float,
  49. .RGBA8_Norm,
  50. })
  51. return s
  52. }
  53. DEFAULT_SHADER_SOURCE :: #load("shader.hlsl")
  54. // Closes the window and cleans up the internal state.
  55. shutdown :: proc() {
  56. s.rb.destroy_texture(s.shape_drawing_texture)
  57. destroy_shader(s.default_shader)
  58. s.rb.shutdown()
  59. delete(s.vertex_buffer_cpu, s.allocator)
  60. wi.shutdown()
  61. a := s.allocator
  62. free(s.window_state, a)
  63. free(s.rb_state, a)
  64. free(s, a)
  65. s = nil
  66. }
  67. // Clear the backbuffer with supplied color.
  68. clear :: proc(color: Color) {
  69. s.rb.clear(color)
  70. }
  71. // Present the backbuffer. Call at end of frame to make everything you've drawn appear on the screen.
  72. present :: proc() {
  73. draw_current_batch()
  74. s.rb.present()
  75. }
  76. // Call at start or end of frame to process all events that have arrived to the window.
  77. //
  78. // WARNING: Not calling this will make your program impossible to interact with.
  79. process_events :: proc() {
  80. s.keys_went_up = {}
  81. s.keys_went_down = {}
  82. wi.process_events()
  83. events := wi.get_events()
  84. for &event in events {
  85. switch &e in event {
  86. case Window_Event_Close_Wanted:
  87. s.shutdown_wanted = true
  88. case Window_Event_Key_Went_Down:
  89. s.keys_went_down[e.key] = true
  90. s.keys_is_held[e.key] = true
  91. case Window_Event_Key_Went_Up:
  92. s.keys_is_held[e.key] = false
  93. s.keys_went_up[e.key] = true
  94. }
  95. }
  96. wi.clear_events()
  97. }
  98. /* Flushes the current batch. This sends off everything to the GPU that has been queued in the
  99. current batch. Normally, you do not need to do this manually. It is done automatically when these
  100. procedures run:
  101. present
  102. set_camera
  103. set_shader
  104. TODO: complete this list and motivate why it needs to happen on those procs (or do that in the
  105. docs for those procs).
  106. */
  107. draw_current_batch :: proc() {
  108. shader := s.batch_shader.? or_else s.default_shader
  109. s.rb.draw(shader, s.batch_texture, s.proj_matrix * s.view_matrix, s.vertex_buffer_cpu[:s.vertex_buffer_cpu_used])
  110. s.vertex_buffer_cpu_used = 0
  111. }
  112. // Can be used to restore the internal state using the pointer returned by `init`. Useful after
  113. // reloading the library (for example, when doing code hot reload).
  114. set_internal_state :: proc(state: ^State) {
  115. s = state
  116. s.rb.set_internal_state(s.rb_state)
  117. }
  118. get_screen_width :: proc() -> int {
  119. return s.rb.get_swapchain_width()
  120. }
  121. get_screen_height :: proc() -> int {
  122. return s.rb.get_swapchain_height()
  123. }
  124. key_went_down :: proc(key: Keyboard_Key) -> bool {
  125. return s.keys_went_down[key]
  126. }
  127. key_went_up :: proc(key: Keyboard_Key) -> bool {
  128. return s.keys_went_up[key]
  129. }
  130. key_is_held :: proc(key: Keyboard_Key) -> bool {
  131. return s.keys_is_held[key]
  132. }
  133. shutdown_wanted :: proc() -> bool {
  134. return s.shutdown_wanted
  135. }
  136. set_window_position :: proc(x: int, y: int) {
  137. wi.set_position(x, y)
  138. }
  139. set_window_size :: proc(width: int, height: int) {
  140. panic("Not implemented")
  141. }
  142. set_camera :: proc(camera: Maybe(Camera)) {
  143. if camera == s.batch_camera {
  144. return
  145. }
  146. draw_current_batch()
  147. s.batch_camera = camera
  148. s.proj_matrix = make_default_projection(s.width, s.height)
  149. if c, c_ok := camera.?; c_ok {
  150. origin_trans := linalg.matrix4_translate(vec3_from_vec2(-c.origin))
  151. translate := linalg.matrix4_translate(vec3_from_vec2(c.target))
  152. rot := linalg.matrix4_rotate_f32(c.rotation * math.RAD_PER_DEG, {0, 0, 1})
  153. camera_matrix := translate * rot * origin_trans
  154. s.view_matrix = linalg.inverse(camera_matrix)
  155. s.proj_matrix[0, 0] *= c.zoom
  156. s.proj_matrix[1, 1] *= c.zoom
  157. } else {
  158. s.view_matrix = 1
  159. }
  160. }
  161. load_texture_from_file :: proc(filename: string) -> Texture {
  162. img, img_err := image.load_from_file(filename, options = {.alpha_add_if_missing}, allocator = context.temp_allocator)
  163. if img_err != nil {
  164. log.errorf("Error loading texture %v: %v", filename, img_err)
  165. return {}
  166. }
  167. backend_tex := s.rb.load_texture(img.pixels.buf[:], img.width, img.height)
  168. return {
  169. handle = backend_tex,
  170. width = img.width,
  171. height = img.height,
  172. }
  173. }
  174. destroy_texture :: proc(tex: Texture) {
  175. s.rb.destroy_texture(tex.handle)
  176. }
  177. draw_rect :: proc(r: Rect, c: Color) {
  178. if s.batch_texture != TEXTURE_NONE && s.batch_texture != s.shape_drawing_texture {
  179. draw_current_batch()
  180. }
  181. s.batch_texture = s.shape_drawing_texture
  182. _batch_vertex({r.x, r.y}, {0, 0}, c)
  183. _batch_vertex({r.x + r.w, r.y}, {1, 0}, c)
  184. _batch_vertex({r.x + r.w, r.y + r.h}, {1, 1}, c)
  185. _batch_vertex({r.x, r.y}, {0, 0}, c)
  186. _batch_vertex({r.x + r.w, r.y + r.h}, {1, 1}, c)
  187. _batch_vertex({r.x, r.y + r.h}, {0, 1}, c)
  188. }
  189. draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color) {
  190. if s.batch_texture != TEXTURE_NONE && s.batch_texture != s.shape_drawing_texture {
  191. draw_current_batch()
  192. }
  193. r := r
  194. r.x -= origin.x
  195. r.y -= origin.y
  196. s.batch_texture = s.shape_drawing_texture
  197. tl, tr, bl, br: Vec2
  198. // Rotation adapted from Raylib's "DrawTexturePro"
  199. if rot == 0 {
  200. x := r.x - origin.x
  201. y := r.y - origin.y
  202. tl = { x, y }
  203. tr = { x + r.w, y }
  204. bl = { x, y + r.h }
  205. br = { x + r.w, y + r.h }
  206. } else {
  207. sin_rot := math.sin(rot * math.RAD_PER_DEG)
  208. cos_rot := math.cos(rot * math.RAD_PER_DEG)
  209. x := r.x
  210. y := r.y
  211. dx := -origin.x
  212. dy := -origin.y
  213. tl = {
  214. x + dx * cos_rot - dy * sin_rot,
  215. y + dx * sin_rot + dy * cos_rot,
  216. }
  217. tr = {
  218. x + (dx + r.w) * cos_rot - dy * sin_rot,
  219. y + (dx + r.w) * sin_rot + dy * cos_rot,
  220. }
  221. bl = {
  222. x + dx * cos_rot - (dy + r.h) * sin_rot,
  223. y + dx * sin_rot + (dy + r.h) * cos_rot,
  224. }
  225. br = {
  226. x + (dx + r.w) * cos_rot - (dy + r.h) * sin_rot,
  227. y + (dx + r.w) * sin_rot + (dy + r.h) * cos_rot,
  228. }
  229. }
  230. _batch_vertex(tl, {0, 0}, c)
  231. _batch_vertex(tr, {1, 0}, c)
  232. _batch_vertex(br, {1, 1}, c)
  233. _batch_vertex(tl, {0, 0}, c)
  234. _batch_vertex(br, {1, 1}, c)
  235. _batch_vertex(bl, {0, 1}, c)
  236. }
  237. draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color) {
  238. t := thickness
  239. // Based on DrawRectangleLinesEx from Raylib
  240. top := Rect {
  241. r.x,
  242. r.y,
  243. r.w,
  244. t,
  245. }
  246. bottom := Rect {
  247. r.x,
  248. r.y + r.h - t,
  249. r.w,
  250. t,
  251. }
  252. left := Rect {
  253. r.x,
  254. r.y + t,
  255. t,
  256. r.h - t * 2,
  257. }
  258. right := Rect {
  259. r.x + r.w - t,
  260. r.y + t,
  261. t,
  262. r.h - t * 2,
  263. }
  264. draw_rect(top, color)
  265. draw_rect(bottom, color)
  266. draw_rect(left, color)
  267. draw_rect(right, color)
  268. }
  269. draw_circle :: proc(center: Vec2, radius: f32, color: Color) {
  270. panic("not implemented")
  271. }
  272. draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color) {
  273. p := Vec2{start.x, start.y + thickness*0.5}
  274. s := Vec2{linalg.length(end - start), thickness}
  275. origin := Vec2 {0, thickness*0.5}
  276. r := Rect {p.x, p.y, s.x, s.y}
  277. rot := math.atan2(end.y - start.y, end.x - start.x)
  278. draw_rect_ex(r, origin, rot * math.DEG_PER_RAD, color)
  279. }
  280. draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE) {
  281. draw_texture_ex(
  282. tex,
  283. {0, 0, f32(tex.width), f32(tex.height)},
  284. {pos.x, pos.y, f32(tex.width), f32(tex.height)},
  285. {},
  286. 0,
  287. tint,
  288. )
  289. }
  290. draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE) {
  291. draw_texture_ex(
  292. tex,
  293. rect,
  294. {pos.x, pos.y, rect.w, rect.h},
  295. {},
  296. 0,
  297. tint,
  298. )
  299. }
  300. draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE) {
  301. if tex.width == 0 || tex.height == 0 {
  302. return
  303. }
  304. if s.batch_texture != TEXTURE_NONE && s.batch_texture != tex.handle {
  305. draw_current_batch()
  306. }
  307. r := dst
  308. r.x -= origin.x
  309. r.y -= origin.y
  310. s.batch_texture = tex.handle
  311. tl, tr, bl, br: Vec2
  312. // Rotation adapted from Raylib's "DrawTexturePro"
  313. if rotation == 0 {
  314. x := dst.x - origin.x
  315. y := dst.y - origin.y
  316. tl = { x, y }
  317. tr = { x + dst.w, y }
  318. bl = { x, y + dst.h }
  319. br = { x + dst.w, y + dst.h }
  320. } else {
  321. sin_rot := math.sin(rotation * math.RAD_PER_DEG)
  322. cos_rot := math.cos(rotation * math.RAD_PER_DEG)
  323. x := dst.x
  324. y := dst.y
  325. dx := -origin.x
  326. dy := -origin.y
  327. tl = {
  328. x + dx * cos_rot - dy * sin_rot,
  329. y + dx * sin_rot + dy * cos_rot,
  330. }
  331. tr = {
  332. x + (dx + dst.w) * cos_rot - dy * sin_rot,
  333. y + (dx + dst.w) * sin_rot + dy * cos_rot,
  334. }
  335. bl = {
  336. x + dx * cos_rot - (dy + dst.h) * sin_rot,
  337. y + dx * sin_rot + (dy + dst.h) * cos_rot,
  338. }
  339. br = {
  340. x + (dx + dst.w) * cos_rot - (dy + dst.h) * sin_rot,
  341. y + (dx + dst.w) * sin_rot + (dy + dst.h) * cos_rot,
  342. }
  343. }
  344. ts := Vec2{f32(tex.width), f32(tex.height)}
  345. up := Vec2{src.x, src.y} / ts
  346. us := Vec2{src.w, src.h} / ts
  347. c := tint
  348. _batch_vertex(tl, up, c)
  349. _batch_vertex(tr, up + {us.x, 0}, c)
  350. _batch_vertex(br, up + us, c)
  351. _batch_vertex(tl, up, c)
  352. _batch_vertex(br, up + us, c)
  353. _batch_vertex(bl, up + {0, us.y}, c)
  354. }
  355. load_shader :: proc(shader_source: string, layout_formats: []Shader_Input_Format = {}) -> Shader {
  356. return s.rb.load_shader(shader_source, layout_formats)
  357. }
  358. destroy_shader :: proc(shader: Shader) {
  359. s.rb.destroy_shader(shader)
  360. }
  361. set_shader :: proc(shader: Maybe(Shader)) {
  362. if maybe_handle_equal(shader, s.batch_shader) {
  363. return
  364. }
  365. draw_current_batch()
  366. s.batch_shader = shader
  367. }
  368. maybe_handle_equal :: proc(m1: Maybe($T), m2: Maybe(T)) -> bool {
  369. if m1 == nil && m2 == nil {
  370. return true
  371. }
  372. m1v, m1v_ok := m1.?
  373. m2v, m2v_ok := m2.?
  374. if !m1v_ok || !m2v_ok {
  375. return false
  376. }
  377. return m1v.handle == m2v.handle
  378. }
  379. set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: $T) {
  380. draw_current_batch()
  381. if int(loc.buffer_idx) >= len(shd.constant_buffers) {
  382. log.warnf("Constant buffer idx %v is out of bounds", loc.buffer_idx)
  383. return
  384. }
  385. b := &shd.constant_buffers[loc.buffer_idx]
  386. if int(loc.offset) + size_of(val) > len(b.cpu_data) {
  387. log.warnf("Constant buffer idx %v is trying to be written out of bounds by at offset %v with %v bytes", loc.buffer_idx, loc.offset, size_of(val))
  388. return
  389. }
  390. dst := (^T)(&b.cpu_data[loc.offset])
  391. dst^ = val
  392. }
  393. set_shader_constant_mat4 :: proc(shader: Shader, loc: Shader_Constant_Location, val: matrix[4,4]f32) {
  394. set_shader_constant(shader, loc, val)
  395. }
  396. set_shader_constant_f32 :: proc(shader: Shader, loc: Shader_Constant_Location, val: f32) {
  397. set_shader_constant(shader, loc, val)
  398. }
  399. set_shader_constant_vec2 :: proc(shader: Shader, loc: Shader_Constant_Location, val: Vec2) {
  400. set_shader_constant(shader, loc, val)
  401. }
  402. get_default_shader :: proc() -> Shader {
  403. return s.default_shader
  404. }
  405. set_scissor_rect :: proc(scissor_rect: Maybe(Rect)) {
  406. panic("not implemented")
  407. }
  408. screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2 {
  409. panic("not implemented")
  410. }
  411. draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color) {
  412. }
  413. mouse_button_went_down :: proc(button: Mouse_Button) -> bool {
  414. panic("not implemented")
  415. }
  416. mouse_button_went_up :: proc(button: Mouse_Button) -> bool {
  417. panic("not implemented")
  418. }
  419. mouse_button_is_held :: proc(button: Mouse_Button) -> bool {
  420. panic("not implemented")
  421. }
  422. get_mouse_wheel_delta :: proc() -> f32 {
  423. return 0
  424. }
  425. get_mouse_position :: proc() -> Vec2 {
  426. panic("not implemented")
  427. }
  428. _batch_vertex :: proc(v: Vec2, uv: Vec2, color: Color) {
  429. v := v
  430. if s.vertex_buffer_cpu_used == len(s.vertex_buffer_cpu) {
  431. panic("Must dispatch here")
  432. }
  433. shd := s.batch_shader.? or_else s.default_shader
  434. base_offset := s.vertex_buffer_cpu_used
  435. pos_offset := shd.default_input_offsets[.Position]
  436. uv_offset := shd.default_input_offsets[.UV]
  437. color_offset := shd.default_input_offsets[.Color]
  438. mem.set(&s.vertex_buffer_cpu[base_offset], 0, shd.vertex_size)
  439. if pos_offset != -1 {
  440. (^Vec2)(&s.vertex_buffer_cpu[base_offset + pos_offset])^ = v
  441. }
  442. if uv_offset != -1 {
  443. (^Vec2)(&s.vertex_buffer_cpu[base_offset + uv_offset])^ = uv
  444. }
  445. if color_offset != -1 {
  446. (^Color)(&s.vertex_buffer_cpu[base_offset + color_offset])^ = color
  447. }
  448. override_offset: int
  449. for &o, idx in shd.input_overrides {
  450. input := &shd.inputs[idx]
  451. sz := shader_input_format_size(input.format)
  452. if o.used != 0 {
  453. mem.copy(&s.vertex_buffer_cpu[base_offset + override_offset], raw_data(&o.val), o.used)
  454. }
  455. override_offset += sz
  456. }
  457. s.vertex_buffer_cpu_used += shd.vertex_size
  458. }
  459. State :: struct {
  460. allocator: runtime.Allocator,
  461. custom_context: runtime.Context,
  462. wi: Window_Interface,
  463. window_state: rawptr,
  464. rb: Rendering_Backend,
  465. rb_state: rawptr,
  466. shutdown_wanted: bool,
  467. keys_went_down: #sparse [Keyboard_Key]bool,
  468. keys_went_up: #sparse [Keyboard_Key]bool,
  469. keys_is_held: #sparse [Keyboard_Key]bool,
  470. window: Window_Handle,
  471. width: int,
  472. height: int,
  473. shape_drawing_texture: Texture_Handle,
  474. batch_camera: Maybe(Camera),
  475. batch_shader: Maybe(Shader),
  476. batch_texture: Texture_Handle,
  477. view_matrix: Mat4,
  478. proj_matrix: Mat4,
  479. vertex_buffer_cpu: []u8,
  480. vertex_buffer_cpu_used: int,
  481. default_shader: Shader,
  482. }
  483. @(private="file")
  484. s: ^State
  485. wi: Window_Interface
  486. Shader_Input_Format :: enum {
  487. Unknown,
  488. RGBA32_Float,
  489. RGBA8_Norm,
  490. RGBA8_Norm_SRGB,
  491. RG32_Float,
  492. R32_Float,
  493. }
  494. Color :: [4]u8
  495. Vec2 :: [2]f32
  496. Vec3 :: [3]f32
  497. Mat4 :: matrix[4,4]f32
  498. Vec2i :: [2]int
  499. Rect :: struct {
  500. x, y: f32,
  501. w, h: f32,
  502. }
  503. Texture :: struct {
  504. handle: Texture_Handle,
  505. width: int,
  506. height: int,
  507. }
  508. Shader :: struct {
  509. handle: Shader_Handle,
  510. constant_buffers: []Shader_Constant_Buffer,
  511. constant_lookup: map[string]Shader_Constant_Location,
  512. constant_builtin_locations: [Shader_Builtin_Constant]Maybe(Shader_Constant_Location),
  513. inputs: []Shader_Input,
  514. input_overrides: []Shader_Input_Value_Override,
  515. default_input_offsets: [Shader_Default_Inputs]int,
  516. vertex_size: int,
  517. }
  518. Camera :: struct {
  519. target: Vec2,
  520. origin: Vec2,
  521. rotation: f32,
  522. zoom: f32,
  523. }
  524. // Support for up to 255 mouse buttons. Cast an int to type `Mouse_Button` to use things outside the
  525. // options presented here.
  526. Mouse_Button :: enum {
  527. Left,
  528. Right,
  529. Middle,
  530. Max = 255,
  531. }
  532. // TODO: These are just copied from raylib, we probably want a list of our own "default colors"
  533. WHITE :: Color { 255, 255, 255, 255 }
  534. BLACK :: Color { 0, 0, 0, 255 }
  535. GRAY :: Color{ 130, 130, 130, 255 }
  536. RED :: Color { 230, 41, 55, 255 }
  537. YELLOW :: Color { 253, 249, 0, 255 }
  538. BLUE :: Color { 0, 121, 241, 255 }
  539. MAGENTA :: Color { 255, 0, 255, 255 }
  540. DARKGRAY :: Color{ 80, 80, 80, 255 }
  541. GREEN :: Color{ 0, 228, 48, 255 }
  542. Shader_Handle :: distinct Handle
  543. SHADER_NONE :: Shader_Handle {}
  544. // Based on Raylib / GLFW
  545. Keyboard_Key :: enum {
  546. None = 0,
  547. // Alphanumeric keys
  548. Apostrophe = 39,
  549. Comma = 44,
  550. Minus = 45,
  551. Period = 46,
  552. Slash = 47,
  553. Zero = 48,
  554. One = 49,
  555. Two = 50,
  556. Three = 51,
  557. Four = 52,
  558. Five = 53,
  559. Six = 54,
  560. Seven = 55,
  561. Eight = 56,
  562. Nine = 57,
  563. Semicolon = 59,
  564. Equal = 61,
  565. A = 65,
  566. B = 66,
  567. C = 67,
  568. D = 68,
  569. E = 69,
  570. F = 70,
  571. G = 71,
  572. H = 72,
  573. I = 73,
  574. J = 74,
  575. K = 75,
  576. L = 76,
  577. M = 77,
  578. N = 78,
  579. O = 79,
  580. P = 80,
  581. Q = 81,
  582. R = 82,
  583. S = 83,
  584. T = 84,
  585. U = 85,
  586. V = 86,
  587. W = 87,
  588. X = 88,
  589. Y = 89,
  590. Z = 90,
  591. Left_Bracket = 91,
  592. Backslash = 92,
  593. Right_Bracket = 93,
  594. Grave = 96,
  595. // Function keys
  596. Space = 32,
  597. Escape = 256,
  598. Enter = 257,
  599. Tab = 258,
  600. Backspace = 259,
  601. Insert = 260,
  602. Delete = 261,
  603. Right = 262,
  604. Left = 263,
  605. Down = 264,
  606. Up = 265,
  607. Page_Up = 266,
  608. Page_Down = 267,
  609. Home = 268,
  610. End = 269,
  611. Caps_Lock = 280,
  612. Scroll_Lock = 281,
  613. Num_Lock = 282,
  614. Print_Screen = 283,
  615. Pause = 284,
  616. F1 = 290,
  617. F2 = 291,
  618. F3 = 292,
  619. F4 = 293,
  620. F5 = 294,
  621. F6 = 295,
  622. F7 = 296,
  623. F8 = 297,
  624. F9 = 298,
  625. F10 = 299,
  626. F11 = 300,
  627. F12 = 301,
  628. Left_Shift = 340,
  629. Left_Control = 341,
  630. Left_Alt = 342,
  631. Left_Super = 343,
  632. Right_Shift = 344,
  633. Right_Control = 345,
  634. Right_Alt = 346,
  635. Right_Super = 347,
  636. Menu = 348,
  637. // Keypad keys
  638. KP_0 = 320,
  639. KP_1 = 321,
  640. KP_2 = 322,
  641. KP_3 = 323,
  642. KP_4 = 324,
  643. KP_5 = 325,
  644. KP_6 = 326,
  645. KP_7 = 327,
  646. KP_8 = 328,
  647. KP_9 = 329,
  648. KP_Decimal = 330,
  649. KP_Divide = 331,
  650. KP_Multiply = 332,
  651. KP_Subtract = 333,
  652. KP_Add = 334,
  653. KP_Enter = 335,
  654. KP_Equal = 336,
  655. }