Skip to main content
11 votes
Accepted

How to use the SDL viewport properly?

My guess is you're trying to implement a camera, and should not be using SDL Viewports. The viewports are for UI elements like menus, minimaps, etc. It's a way of dividing up the screen into multiple ...
amitp's user avatar
  • 6,046
10 votes
Accepted

Proper names and wordings for Real/Fake fullscreen video modes

From the SDL Docs: SDL_WINDOW_FULLSCREEN_DESKTOP for "fake" fullscreen that takes the size of the desktop This sounds like what other games call Borderless Mode, Borderless Windowed Mode, or ...
tkausl's user avatar
  • 1,860
7 votes
Accepted

Is 3d game development advantageous/possible in SDL2?

Your question needs re-phrasing. SDL and OPENGL are two different technologies so to speak. Also, this question will lead to opinions instead of facts Wikipedia says: Simple DirectMedia Layer (SDL) ...
zimspy's user avatar
  • 347
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
Accepted

How can I avoid jittery motion in SDL2?

As Alexandre Vaillancourt in the comments suggested: it is caused by the conversion from float to int (rounding errors). It might also be caused by the fact that I used SDL_Delay() earlier to cap the ...
user9266's user avatar
  • 111
6 votes
Accepted

Smooth character movement

To create smooth movement you need 4 things: The position of the character The velocity of the character The acceleration of the character The max speed of the character When the user presses the ...
Bálint's user avatar
  • 14.9k
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

SDL2 C++ How to make enemy move in random directions

First of all, you don't have breaks in your switch statement, that means that if your random number is for example 1, after subtracting the speed value from the ...
Mario1159's user avatar
6 votes
Accepted

SDL2 - Why use `SDL_Window* win` and not `SDL_Window win`?

SDL_Window win; will not compile. SDL_Window is a so-called opaque struct. Somewhere in SDL headers, it's declared as ...
HolyBlackCat's user avatar
  • 2,035
5 votes

Fast texture pixel access using SDL2

SDL2's "texture" rendering API is designed for accelerated graphics in mind; this is where you upload textures to your graphics hardware beforehand, and then render that texture by referring to it. ...
congusbongus's user avatar
  • 14.8k
5 votes
Accepted

Is it a good idea to use per pixel collision detection in an isometric game?

The problem with per-pixel collision detection is that 1. it can be very slow and 2. your graphic design can have a lot more impact on your game mechanics than you would like. It is usually better to ...
Philipp's user avatar
  • 120k
5 votes
Accepted

SDL2 mouse motion event keeps occurring

You're not checking the return value of SDL_PollEvent to see if there's a new event, which means that regardless of whether there is an event to handle, you're ...
wizzwizz4's user avatar
  • 165
5 votes
Accepted

How to get the RGB color values of a clicked pixel on a rendered image in SDL2?

After much scouring the Internet, I discovered this forum post, containing the following code that completely solved my problem. I've abridged it slightly for easy copy-paste into your project. ...
Sciborg's user avatar
  • 594
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

How can I resize SDL2 windows efficiently?

First, on Linux it appears to matter what Window Manager and Compositor you are using. WindowMaker with opaque windows enabled (not the default) was still fast, the wire windows are always fast ...
orangetide's user avatar
4 votes

Bullets Stop Working Error

You're shooting yourself in the foot: ...
Vaillancourt's user avatar
  • 16.3k
4 votes
Accepted

SDL2 not setting OpenGL version?

Put your SDL_GL_SetAttribute() calls after SDL_Init().
HolyBlackCat's user avatar
  • 2,035
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
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

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