karl2d.odin 19 KB

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