Geen omschrijving

Karl Zylinski 5a1b74cb0c Disable key repeat in win32 1 maand geleden
.github 6be8507d02 Make ci check instead of build 1 maand geleden
.sublime babd6721ea X11 windowing stub, nothing works yet 1 maand geleden
api_doc_builder 2355e776cd Docs 1 maand geleden
build_web 9ffc670c27 Fix for build_web using wrong permissions on linux 1 maand geleden
examples e01dfd29a3 Made render textures example a bit better 1 maand geleden
handle_map c994c4c77b Some kind of texture handle concept 5 maanden geleden
.gitignore 4ca5775e29 Generalise 'build_web' program so it sounds less tied to the examples 1 maand geleden
LICENSE 361c3c9672 Snake example 5 maanden geleden
README.md a684da9544 Note about lld 1 maand geleden
TODO.md e929de5497 todo 1 maand geleden
karl2d.doc.odin 611815e2ab Rename Windowed_Borderless_Fullscreen to just Borderless_Fullscreen 1 maand geleden
karl2d.odin 611815e2ab Rename Windowed_Borderless_Fullscreen to just Borderless_Fullscreen 1 maand geleden
render_backend_chooser.odin 0bac2e5a50 Better render backend naming 1 maand geleden
render_backend_d3d11.odin 0bac2e5a50 Better render backend naming 1 maand geleden
render_backend_d3d11_default_shader.hlsl 3d076f7bf5 Rename default hlsl shader 2 maanden geleden
render_backend_gl.odin babd6721ea X11 windowing stub, nothing works yet 1 maand geleden
render_backend_gl_default_fragment_shader.glsl 4ec00f3e66 Use 300 es shader for default gl/webgl shader (works with both APIs) 1 maand geleden
render_backend_gl_default_vertex_shader.glsl 4ec00f3e66 Use 300 es shader for default gl/webgl shader (works with both APIs) 1 maand geleden
render_backend_gl_windows.odin 13490b536d Enable vsync on gl-windows 2 maanden geleden
render_backend_interface.odin 100d2362e2 Render texture support in GL 1 maand geleden
render_backend_nil.odin babd6721ea X11 windowing stub, nothing works yet 1 maand geleden
render_backend_webgl.odin 787c8b342b Use CheckFramebufferStatus in webgl (added it to bindings) 1 maand geleden
roboto.ttf 3cc43427a0 Some basic font rendering 4 maanden geleden
window_interface.odin 233ebf7dd2 Borderless fullscreen support. Changed `init` to take an Init_Options struct that has a Window_Mode enum that says if you want Windowed, Windowed_Resizable or Borderless_Fullscreen 1 maand geleden
window_interface_chooser.odin babd6721ea X11 windowing stub, nothing works yet 1 maand geleden
window_js.odin 611815e2ab Rename Windowed_Borderless_Fullscreen to just Borderless_Fullscreen 1 maand geleden
window_win32.odin 5a1b74cb0c Disable key repeat in win32 1 maand geleden
window_x11.odin ddc32fed43 X11 window creation 1 maand geleden

README.md

karl2d_logo

Karl2D is a library for creating 2D games using the Odin programming language. The focus is on making 2D gamdev fun, fast and beginner friendly.

See karl2d.doc.odin for an API overview.

Here's a minimal "Hello world" program:

package hello_world

import k2 "karl2d"
import "core:log"

main :: proc() {
	context.logger = log.create_console_logger()
	k2.init(1920, 1080, "Hellope!")

	for !k2.shutdown_wanted() {
		k2.new_frame()
		k2.process_events()
		k2.clear(k2.LIGHT_BLUE)
		k2.draw_text("Hellope!", {10, 10}, 100, k2.BLACK)
		k2.present()
		free_all(context.temp_allocator)
	}

	k2.shutdown()
}

See the examples folder for a wide variety of example programs.

Some examples are available as live web builds: box2d, fonts, gamepad, minimal, mouse, render_texture, snake.

Discuss and get help in the #karl2d channel on my Discord server.

FIRST BETA

Karl2D is currently in its FIRST BETA period. This first beta has these features:

  • Rendering of shapes, textures and text with automatic batching
  • Support for shaders and cameras
  • Windows support (D3D11 and OpenGL)
  • Web support (WebGL, no emscripten needed!)
  • Input: Mouse, keyboard, gamepad

[!WARNING] This first beta does NOT have the following features, but they are planned in the order stated:

  • Linux
  • Sound
  • System for cross-compiling shaders between different backends (HLSL, GLSL etc)
  • Mac (metal)

Feedback wanted

Here are some things I want to get feedback on during this first beta:

  • Is the k2.new_frame() concept OK? It sets the "frame time" and clears some frame-specific state. I was thinking of merging new_frame() and process_events(), but something tells me that some people may want to move their event processing around. Initially I was toying with the idea to have the user use core:time and figure out dt etc themselves, but that was not good for first-user experience.

  • How do people think that DPI scaling should work? I've had bad experiences with high DPI mode Raylib. So I've gone for an idea where you always get everything in native coords and then you scale yourself using the number returned by k2.get_window_scale()

  • Because of how web builds need init and step to be split up, I also split the examples up this way, so we can use them both on desktop and on web. This sometimes made them a bit more chatty. For example, I had to move some variables to the global scope. Should I approach this differently?

  • Is it annoying that the documentation file karl2d.doc.odin has a real .odin file extension? I like that it gets syntax highlight for everyone etc. But it can also be a bit disruptive it "go to symbol" etc. Perhaps I should chance it to .odin_doc or something.

Join my Discord server and let me know in the #karl2d channel what you think! Here's the invite: https://discord.gg/4FsHgtBmFK

How to make a web build of your game

There's a build script located in the build_web folder. Run it like this:

odin run build_web -- your_game_path

The web build will end up in your_game_path/bin/web.

[!NOTE] On Linux / Mac you may need to install some lld package that contains the wasm-ld linker. It's included with Odin on Windows.

It requires that you game contains a init procedure and a step procedure. The init procedure is called once on startup and the step procedure will be called every frame of your game.

Also, see the minimal_web example: https://github.com/karl-zylinski/karl2d/blob/master/examples/minimal_web/minimal_web.odin

The build_web tool will copy odin.js file from <odin>/core/sys/wasm/js/odin.js into the bin/web folder. It will also copy a HTML index file into that folder.

It will also create a build/web folder. That's the package it actually builds. It contains a bit of wrapper code that then calls the init and step functions of your game. The result of building the wrapper (and your game) is a main.wasm file that also ends up in bin/web.

Launch your game by opening bin/web/index.html in a browser.

[!NOTE] To get better in-browser debug symbols, you can add -debug when running the build_web script: odin run build_web -- your_game_path -debug Note that it comes after the --: That's the flags that get sent on to the build_web program! There are also -o:speed/size flags to turn on optimization.

[!WARNING] If you open the index.html file and see nothing, then there might be an error about "cross site policy" stuff in the browser's console. In that case you can use python to run a local web-server and access the web build through it. Run python -m http.server in the bin/web folder and then navigate to https://localhost:8000.

Architecture notes

The platform-independent parts and the API lives in karl2d.odin

karl2d.odin in turn has a window interface and a rendering backend.

The window interface depends on the operating system. I do not use anything like GLFW in order to abstract away window creation and event handling. Less libraries between you and the OS, less trouble when shipping!

The rendering backend tells Karl2D how to talk to the GPU. I currently support three rendering APIs: D3D11, OpenGL and WebGL. On some platforms you have multiple choices, for exmaple on Windows you can use both D3D11 and OpenGL.

The platform independent code in karl2d.odin creates a list of vertices for each batch it needs to render. That's done independently of the rendering backend. The backend is just fed that list, along with information about what shader and such to use.

The web builds do not need emscripten, instead I've written a WebGL backend and make use of the official Odin JS runtime. This makes building for the web easier and less error-prone.

Is this a Raylib clone?

The API was originally based on Raylib API, because I like that API. But I have changed things I don't like about Raylib and made the API more Odin-friendly. The implementation is meant to have as few dependencies as possible (mostly core libs and some libraries from vendor). The web builds do not need emscripten, it uses Odin's js_wasm32 target.

Since I have shipped an actual game using Odin + Raylib, I am in a good position to know what worked well and what worked less well. I have tried to put that experience into this library.

Have fun!

Logo by chris_php