26
votes
Accepted
Consistent cross platform procedural generation
The best resource I've found on this topic is Bruce Dawson's blog article "Floating-Point Determinism"
It establishes that yes, in theory, you could get cross-platform determinism out of ...
24
votes
Accepted
Convert integer to float while also dividing down the scale, without data loss
I think you're making this too complicated. The trick to preserving precision in your floating point numbers is just to keep their magnitude small. No chaining through doubles or two-stage fractional/...
11
votes
Accepted
How could I implement an ECS in C?
As a pattern ECS and data oriented programming in general are closer to pure C than C++.
Entity component systems consist of three major elements.
Components are simply holding data; they shouldn't ...
7
votes
Accepted
Handling variable frame rate in SDL2
The most consistent way to do this is to use a fixed time step for your game logic. This avoids game logic oddities due to rounding errors when frame rate changes (collisions or events that don't ...
7
votes
Accepted
Key released, multiple Keys, how to go around ncurses limitations?
For future readers, here is what I did in order to handle multi key inputs with ncurses :
I realized you can call getch() multiple times during a frame, and it ...
7
votes
Consistent cross platform procedural generation
What I would be trying to do is to generate on multiple levels, where things at one level could be calculated from the level above with integer math.
For example, at the top level I might draw a bunch ...
6
votes
Accepted
How to pass PNG image data directly to SDL?
SDL uses a type called SDL_RWops for this purpose. This is essentially a wrapper around a stream. When you call a function like ...
6
votes
Accepted
How should I store loaded world chunks in RAM (For my game similar to Minecraft)?
If you don't want a 2d array of chunks indexed by world position because the player might get very far away from the world origin or you might have negative indexes, then it might be worth to look at ...
5
votes
Why am I getting these errors when including stb_image.h?
From the stb_image.h file itself:
Do this:
#define STB_IMAGE_IMPLEMENTATION before you include this file in one C or C++ file to create the implementation.
You must not ...
5
votes
Convert integer to float while also dividing down the scale, without data loss
In a comment I mentioned in passing that you could switch to representing 1024ths of meters instead of millimeters. That also helps with representability generally. Your code would look like this:
<...
5
votes
Accepted
How to install game with dependencies on Linux?
Standalone game
For Linux, SDL suggests to download the source code, compile it, and include the relevant files as part of your game.
The main information can be found on the official site SDL2 - ...
4
votes
Drawing at floating point position
There's a simple way to render a rectangle with floating point coordinates but for some reason it's documentation is not available on the wiki. A commit was done to add this feature on October 22, ...
4
votes
Drawing at floating point position
Maybe this answer will not suit your question, but I assume that you want to have float movement precision even when SDL rectangles support only integer values.
One of the tricks you can do is to ...
3
votes
C/C++ Flexible yet fast way of linking UI elements to functions
First off, your part about avoiding pointers and virtual functions due to responsiveness of button clicks is terribly misguided - you listened to someone you should not have listened to. If we're ...
3
votes
SDL_RenderPresent is writing over the previous frame
To get past this, you might be able to use a texture buffer which you render to before rendering to the window. This is accomplished with creating a texture with ...
3
votes
Accepted
What do I provide to SDL_LockTexture **pixels?
void **pixels is a pointer-to-a-pointer; these are typically used (in this kind of context) where the data is of a pointer type but memory management is handled by ...
3
votes
One global game loop vs multiple local game loops
The cost of rewriting your loop is not worth any perceived benefits of having "more efficient" loops that leave out unneeded bits.
This is "premature optimization". I would not ...
Almo♦
- 6,708
3
votes
SDL2 memory leak
The problem is that you're calling TTF_OpenFont every frame, and you only need to load a font once. TTF_OpenFont is a very ...
3
votes
Accepted
Strange flashing cube bug in snake game
When your "snake eats apple" code block is executed, you increment the snake snake size, but it doesn't look like you're initializing the location for the new snake segment. The flash looks ...
2
votes
SDL Player do something for 3 seconds then stop
Given that you are working with SDL2, SDL_GetTicks() is the most straightforward solution. SDL_AddTimer is also an option, but ...
2
votes
OpenGL Perspective Issue
This was caused by an uninitialized variable being fed into the projection function:
...
2
votes
C/C++ Flexible yet fast way of linking UI elements to functions
What C++ standard are you writing against? C++ 11 Introduced support for Lambdas, which are basically unnamed functions that can "capture" variables.
So you could just define a Lambda instead of your ...
2
votes
Accepted
Setting a uniform float in a fragment shader results in strange values, is this a type conversion? How can it be fixed?
You can try solving the issue by using glUniform1fv(uniFactor, 1, &factorToSet);
instead of glUniform1f as this has worked ...
2
votes
Accepted
How to handle Japanese on Windows and Linux using SDL_ttf and C++?
I'm an idiot.
In C++, the compiler knows what a u8"" string literal is, and will convert that string literal appropriately to an UTF-8 compatible string.
And ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c × 278c++ × 82
opengl × 67
sdl × 42
sdl2 × 28
game-loop × 10
collision-detection × 9
2d × 8
mathematics × 8
rotation × 8
networking × 8
linux × 8
3d × 7
game-design × 7
textures × 7
directx × 7
glsl × 7
algorithm × 6
graphics × 6
software-engineering × 6
rendering × 5
matrix × 5
graphics-programming × 5
sfml × 5
windows × 5