Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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 ...
DMGregory's user avatar
  • 135k
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/...
DMGregory's user avatar
  • 135k
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 ...
Exaila's user avatar
  • 687
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 ...
realUser404's user avatar
  • 1,057
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 ...
Stephane Hockenhull's user avatar
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 ...
James Hollis's user avatar
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 ...
Sean Middleditch's user avatar
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 ...
Philipp's user avatar
  • 120k
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 ...
Stephane Hockenhull's user avatar
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: <...
Steve Cox's user avatar
  • 151
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 - ...
Tom Tsagkatos's user avatar
4 votes
Accepted

Having issue's with a confusing access violation? - C , OpenGL 3.3+ , SDL 2.0+

void glShaderSource(GLuint shader, GLsizei count, const GLchar **string, const GLint *length); Okay, I guess you didn't understand what these values ...
Antoine Morrier's user avatar
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, ...
tripulse's user avatar
  • 140
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 ...
Pins's user avatar
  • 569
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 ...
Peter's user avatar
  • 9,925
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 ...
Ray C's user avatar
  • 273
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 ...
Maximus Minimus's user avatar
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's user avatar
  • 6,678
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 ...
Sciborg's user avatar
  • 594
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 ...
Pikalek's user avatar
  • 12.4k
2 votes

OpenGL Perspective Issue

This was caused by an uninitialized variable being fed into the projection function: ...
Brian's user avatar
  • 151
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 ...
TOM__'s user avatar
  • 96
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 ...
uliwitness's user avatar
  • 1,217

Only top scored, non community-wiki answers of a minimum length are eligible