Compare commits
2
Commits
7e909ac7eb
...
65382a1663
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65382a1663 | ||
|
|
985f6e2fee |
@@ -0,0 +1,74 @@
|
|||||||
|
# Dangerzone
|
||||||
|
|
||||||
|
## A tiny game engine / software renderer using SDL for framebuffer visualization
|
||||||
|
|
||||||
|
#### Features
|
||||||
|
|
||||||
|
1. Put Pixel
|
||||||
|
|
||||||
|
```
|
||||||
|
void put_pixel(unsigned int x, unsigned int y, uint32_t color);
|
||||||
|
```
|
||||||
|
|
||||||
|
- Lets you color one given pixel in the framebuffer.
|
||||||
|
|
||||||
|
2. Clear Framebuffer
|
||||||
|
|
||||||
|
```
|
||||||
|
void clear_framebuffer(uint32_t color);
|
||||||
|
```
|
||||||
|
|
||||||
|
- Lets you fill the entire framebuffer with one color.
|
||||||
|
|
||||||
|
#### Usage
|
||||||
|
|
||||||
|
The main function of a program that uses this engine should look something like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
int main() {
|
||||||
|
// initialize the engine
|
||||||
|
if (engine_init(
|
||||||
|
client_poll_event,
|
||||||
|
client_update_framebuffer
|
||||||
|
)) {
|
||||||
|
// start the main game loop
|
||||||
|
engine_start();
|
||||||
|
// once the engine finishes, end gracefully
|
||||||
|
engine_stop();
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `client_poll_event()` and `client_update_framebuffer()` are two special functions that let you poll events and update the framebuffer respectively. (Shocking, I know.) You are supposed to define them yourself and pass them as function pointers to `engine_init()`.
|
||||||
|
|
||||||
|
Polling events allows you to handle mouse clicks, keyboard key presses, quitting the program and so on.
|
||||||
|
|
||||||
|
Updating the framebuffer means changing color values in the respective struct and thus getting an image on the screen.
|
||||||
|
|
||||||
|
An excerpt from the main game loop is below:
|
||||||
|
|
||||||
|
```
|
||||||
|
...
|
||||||
|
|
||||||
|
// main game loop
|
||||||
|
while(game_state->is_running) {
|
||||||
|
uint64_t start = SDL_GetPerformanceCounter();
|
||||||
|
|
||||||
|
// poll events
|
||||||
|
while (SDL_PollEvent(&game_state->event)) {
|
||||||
|
internal_state->engine_poll_events();
|
||||||
|
}
|
||||||
|
|
||||||
|
// call the user-defined framebuffer manipulation function
|
||||||
|
internal_state->engine_update_framebuffer();
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to modify the values for things like the window size or window name, (for now) go into `src/engine/engine.h` and change them there on the `#define` lines.
|
||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#define WINDOW_WIDTH 1280
|
#define WINDOW_WIDTH 1280
|
||||||
#define WINDOW_HEIGHT 720
|
#define WINDOW_HEIGHT 720
|
||||||
#define DEFAULT_WINDOW_NAME "SDL Playground"
|
#define DEFAULT_WINDOW_NAME "Dangerzone"
|
||||||
#define WINDOW_NAME_LENGTH 128
|
#define WINDOW_NAME_LENGTH 128
|
||||||
#define TARGET_FRAME 1.0 / 60.0
|
#define TARGET_FRAME 1.0 / 60.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user