|
| 1 | +# FAQ |
| 2 | + |
| 3 | +## General |
| 4 | + |
| 5 | +### Will Tetra be written in pure Rust eventually? |
| 6 | + |
| 7 | +Probably not - SDL2 is a stable and well-tested foundation for building games, and it runs on basically every platform under the sun, so I'm hesitant to replace it. That's likely to remain the only non-Rust dependency, however. |
| 8 | + |
| 9 | +If you're looking for a similar engine that _is_ pure Rust, [GGEZ](https://github.com/ggez/ggez) and [Macroquad](https://github.com/not-fl3/macroquad) are good options. |
| 10 | + |
| 11 | +### Do I have to install SDL manually? |
| 12 | + |
| 13 | +It's possible to have your project automatically compile SDL2 from source as part of the build process. To do so, specify your dependency on Tetra like this: |
| 14 | + |
| 15 | +```toml |
| 16 | +[dependencies.tetra] |
| 17 | +version = "0.7" |
| 18 | +features = ["sdl2_bundled"] |
| 19 | +``` |
| 20 | + |
| 21 | +This is more convienent, but does however require you to have various build tools installed on your machine (e.g. a C compiler, CMake, etc). In particular, this can be a pain on Windows - hence why it's not the default! |
| 22 | + |
| 23 | +### Can I static link SDL? |
| 24 | + |
| 25 | +If you want to avoid your users having to install SDL2 themselves (or you having to distribute it as a DLL), you can specify for it to be statically linked: |
| 26 | + |
| 27 | +```toml |
| 28 | +[dependencies.tetra] |
| 29 | +version = "0.7" |
| 30 | +features = ["sdl2_static_link"] |
| 31 | +``` |
| 32 | + |
| 33 | +This comes with some trade-offs, however - make sure you read [this document](https://hg.libsdl.org/SDL/file/default/docs/README-dynapi.md) in the SDL2 repository so that you understand what you're doing! |
| 34 | + |
| 35 | +## Graphics |
| 36 | + |
| 37 | +### Why am I getting a black screen? |
| 38 | + |
| 39 | +Tetra currently targets OpenGL 3.2, so if your hardware does not support this, you might have trouble running games written with the framework. You can check your version of OpenGL by enabling Tetra's debug output - add `.debug_info(true)` to your `ContextBuilder`, run your game, and then look at the console. |
| 40 | + |
| 41 | +If your OpenGL version is 3.2 or higher and you're still getting a black screen, that may indicate a bug - I currently only have access to a Windows machine with a reasonably modern graphics card, so it's not outside the realms of possibility that something that works for me might be broken for others! Please submit an issue, and I'll try to fix it and release a patch version. |
| 42 | + |
| 43 | +### Does Tetra support drawing custom meshes? |
| 44 | + |
| 45 | +Yes - the `Mesh` API has been available since 0.5.4. |
| 46 | + |
| 47 | +### Does Tetra support drawing primitive shapes? |
| 48 | + |
| 49 | +Yes - since 0.5.8, `Mesh` has constructors for basic shapes and there is a `GeometryBuilder` type that can be used to build more complex shapes without manipulating raw vertex data. For more complex/custom use cases, the third party [`lyon`](https://github.com/nical/lyon) crate can be used to generate vertex data. |
| 50 | + |
| 51 | +Note that primitive shape drawing currently isn't batched, so drawing too many generated shapes at once may be slow. |
| 52 | + |
| 53 | +If that's all too complicated and you just want to draw simple rectangles, you could also [create a solid colored `Texture`](https://docs.rs/tetra/0.7.0/tetra/graphics/struct.Texture.html#method.from_data) and then draw that. If you create a 1x1 solid white texture, you can use the `scale` and `color` `DrawParams` to draw multiple rectangles of varying sizes/colors/transparencies in a single draw call. |
| 54 | + |
| 55 | +### Does Tetra support high-DPI rendering? |
| 56 | + |
| 57 | +Tetra added basic support for high-DPI rendering in 0.5.4, which can be enabled via [`ContextBuilder::high_dpi`](https://docs.rs/tetra/0.7/tetra/struct.ContextBuilder.html#method.high_dpi). You may also need some platform-specific configuration/packaging - see the docs for `ContextBuilder::high_dpi` for more info. |
| 58 | + |
| 59 | +## Performance |
| 60 | + |
| 61 | +### Why is my game running slow? |
| 62 | + |
| 63 | +Cargo builds projects in debug mode by default. This can lead to your game running slowly, as the compiler does not fully optimize your code. |
| 64 | + |
| 65 | +Optimizations can be enabled by passing `--release` when building/running your project, but this increases build times quite significantly and removes debug info from the binary, meaning you cannot easily debug or profile your code. |
| 66 | + |
| 67 | +To work around this, add one of the following snippets to your `Cargo.toml`: |
| 68 | + |
| 69 | +```toml |
| 70 | +# To enable optimizations in debug mode for Tetra only (requires Rust 1.41): |
| 71 | +[profile.dev.package.tetra] |
| 72 | +opt-level = 3 |
| 73 | + |
| 74 | +# To enable optimizations in debug mode for all dependencies (requires Rust 1.41): |
| 75 | +[profile.dev.package."*"] |
| 76 | +opt-level = 3 |
| 77 | + |
| 78 | +# To enable optimizations in debug mode for the entire project (works with all Rust versions): |
| 79 | +[profile.dev] |
| 80 | +opt-level = 3 |
| 81 | +``` |
| 82 | + |
| 83 | +Choosing one of the first two options is preferred, as they will not slow down rebuilds of your game's code. |
| 84 | + |
| 85 | +You should also make sure to build with `--release` when distributing your game, so that the final binary is as fast as possible. |
| 86 | + |
| 87 | +#### Benchmarks |
| 88 | + |
| 89 | +The impact of compiler optimizations can be observed by running the `bunnymark` example both with and without the `--release` flag. This example adds 100 new sprites to the screen every time the user clicks, until rendering conistently drops below 60fps. |
| 90 | + |
| 91 | +These were the results when I ran it against Tetra 0.2.9 on my local machine: |
| 92 | + |
| 93 | +| Configuration | Bunnies Rendered | |
| 94 | +| ------------- | ---------------- | |
| 95 | +| Debug | 3200 | |
| 96 | +| Release | 230000 | |
| 97 | + |
| 98 | +For reference, my system specs are: |
| 99 | + |
| 100 | +- CPU: AMD Ryzen 5 1600 3.2GHz |
| 101 | +- GPU: NVidia GeForce GTX 1050 Ti |
| 102 | +- RAM: 8GB DDR4 |
| 103 | + |
| 104 | +## Miscellaneous |
| 105 | + |
| 106 | +### Why is it called Tetra? |
| 107 | + |
| 108 | +I'm terrible at naming projects, and [this](https://www.youtube.com/watch?v=g3xg28yaZ5E) happened to be playing when I was typing `cargo new`. I wish there was a better origin story than that :D |
0 commit comments