

- HOW TO CREATE YOUR OWN GAME RUST HOW TO
- HOW TO CREATE YOUR OWN GAME RUST INSTALL
- HOW TO CREATE YOUR OWN GAME RUST CODE
The screen can also store other properties we might want to clear, but that's not relevant here. Gl.COLOR_BUFFER_BIT says that we want to clear only the screen's color.

Each number in the arguments represents the amount of red, green, blue, and alpha (also known as transparency) respectively. Gl.clearColor sets the color to fill the screen. The gl.viewport tells WebGL to render to the entire canvas. We immediately resize the canvas to have the same number of pixels as the space it takes up within the HTML. What we're doing here is getting the canvas and taking the gl handle that lets us use WebGL functions for drawing to the canvas.
HOW TO CREATE YOUR OWN GAME RUST CODE
This tutorial won't focus too heavily on Open/WebGL as there are already great tutorials that teach them.Īdd the following code above the imports in your index.html file: We're using WebGL instead of simpler web-specific APIs because our WebGL code is similar to OpenGL code we could write on non-web platforms. WebGL is basically OpenGL and both WebGL and OpenGL can feel a bit antiquated and finicky if you aren't familar with them.
HOW TO CREATE YOUR OWN GAME RUST HOW TO
After we will figure out how to connect it to Rust. Let's add our engine's first feature and make the screen a different color!įirst let's just make the screen red on the Javascript side. Sadly communicating with Javascript is inherently unsafe. Rust is very cautious that way and if you stick to Rust without unsafe you'll create fewer weird bugs.

In game.rs let's write the classic "Hello World" code: fn main () because Rust rightfully makes us acknowledge that we're doing something unsafe. In your game engine folder create a folder named examples and add an example file named game.rs. As we develop our engine we'll repeatedly run this example game as a test. Let's also create an examples folder for our library. We're creating a library (or a crate in Rust terminology) so we can use our game engine easily with multiple projects. It might be easiest if you call yours sprinkles too, but if you don't just replace the word sprinkles everywhere with your engine's name.Ĭreate a folder with your engine name, open that folder with a command line, and run cargo init -lib to initialize a Rust library project. I'm calling my engine "sprinkles" because it's the first thing that popped into my head.
HOW TO CREATE YOUR OWN GAME RUST INSTALL
Setupįirst off install Rust if you don't already have it installed. If ever you get stuck consult the GitHub repository to figure out what's different. This tutorial has lots of steps but they're individually simple. If ever you get lost or just want to skip ahead the final code is here: This tutorial is written to be legible for a Rust beginner and skimmable for a Rust expert. To follow along you should already know the basics of programming. This tutorial includes some Javascript and web code, but the general ideas apply to non-web as well. If you aren't familiar with Rust it's a relatively new programming language that runs fast and helps you write better code. It will compile near-instantly (less than a second on my computer) and be about 130 lines of code total.

Our engine will use no code other than Rust's standard library and the APIs the browser provides us. Our game engine will respond to key presses, draw rectangles, and define a structure that could accomodate a larger engine. In this tutorial we'll use the Rust programming language to code a tiny game engine. Tutorial: Writing a Tiny Rust Game Engine for Web
