| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935 |
- // This file is purely documentational. It is generated from the contents of 'karl2d.odin'.
- #+build ignore
- package karl2d
- //-----------------------------------------------//
- // SETUP, WINDOW MANAGEMENT AND FRAME MANAGEMENT //
- //-----------------------------------------------//
- // Opens a window and initializes some internal state. The internal state will use `allocator` for
- // all dynamically allocated memory. The return value can be ignored unless you need to later call
- // `set_internal_state`.
- //
- // `screen_width` and `screen_height` refer to the the resolution of the drawable area of the
- // window. The window might be slightly larger due borders and headers.
- init :: proc(
- screen_width: int,
- screen_height: int,
- window_title: string,
- options := Init_Options {},
- allocator := context.allocator,
- loc := #caller_location
- ) -> ^State
- // Returns true the user has pressed the close button on the window, or used a key stroke such as
- // ALT+F4 on Windows. The application can decide if it wants to shut down or if it wants to show
- // some kind of confirmation dialogue.
- //
- // Commonly used for creating the "main loop" of a game: `for !k2.shutdown_wanted {}`
- shutdown_wanted :: proc() -> bool
- // Closes the window and cleans up Karl2D's internal state.
- shutdown :: proc()
- // Clear the "screen" with the supplied color. By default this will clear your window. But if you
- // have set a Render Texture using the `set_render_texture` procedure, then that Render Texture will
- // be cleared instead.
- clear :: proc(color: Color)
- // Call at the start of each frame. This procedure does two main things:
- // - Fetches how long the previous frame took and how long since the program started. These values
- // can be fetched using `get_frame_time()` and `get_time()`
- // - Clears Karl2D's internal "frame_allocator" -- that's the allocator the library uses for
- // dynamic memory that has a lifetime of a single frame.
- new_frame :: proc()
- // "Flips the backbuffer": Call at end of frame to make everything you've drawn appear on the screen.
- //
- // When you draw using for example `draw_texture`, then that stuff is drawn to an invisible texture
- // called a "backbuffer". This makes sure that we don't see half-drawn frames. So when you are happy
- // with a frame and want to show it to the player, call this procedure.
- //
- // WebGL note: WebGL does the backbuffer flipping automatically. But you should still call this to
- // make sure that all rendering has been sent off to the GPU (it calls `draw_current_batch()`).
- present :: proc()
- // Call at start or end of frame to process all events that have arrived to the window. This
- // includes keyboard, mouse, gamepad and window events.
- //
- // WARNING: Not calling this will make your program impossible to interact with.
- process_events :: proc()
- // Returns how many seconds the previous frame took. Often a tiny number such as 0.016 s.
- //
- // You must call `new_frame()` at the start of your frame in order for the frame_time to be updated.
- get_frame_time :: proc() -> f32
- // Returns how many seconds has elapsed since the game started.
- //
- // You must call `new_frame()` at the start of your frame for this value to get updated.
- get_time :: proc() -> f64
- // Gets the width of the drawing area within the window. The returned number is not scaled by any
- // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
- get_screen_width :: proc() -> int
- // Gets the height of the drawing area within the window. The returned number is not scaled by any
- // monitor DPI scaling. You do that manually using the number returned by `get_window_scale()`.
- get_screen_height :: proc() -> int
- // Moves the window.
- //
- // This does nothing for web builds.
- set_window_position :: proc(x: int, y: int)
- // Resize the window to a new size. If the window has the flag Resizable set, then the backbuffer
- // will also be resized.
- set_window_size :: proc(width: int, height: int)
- // Fetch the scale of the window. This usually comes from some DPI scaling setting in the OS.
- // 1 means 100% scale, 1.5 means 150% etc.
- get_window_scale :: proc() -> f32
- // Use to change between windowed mode, resizable windowed mode and fullscreen
- set_window_mode :: proc(window_mode: Window_Mode)
- // Flushes the current batch. This sends off everything to the GPU that has been queued in the
- // current batch. Normally, you do not need to do this manually. It is done automatically when these
- // procedures run:
- //
- // - present
- // - set_camera
- // - set_shader
- // - set_shader_constant
- // - set_scissor_rect
- // - set_blend_mode
- // - set_render_texture
- // - clear
- // - draw_texture_* IF previous draw did not use the same texture (1)
- // - draw_rect_*, draw_circle_*, draw_line IF previous draw did not use the shapes drawing texture (2)
- //
- // (1) When drawing textures, the current texture is fed into the active shader. Everything within
- // the same batch must use the same texture. So drawing with a new texture forces the current to
- // be drawn. You can combine several textures into an atlas to get bigger batches.
- //
- // (2) In order to use the same shader for shapes drawing and textured drawing, the shapes drawing
- // uses a blank, white texture. For the same reasons as (1), drawing something else than shapes
- // before drawing a shape will break up the batches. In a future update I'll add so that you can
- // set your own shapes drawing texture, making it possible to combine it with a bigger atlas.
- //
- // The batch has maximum size of VERTEX_BUFFER_MAX bytes. The shader dictates how big a vertex is
- // so the maximum number of vertices that can be drawn in each batch is
- // VERTEX_BUFFER_MAX / shader.vertex_size
- draw_current_batch :: proc()
- //-------//
- // INPUT //
- //-------//
- // Returns true if a keyboard key went down between the current and the previous frame. Set when
- // 'process_events' runs.
- key_went_down :: proc(key: Keyboard_Key) -> bool
- // Returns true if a keyboard key went up (was released) between the current and the previous frame.
- // Set when 'process_events' runs.
- key_went_up :: proc(key: Keyboard_Key) -> bool
- // Returns true if a keyboard is currently being held down. Set when 'process_events' runs.
- key_is_held :: proc(key: Keyboard_Key) -> bool
- // Returns true if a mouse button went down between the current and the previous frame. Specify
- // which mouse button using the `button` parameter.
- //
- // Set when 'process_events' runs.
- mouse_button_went_down :: proc(button: Mouse_Button) -> bool
- // Returns true if a mouse button went up (was released) between the current and the previous frame.
- // Specify which mouse button using the `button` parameter.
- //
- // Set when 'process_events' runs.
- mouse_button_went_up :: proc(button: Mouse_Button) -> bool
- // Returns true if a mouse button is currently being held down. Specify which mouse button using the
- // `button` parameter. Set when 'process_events' runs.
- mouse_button_is_held :: proc(button: Mouse_Button) -> bool
- // Returns how many clicks the mouse wheel has scrolled between the previous and current frame.
- get_mouse_wheel_delta :: proc() -> f32
- // Returns the mouse position, measured from the top-left corner of the window.
- get_mouse_position :: proc() -> Vec2
- // Returns how many pixels the mouse moved between the previous and the current frame.
- get_mouse_delta :: proc() -> Vec2
- // Returns true if a gamepad with the supplied index is connected. The parameter should be a value
- // between 0 and MAX_GAMEPADS.
- is_gamepad_active :: proc(gamepad: Gamepad_Index) -> bool
- // Returns true if a gamepad button went down between the previous and the current frame.
- gamepad_button_went_down :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
- // Returns true if a gamepad button went up (was released) between the previous and the current
- // frame.
- gamepad_button_went_up :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
- // Returns true if a gamepad button is currently held down.
- //
- // The "trigger buttons" on some gamepads also have an analogue "axis value" associated with them.
- // Fetch that value using `get_gamepad_axis()`.
- gamepad_button_is_held :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
- // Returns the value of analogue gamepad axes such as the thumbsticks and trigger buttons. The value
- // is in the range -1 to 1 for sticks and 0 to 1 for trigger buttons.
- get_gamepad_axis :: proc(gamepad: Gamepad_Index, axis: Gamepad_Axis) -> f32
- // Set the left and right vibration motor speed. The range of left and right is 0 to 1. Note that on
- // most gamepads, the left motor is "low frequency" and the right motor is "high frequency". They do
- // not vibrate with the same speed.
- set_gamepad_vibration :: proc(gamepad: Gamepad_Index, left: f32, right: f32)
- //---------//
- // DRAWING //
- //---------//
- // Draw a colored rectangle. The rectangles have their (x, y) position in the top-left corner of the
- // rectangle.
- draw_rect :: proc(r: Rect, c: Color)
- // Creates a rectangle from a position and a size and draws it.
- draw_rect_vec :: proc(pos: Vec2, size: Vec2, c: Color)
- // Draw a rectangle with a custom origin and rotation.
- //
- // The origin says which point the rotation rotates around. If the origin is `(0, 0)`, then the
- // rectangle rotates around the top-left corner of the rectangle. If it is `(rect.w/2, rect.h/2)`
- // then the rectangle rotates around its center.
- draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color)
- // Draw the outline of a rectangle with a specific thickness. The outline is drawn using four
- // rectangles.
- draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color)
- // Draw a circle with a certain center and radius. Note the `segments` parameter: This circle is not
- // perfect! It is drawn using a number of "cake segments".
- draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16)
- // Like `draw_circle` but only draws the outer edge of the circle.
- draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Color, segments := 16)
- // Draws a line from `start` to `end` of a certain thickness.
- draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color)
- // Draw a texture at a specific position. The texture will be drawn with its top-left corner at
- // position `pos`.
- //
- // Load textures using `load_texture_from_file` or `load_texture_from_bytes`.
- draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE)
- // Draw a section of a texture at a specific position. `rect` is a rectangle measured in pixels. It
- // tells the procedure which part of the texture to display. The texture will be drawn with its
- // top-left corner at position `pos`.
- draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE)
- // Draw a texture by taking a section of the texture specified by `src` and draw it into the area of
- // the screen specified by `dst`. You can also rotate the texture around an origin point of your
- // choice.
- //
- // Tip: Use `k2.get_texture_rect(tex)` for `src` if you want to draw the whole texture.
- draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE)
- // Tells you how much space some text of a certain size will use on the screen. The font used is the
- // default font. The return value contains the width and height of the text.
- measure_text :: proc(text: string, font_size: f32) -> Vec2
- // Tells you how much space some text of a certain size will use on the screen, using a custom font.
- // The return value contains the width and height of the text.
- measure_text_ex :: proc(font_handle: Font, text: string, font_size: f32) -> Vec2
- // Draw text at a position with a size. This uses the default font. `pos` will be equal to the
- // top-left position of the text.
- draw_text :: proc(text: string, pos: Vec2, font_size: f32, color := BLACK)
- // Draw text at a position with a size, using a custom font. `pos` will be equal to the top-left
- // position of the text.
- draw_text_ex :: proc(font_handle: Font, text: string, pos: Vec2, font_size: f32, color := BLACK)
- //--------------------//
- // TEXTURE MANAGEMENT //
- //--------------------//
- // Create an empty texture.
- create_texture :: proc(width: int, height: int, format: Pixel_Format) -> Texture
- // Load a texture from disk and upload it to the GPU so you can draw it to the screen.
- // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
- //
- // The `options` parameter can be used to specify things things such as premultiplication of alpha.
- load_texture_from_file :: proc(filename: string, options: Load_Texture_Options = {}) -> Texture
- // Load a texture from a byte slice and upload it to the GPU so you can draw it to the screen.
- // Supports PNG, BMP, TGA and baseline PNG. Note that progressive PNG files are not supported!
- //
- // The `options` parameter can be used to specify things things such as premultiplication of alpha.
- load_texture_from_bytes :: proc(bytes: []u8, options: Load_Texture_Options = {}) -> Texture
- // Load raw texture data. You need to specify the data, size and format of the texture yourself.
- // This assumes that there is no header in the data. If your data has a header (you read the data
- // from a file on disk), then please use `load_texture_from_bytes` instead.
- load_texture_from_bytes_raw :: proc(bytes: []u8, width: int, height: int, format: Pixel_Format) -> Texture
- // Get a rectangle that spans the whole texture. Coordinates will be (x, y) = (0, 0) and size
- // (w, h) = (texture_width, texture_height)
- get_texture_rect :: proc(t: Texture) -> Rect
- // Update a texture with new pixels. `bytes` is the new pixel data. `rect` is the rectangle in
- // `tex` where the new pixels should end up.
- update_texture :: proc(tex: Texture, bytes: []u8, rect: Rect) -> bool
- // Destroy a texture, freeing up any memory it has used on the GPU.
- destroy_texture :: proc(tex: Texture)
- // Controls how a texture should be filtered. You can choose "point" or "linear" filtering. Which
- // means "pixly" or "smooth". This filter will be used for up and down-scaling as well as for
- // mipmap sampling. Use `set_texture_filter_ex` if you need to control these settings separately.
- set_texture_filter :: proc(t: Texture, filter: Texture_Filter)
- // Controls how a texture should be filtered. `scale_down_filter` and `scale_up_filter` controls how
- // the texture is filtered when we render the texture at a smaller or larger size.
- // `mip_filter` controls how the texture is filtered when it is sampled using _mipmapping_.
- //
- // TODO: Add mipmapping generation controls for texture and refer to it from here.
- set_texture_filter_ex :: proc(
- t: Texture,
- scale_down_filter: Texture_Filter,
- scale_up_filter: Texture_Filter,
- mip_filter: Texture_Filter,
- )
- //-----------------//
- // RENDER TEXTURES //
- //-----------------//
- // Create a texture that you can render into. Meaning that you can draw into it instead of drawing
- // onto the screen. Use `set_render_texture` to enable this Render Texture for drawing.
- create_render_texture :: proc(width: int, height: int) -> Render_Texture
- // Destroy a Render_Texture previously created using `create_render_texture`.
- destroy_render_texture :: proc(render_texture: Render_Texture)
- // Make all rendering go into a texture instead of onto the screen. Create the render texture using
- // `create_render_texture`. Pass `nil` to resume drawing onto the screen.
- set_render_texture :: proc(render_texture: Maybe(Render_Texture))
- //-------//
- // FONTS //
- //-------//
- // Loads a font from disk and returns a handle that represents it.
- load_font_from_file :: proc(filename: string) -> Font
- // Loads a font from a block of memory and returns a handle that represents it.
- load_font_from_bytes :: proc(data: []u8) -> Font
- // Destroy a font previously loaded using `load_font_from_file` or `load_font_from_bytes`.
- destroy_font :: proc(font: Font)
- // Returns the built-in font of Karl2D (the font is known as "roboto")
- get_default_font :: proc() -> Font
- //---------//
- // SHADERS //
- //---------//
- // Load a shader from a vertex and fragment shader file. If the vertex and fragment shaders live in
- // the same file, then pass it twice.
- //
- // `layout_formats` can in many cases be left default initialized. It is used to specify the format
- // of the vertex shader inputs. By formats this means the format that you pass on the CPU side.
- load_shader_from_file :: proc(
- vertex_filename: string,
- fragment_filename: string,
- layout_formats: []Pixel_Format = {}
- ) -> Shader
- // Load a vertex and fragment shader from a block of memory. See `load_shader_from_file` for what
- // `layout_formats` means.
- load_shader_from_bytes :: proc(
- vertex_shader_bytes: []byte,
- fragment_shader_bytes: []byte,
- layout_formats: []Pixel_Format = {},
- ) -> Shader
- // Destroy a shader previously loaded using `load_shader_from_file` or `load_shader_from_bytes`
- destroy_shader :: proc(shader: Shader)
- // Fetches the shader that Karl2D uses by default.
- get_default_shader :: proc() -> Shader
- // The supplied shader will be used for subsequent drawing. Return to the default shader by calling
- // `set_shader(nil)`.
- set_shader :: proc(shader: Maybe(Shader))
- // Set the value of a constant (also known as uniform in OpenGL). Look up shader constant locations
- // (the kind of value needed for `loc`) by running `loc := shader.constant_lookup["constant_name"]`.
- set_shader_constant :: proc(shd: Shader, loc: Shader_Constant_Location, val: any)
- // Sets the value of a shader input (also known as a shader attribute). There are three default
- // shader inputs known as position, texcoord and color. If you have shader with additional inputs,
- // then you can use this procedure to set their values. This is a way to feed per-object data into
- // your shader.
- //
- // `input` should be the index of the input and `val` should be a value of the correct size.
- //
- // You can modify which type that is expected for `val` by passing a custom `layout_formats` when
- // you load the shader.
- override_shader_input :: proc(shader: Shader, input: int, val: any)
- // Returns the number of bytes that a pixel in a texture uses.
- pixel_format_size :: proc(f: Pixel_Format) -> int
- //-------------------------------//
- // CAMERA AND COORDINATE SYSTEMS //
- //-------------------------------//
- // Make Karl2D use a camera. Return to the "default camera" by passing `nil`. All drawing operations
- // will use this camera until you again change it.
- set_camera :: proc(camera: Maybe(Camera))
- // Transform a point `pos` that lives on the screen to a point in the world. This can be useful for
- // bringing (for example) mouse positions (k2.get_mouse_position()) into world-space.
- screen_to_world :: proc(pos: Vec2, camera: Camera) -> Vec2
- // Transform a point `pos` that lices in the world to a point on the screen. This can be useful when
- // you need to take a position in the world and compare it to a screen-space point.
- world_to_screen :: proc(pos: Vec2, camera: Camera) -> Vec2
- // Get the matrix that `screen_to_world` and `world_to_screen` uses to do their transformations.
- //
- // A view matrix is essentially the world transform matrix of the camera, but inverted. In other
- // words, instead of bringing the camera in front of things in the world, we bring everything in the
- // world "in front of the camera".
- //
- // Instead of constructing the camera matrix and doing a matrix inverse, here we just do the
- // maths in "backwards order". I.e. a camera transform matrix would be:
- //
- // target_translate * rot * scale * offset_translate
- //
- // but we do
- //
- // inv_offset_translate * inv_scale * inv_rot * inv_target_translate
- //
- // This is faster, since matrix inverses are expensive.
- get_camera_view_matrix :: proc(c: Camera) -> Mat4
- // Get the matrix that brings something in front of the camera.
- get_camera_world_matrix :: proc(c: Camera) -> Mat4
- //------//
- // MISC //
- //------//
- // Choose how the alpha channel is used when mixing half-transparent color with what is already
- // drawn. The default is the .Alpha mode, but you also have the option of using .Premultiply_Alpha.
- set_blend_mode :: proc(mode: Blend_Mode)
- // Make everything outside of the screen-space rectangle `scissor_rect` not render. Disable the
- // scissor rectangle by running `set_scissor_rect(nil)`.
- set_scissor_rect :: proc(scissor_rect: Maybe(Rect))
- // Restore the internal state using the pointer returned by `init`. Useful after reloading the
- // library (for example, when doing code hot reload).
- set_internal_state :: proc(state: ^State)
- //---------------------//
- // TYPES AND CONSTANTS //
- //---------------------//
- Vec2 :: [2]f32
- Vec3 :: [3]f32
- Vec4 :: [4]f32
- Mat4 :: matrix[4,4]f32
- // A rectangle that sits at position (x, y) and has size (w, h).
- Rect :: struct {
- x, y: f32,
- w, h: f32,
- }
- // An RGBA (Red, Green, Blue, Alpha) color. Each channel can have a value between 0 and 255.
- Color :: [4]u8
- // See the folder examples/palette for a demo that shows all colors
- BLACK :: Color { 0, 0, 0, 255 }
- WHITE :: Color { 255, 255, 255, 255 }
- BLANK :: Color { 0, 0, 0, 0 }
- GRAY :: Color { 183, 183, 183, 255 }
- DARK_GRAY :: Color { 66, 66, 66, 255}
- BLUE :: Color { 25, 198, 236, 255 }
- DARK_BLUE :: Color { 7, 47, 88, 255 }
- LIGHT_BLUE :: Color { 200, 230, 255, 255 }
- GREEN :: Color { 16, 130, 11, 255 }
- DARK_GREEN :: Color { 6, 53, 34, 255}
- LIGHT_GREEN :: Color { 175, 246, 184, 255 }
- ORANGE :: Color { 255, 114, 0, 255 }
- RED :: Color { 239, 53, 53, 255 }
- DARK_RED :: Color { 127, 10, 10, 255 }
- LIGHT_RED :: Color { 248, 183, 183, 255 }
- BROWN :: Color { 115, 78, 74, 255 }
- DARK_BROWN :: Color { 50, 36, 32, 255 }
- LIGHT_BROWN :: Color { 146, 119, 119, 255 }
- PURPLE :: Color { 155, 31, 232, 255 }
- LIGHT_PURPLE :: Color { 217, 172, 248, 255 }
- MAGENTA :: Color { 209, 17, 209, 255 }
- YELLOW :: Color { 250, 250, 129, 255 }
- LIGHT_YELLOW :: Color { 253, 250, 222, 255 }
- // These are from Raylib. They are here so you can easily port a Raylib program to Karl2D.
- RL_LIGHTGRAY :: Color { 200, 200, 200, 255 }
- RL_GRAY :: Color { 130, 130, 130, 255 }
- RL_DARKGRAY :: Color { 80, 80, 80, 255 }
- RL_YELLOW :: Color { 253, 249, 0, 255 }
- RL_GOLD :: Color { 255, 203, 0, 255 }
- RL_ORANGE :: Color { 255, 161, 0, 255 }
- RL_PINK :: Color { 255, 109, 194, 255 }
- RL_RED :: Color { 230, 41, 55, 255 }
- RL_MAROON :: Color { 190, 33, 55, 255 }
- RL_GREEN :: Color { 0, 228, 48, 255 }
- RL_LIME :: Color { 0, 158, 47, 255 }
- RL_DARKGREEN :: Color { 0, 117, 44, 255 }
- RL_SKYBLUE :: Color { 102, 191, 255, 255 }
- RL_BLUE :: Color { 0, 121, 241, 255 }
- RL_DARKBLUE :: Color { 0, 82, 172, 255 }
- RL_PURPLE :: Color { 200, 122, 255, 255 }
- RL_VIOLET :: Color { 135, 60, 190, 255 }
- RL_DARKPURPLE :: Color { 112, 31, 126, 255 }
- RL_BEIGE :: Color { 211, 176, 131, 255 }
- RL_BROWN :: Color { 127, 106, 79, 255 }
- RL_DARKBROWN :: Color { 76, 63, 47, 255 }
- RL_WHITE :: WHITE
- RL_BLACK :: BLACK
- RL_BLANK :: BLANK
- RL_MAGENTA :: Color { 255, 0, 255, 255 }
- RL_RAYWHITE :: Color { 245, 245, 245, 255 }
- color_alpha :: proc(c: Color, a: u8) -> Color
- Texture :: struct {
- // The render-backend specific texture identifier.
- handle: Texture_Handle,
- // The horizontal size of the texture, measured in pixels.
- width: int,
- // The vertical size of the texture, measure in pixels.
- height: int,
- }
- Load_Texture_Option :: enum {
- // Will multiply the alpha value of the each pixel into the its RGB values. Useful if you want
- // to use `set_blend_mode(.Premultiplied_Alpha)`
- Premultiply_Alpha,
- }
- Load_Texture_Options :: bit_set[Load_Texture_Option]
- Blend_Mode :: enum {
- Alpha,
- // Requires the alpha-channel to be multiplied into texture RGB channels. You can automatically
- // do this using the `Premultiply_Alpha` option when loading a texture.
- Premultiplied_Alpha,
- }
- // A render texture is a texture that you can draw into, instead of drawing to the screen. Create
- // one using `create_render_texture`.
- Render_Texture :: struct {
- // The texture that the things will be drawn into. You can use this as a normal texture, for
- // example, you can pass it to `draw_texture`.
- texture: Texture,
- // The render backend's internal identifier. It describes how to use the texture as something
- // the render backend can draw into.
- render_target: Render_Target_Handle,
- }
- Texture_Filter :: enum {
- Point, // Similar to "nearest neighbor". Pixly texture scaling.
- Linear, // Smoothed texture scaling.
- }
- Camera :: struct {
- // Where the camera looks.
- target: Vec2,
- // By default `target` will be the position of the upper-left corner of the camera. Use this
- // offset to change that. If you set the offset to half the size of the camera view, then the
- // target position will end up in the middle of the scren.
- offset: Vec2,
- // Rotate the camera (unit: degrees)
- rotation: f32,
- // Zoom the camera. A bigger value means "more zoom".
- //
- // To make a certain amount of pixels always occupy the height of the camera, set the zoom to:
- //
- // k2.get_screen_height()/wanted_pixel_height
- zoom: f32,
- }
- Window_Mode :: enum {
- Windowed,
- Windowed_Resizable,
- Windowed_Borderless_Fullscreen,
- }
- Init_Options :: struct {
- window_mode: Window_Mode,
- }
- Shader_Handle :: distinct Handle
- SHADER_NONE :: Shader_Handle {}
- Shader_Constant_Location :: struct {
- offset: int,
- size: int,
- }
- Shader :: struct {
- // The render backend's internal identifier.
- handle: Shader_Handle,
- // We store the CPU-side value of all constants in a single buffer to have less allocations.
- // The 'constants' array says where in this buffer each constant is, and 'constant_lookup'
- // maps a name to a constant location.
- constants_data: []u8,
- constants: []Shader_Constant_Location,
- // Look up named constants. If you have a constant (uniform) in the shader called "bob", then
- // you can find its location by running `shader.constant_lookup["bob"]`. You can then use that
- // location in combination with `set_shader_constant`
- constant_lookup: map[string]Shader_Constant_Location,
- // Maps built in constant types such as "model view projection matrix" to a location.
- constant_builtin_locations: [Shader_Builtin_Constant]Maybe(Shader_Constant_Location),
- texture_bindpoints: []Texture_Handle,
- // Used to lookup bindpoints of textures. You can then set the texture by overriding
- // `shader.texture_bindpoints[shader.texture_lookup["some_tex"]] = some_texture.handle`
- texture_lookup: map[string]int,
- default_texture_index: Maybe(int),
- inputs: []Shader_Input,
- // Overrides the value of a specific vertex input.
- //
- // It's recommended you use `override_shader_input` to modify these overrides.
- input_overrides: []Shader_Input_Value_Override,
- default_input_offsets: [Shader_Default_Inputs]int,
- // How many bytes a vertex uses gives the input of the shader.
- vertex_size: int,
- }
- SHADER_INPUT_VALUE_MAX_SIZE :: 256
- Shader_Input_Value_Override :: struct {
- val: [SHADER_INPUT_VALUE_MAX_SIZE]u8,
- used: int,
- }
- Shader_Input_Type :: enum {
- F32,
- Vec2,
- Vec3,
- Vec4,
- }
- Shader_Builtin_Constant :: enum {
- MVP,
- }
- Shader_Default_Inputs :: enum {
- Unknown,
- Position,
- UV,
- Color,
- }
- Shader_Input :: struct {
- name: string,
- register: int,
- type: Shader_Input_Type,
- format: Pixel_Format,
- }
- Pixel_Format :: enum {
- Unknown,
-
- RGBA_32_Float,
- RGB_32_Float,
- RG_32_Float,
- R_32_Float,
- RGBA_8_Norm,
- RG_8_Norm,
- R_8_Norm,
- R_8_UInt,
- }
- Font_Data :: struct {
- atlas: Texture,
- // internal
- fontstash_handle: int,
- }
- Handle :: hm.Handle
- Texture_Handle :: distinct Handle
- Render_Target_Handle :: distinct Handle
- Font :: distinct int
- FONT_NONE :: Font {}
- TEXTURE_NONE :: Texture_Handle {}
- RENDER_TARGET_NONE :: Render_Target_Handle {}
- // This keeps track of the internal state of the library. Usually, you do not need to poke at it.
- // It is created and kept as a global variable when 'init' is called. However, 'init' also returns
- // the pointer to it, so you can later use 'set_internal_state' to restore it (after for example hot
- // reload).
- State :: struct {
- allocator: runtime.Allocator,
- frame_arena: runtime.Arena,
- frame_allocator: runtime.Allocator,
- win: Window_Interface,
- window_state: rawptr,
- rb: Render_Backend_Interface,
- rb_state: rawptr,
- fs: fs.FontContext,
-
- shutdown_wanted: bool,
- mouse_position: Vec2,
- mouse_delta: Vec2,
- mouse_wheel_delta: f32,
- key_went_down: #sparse [Keyboard_Key]bool,
- key_went_up: #sparse [Keyboard_Key]bool,
- key_is_held: #sparse [Keyboard_Key]bool,
- mouse_button_went_down: #sparse [Mouse_Button]bool,
- mouse_button_went_up: #sparse [Mouse_Button]bool,
- mouse_button_is_held: #sparse [Mouse_Button]bool,
- gamepad_button_went_down: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
- gamepad_button_went_up: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
- gamepad_button_is_held: [MAX_GAMEPADS]#sparse [Gamepad_Button]bool,
- window: Window_Handle,
- default_font: Font,
- fonts: [dynamic]Font_Data,
- shape_drawing_texture: Texture_Handle,
- batch_font: Font,
- batch_camera: Maybe(Camera),
- batch_shader: Shader,
- batch_scissor: Maybe(Rect),
- batch_texture: Texture_Handle,
- batch_render_target: Render_Target_Handle,
- batch_blend_mode: Blend_Mode,
- view_matrix: Mat4,
- proj_matrix: Mat4,
- depth: f32,
- depth_start: f32,
- depth_increment: f32,
- vertex_buffer_cpu: []u8,
- vertex_buffer_cpu_used: int,
- default_shader: Shader,
- // Time when the first call to `new_frame` happened
- start_time: time.Time,
- prev_frame_time: time.Time,
- // "dt"
- frame_time: f32,
- time: f64,
- }
- // Support for up to 255 mouse buttons. Cast an int to type `Mouse_Button` to use things outside the
- // options presented here.
- Mouse_Button :: enum {
- Left,
- Right,
- Middle,
- Max = 255,
- }
- // Based on Raylib / GLFW
- Keyboard_Key :: enum {
- None = 0,
- // Numeric keys (top row)
- N0 = 48,
- N1 = 49,
- N2 = 50,
- N3 = 51,
- N4 = 52,
- N5 = 53,
- N6 = 54,
- N7 = 55,
- N8 = 56,
- N9 = 57,
- // Letter keys
- A = 65,
- B = 66,
- C = 67,
- D = 68,
- E = 69,
- F = 70,
- G = 71,
- H = 72,
- I = 73,
- J = 74,
- K = 75,
- L = 76,
- M = 77,
- N = 78,
- O = 79,
- P = 80,
- Q = 81,
- R = 82,
- S = 83,
- T = 84,
- U = 85,
- V = 86,
- W = 87,
- X = 88,
- Y = 89,
- Z = 90,
- // Special characters
- Apostrophe = 39,
- Comma = 44,
- Minus = 45,
- Period = 46,
- Slash = 47,
- Semicolon = 59,
- Equal = 61,
- Left_Bracket = 91,
- Backslash = 92,
- Right_Bracket = 93,
- Backtick = 96,
- // Function keys, modifiers, caret control etc
- Space = 32,
- Escape = 256,
- Enter = 257,
- Tab = 258,
- Backspace = 259,
- Insert = 260,
- Delete = 261,
- Right = 262,
- Left = 263,
- Down = 264,
- Up = 265,
- Page_Up = 266,
- Page_Down = 267,
- Home = 268,
- End = 269,
- Caps_Lock = 280,
- Scroll_Lock = 281,
- Num_Lock = 282,
- Print_Screen = 283,
- Pause = 284,
- F1 = 290,
- F2 = 291,
- F3 = 292,
- F4 = 293,
- F5 = 294,
- F6 = 295,
- F7 = 296,
- F8 = 297,
- F9 = 298,
- F10 = 299,
- F11 = 300,
- F12 = 301,
- Left_Shift = 340,
- Left_Control = 341,
- Left_Alt = 342,
- Left_Super = 343,
- Right_Shift = 344,
- Right_Control = 345,
- Right_Alt = 346,
- Right_Super = 347,
- Menu = 348,
- // Numpad keys
- NP_0 = 320,
- NP_1 = 321,
- NP_2 = 322,
- NP_3 = 323,
- NP_4 = 324,
- NP_5 = 325,
- NP_6 = 326,
- NP_7 = 327,
- NP_8 = 328,
- NP_9 = 329,
- NP_Decimal = 330,
- NP_Divide = 331,
- NP_Multiply = 332,
- NP_Subtract = 333,
- NP_Add = 334,
- NP_Enter = 335,
- NP_Equal = 336,
- }
- MAX_GAMEPADS :: 4
- // A value between 0 and MAX_GAMEPADS - 1
- Gamepad_Index :: int
- Gamepad_Axis :: enum {
- Left_Stick_X,
- Left_Stick_Y,
- Right_Stick_X,
- Right_Stick_Y,
- Left_Trigger,
- Right_Trigger,
- }
- Gamepad_Button :: enum {
- // DPAD buttons
- Left_Face_Up,
- Left_Face_Down,
- Left_Face_Left,
- Left_Face_Right,
- Right_Face_Up, // XBOX: Y, PS: Triangle
- Right_Face_Down, // XBOX: A, PS: X
- Right_Face_Left, // XBOX: X, PS: Square
- Right_Face_Right, // XBOX: B, PS: Circle
- Left_Shoulder,
- Left_Trigger,
- Right_Shoulder,
- Right_Trigger,
- Left_Stick_Press, // Clicking the left analogue stick
- Right_Stick_Press, // Clicking the right analogue stick
- Middle_Face_Left, // Select / back / options button
- Middle_Face_Middle, // PS button (not available on XBox)
- Middle_Face_Right, // Start
- }
|