[Simple DirectMedia Layer 2](https://www.libsdl.org/) (SDL2) is designed to provide platform independent access to various common multimedia devices. It is the new, current and updated version of SDL and recommended for new projects over legacy SDL1.2

learn more… | top users | synonyms

1
vote
0answers
15 views

Prevent rendering queue from overflowing when using Vsync

My game loop currently looks something like this: while (!quit) { takeInput(); // Input is sampled however fast loop can run time_now = get_time() time_passed += (time_now - time_prev); ...
3
votes
1answer
36 views

How to pass PNG image data directly to SDL?

Well passing just external PNG to SDL is very easy with the SDL_image library. I have a class that does just that. The code looks like the following: SDL_Surface* Texture::LoadImg(const char *...
0
votes
0answers
21 views

Is there a library to easily implement a gui into a OpenGL application (SDL)? [on hold]

I'm writing a basic OpenGL built on SDL2 application to build up my skills. I would like to implement a gui (buttons, widgets and layouts, etc) to my game, but I don't want to have to write it all. My ...
1
vote
2answers
67 views

How should I use this 1D perlin noise function?

I'm trying to create a terraria like terrain with SDL2 and C++. For generating the terrain I'm trying to use the 1D noise function from here: https://github.com/SRombauts/SimplexNoise It's pretty ...
1
vote
0answers
32 views

2D Voxel isometric rendering with non grid-aligned objects

I'm currently working on making a simple SDL2 game (written in C++) where the maps are comprised of sprite voxels (essentially just a png of an isometric cube). Game entities move in 3D space. The ...
0
votes
1answer
32 views

C & SDL: Unexpected Behaviour with Renderer

I'm creating a clone of the memory testing game SIMON. My program is simply four differently colored squares that light up one at a time in a random order. I wrote some code that lights up one square, ...
0
votes
1answer
27 views

Fast texture pixel access using SDL2

People have asked questions on fast pixel manipulation, but I'm looking to read the RGB color values of each pixel. I've heard of SDL_RenderReadPixels but in the docs it says: WARNING: This is a ...
1
vote
1answer
39 views

How do I perform an Iris Wipe transition, using C++ in SDL 2.0?

How do I perform image masking/clipping using an arbitrary shape like a circle? I want to do an Iris Wipe transition, similar to in the movies. By Iris transition, I mean the circle transition ...
-1
votes
1answer
47 views

Rendering with sdl_gfx is so slow, any alternative?

I have been using sdl_gfx ( sdl2 extension library https://github.com/ferzkopp/SDL_gfx ) to make Android games, I have always noticed that rendering primitives is so slow. So I was rendering it once ...
1
vote
0answers
28 views

Get modified key with SDL2

If I poll keyboard events with SDL2 all I get is the pressed key and the modifiers. But I am using Neo and have some keys like Esc and arrow keys on a different layer which means that e.g. Mod4+i is ...
0
votes
1answer
19 views

How to get rid of an image upon collision detection in SDL?

I am fairly new to SDL in C, but I have written a simple game whereby a character has to reach the end of a level and avoid bad stars on the way. If he hits a star, he dies. There are also good stars ...
0
votes
1answer
24 views

Using an SDL_Renderer within a texture wrapper class in SDL2

I have a CTexture class which needs a renderer to create and show textures. I don't know the scope I should put the renderer in. I´ve got it to work as a global variable, but I don't know if it´s a ...
1
vote
1answer
40 views

Premake a texture in SDL (C++) and save it

I am new with SDL, and am making a Conway Game of Life. I want to make a grid appear on the screen, so of course I could make one manually with SDL_RenderDrawLine and two loops. But I don't want to ...
0
votes
0answers
92 views

C++ - Is this a good way to handle GUI events?

I am developing a UI framework for my game (SDL2, C++). I have a ScreenManager class which manages a list of UI widgets on the screen (text, buttons, etc.). The function below builds the main menu ...
3
votes
2answers
293 views

Smooth character movement

I want my character to move smooth not instant stopping etc. I want it to decrease velocity slower not instant. I tried with keystates but that doesn't work for 2 keys at once. I tried using key....
1
vote
1answer
127 views

How to stop SDL from freezing the rendering while resizing the window?

I have a simple SDL application with a re-sizeable window. If I minimize it and then maximize the window the rendering freezes. I've included a simple code example below which makes the screen flash ...
1
vote
1answer
61 views

How to handle different resolutions in SDL2?

What is the easiest way to set different resolutions with SDL2? I was trying to use the SDL_RenderSetScale() function first, but for some reason it alters the physics of the game (jumps are higher or ...
3
votes
1answer
55 views

Can I offset all rendering in SDL2?

I know about SDL_RenderSetScale, but I need also horizontal/vertical shift of the renderer's origin. At the moment, I manually modify positions of all screen objects with the shift. Is there a way to ...
0
votes
1answer
134 views

Is 3d game development advantageous/possible in SDL2? [duplicate]

I think this is not appropriate, but as the given video in the link, the youtuber name Bisqwit creates his own 3d engine from scratch in C and SDL2. How much is this advantageous is real 3d game ...
4
votes
1answer
71 views

How do I create 4 rows of SDL_Rects with each row being a different color?

So using a class i've created a vector and managed to make one row of SDL_rects(with collision detection and destroy on collision). But when I make a second row(and obviously 2 or more rows): 1) it ...
1
vote
1answer
57 views

SDL2: Texture not rendering to screen

I'm trying to render a BMP image, but nothing is showing up other than the draw color. I have most of my code in a header file. [game.h] #ifndef __Game__ #define __Game__ #include <string> #...
-1
votes
1answer
51 views

SDL2 graphics will draw in main process but not in separate thread

I'm having an issue that I'm absolutely stuck on and my ability to debug this issue has been exhausted. I am implementing a base for a 2D game where I am handling my keyboard input, logic, and ...
0
votes
1answer
48 views

SDL2 in a VS2015/C++ panel

I'm trying to use SDL2 in a panel (VS2015/C++) and cannot find solid examples of how to connect the two. Anyone know how this is done? I've tried some code found in various places, but no luck yet. ...
4
votes
1answer
131 views

How can I resize SDL2 windows efficiently?

I guess resizable windows are not being optimized for in game development but still... The following piece of code demonstrates a problem I'm having: resizing the window is very slow. Basically the ...
2
votes
1answer
113 views

Monitor external window events with SDL2

I'm trying to render my game (SDL2, C++) in a Windows Form application (C#) using C++/CLI to interface with my underlying C++ code. The purpose of the form is to create an editor which can monitor/...
0
votes
0answers
21 views

rendering moving terrain using midpoint displacement algorithm in sdl

This is in addition to the question I asked over here. midpoint displacement algorithm in sdl. The answer there helped me but I am facing another problem regarding the moving part. The terrain ...
1
vote
1answer
55 views

midpoint displacement algorithm in sdl

I am trying to implement moving random hills in SDL. I am using midpoint displacement algorithm to create some random terrain and I have also accomplished to move the terrain too. But the problem is ...
1
vote
2answers
88 views

Bullets Stop Working Error

I've made a vector which is used by a universally accessible namespace called 'BULLET_HANDLER'. This vector stores and updates all bullets that are produced from the 'shootBullet' function. The ...
11
votes
2answers
1k views

Removing delay at start of a key press

I'm making a simple game, and one of the problems I encountered is the annoying delay when pressing a key continuously. So basically, when I press (for a very long time) for example Up, my object ...
1
vote
1answer
95 views

glGenBuffers is NULL

I'm using GLEW 1.13.0, (GLUT), SDL2 and OpenGL 3.3 core. #include <GL/glew.h> #include <GL/glut.h> int main(int argc, char* args[]){ Engine::init(); // Initializes SDL_GL_* attributes ...
0
votes
0answers
44 views

Can't alt tab back to SDL2 window with SDL_WINDOW_FULLSCREEN_DESKTOP flag set in Ubuntu

Good evening. I'm trying to build a fullscreen borderless game to run on Ubuntu using SDL2. I'm currently at a loss as to why I can't ALT+TAB back into my SDL2 program after I switch out of it. The ...
2
votes
2answers
85 views

Input before or after update/draw?

This is how I understood the game loop, and I wanted to know if I'm correct or not: 1) Draw/render -> input CPU | GPU ------------------ Update | Draw | Input | Rendering 2) Input -> ...
0
votes
2answers
213 views

How to use the SDL viewport properly?

I'm very confused about the SDL2 viewport, I did some googling to find out how to implement it but people keep mentioning things like "world coordinates" which I don't have in my game. Question : Do ...
1
vote
0answers
133 views

How to draw 2D pixel data with OpenGL

I am fairly new to OpenGL. I have a 2D game in SDL2 that uses currently works by creating a SDL_Surface from the pixel data, copying it into a SDL_Texture, and rendering it to the screen with ...
1
vote
1answer
137 views

SDL2 linux fullscreen issue at lower-than-desktop resolution

Having a problem trying to get proper fullscreen in linux. I'm using 1440x900 on desktop. When i set SDL to use 1280x720 as fullscreen, it does change screen resolution. But if i drag the mouse ...
1
vote
1answer
67 views

SDL2 SDL_PollEvent endless polling on key hold

What is wrong with SDL2 SDL_PollEvent() function? When I press-and-hold a key it enters "while (SDL_PollEvent())" block each frame. If in previous frame event queue was emptied and in new frame I ...
1
vote
1answer
106 views

Is it possible to create a homemade depth buffer?

Studying the case of isometric rendering, I'm facing a big and well-known problem : depth sorting. After many researches it seems that without tile mapping or 'height-leveling' it's impossible to ...
0
votes
1answer
60 views

SDL Key Input previous and current key states not working as expected, how to fix?

Here is my code that's part of the main game loop: // ResetKeyState stores currentKeyState in previousKeyState // and then clears currentKeyState engine.ResetKeyState(); // Fill ...
0
votes
1answer
20 views

Efficiently blit texture rotated by 90° to renderer with SDL 2

Let's say I have a 1024x768 SDL_Window, an SDL_Renderer bound to that window and a 768x1024 SDL_Texture into which I do my rendering. How can I render that texture such that it is rotated by 90° to ...
0
votes
1answer
88 views

Player position not updating when referenced in seperate class?

In my player class I have my players position set to update when you tap the directional keys, that works fine, but when I access my Players position variables, in my projectile class constructor, ...
0
votes
1answer
51 views

Unable to load two enemies with same pic in sdl2

I have loaded two enemies(with the same pic) into my game. However, when I draw them onto the screen it only draws and animates one enemy, instead of two. I can't seem to figure this out. Here is my ...
1
vote
3answers
171 views

How can I represent a tile-based map and related properties on disk?

I'm trying to load a tile-based map in my game. I've been watching SDL tutorials for a while now but they never covered how to represent the map in a file? How can I represent a tile map on-disk in a ...
0
votes
3answers
161 views

How to “reload” a TTF Text during runtime?

As the title says I would like to know how to reload a TTF_SDL Text during runtime in C++. What I want to do is to update all the values of the text each frame so I can, to example change the font ...
0
votes
0answers
33 views

Should all textures be power of 2 in SDL2? [duplicate]

I come from Gamemaker background, and I know that anything you give Gamemaker is put onto a texture page that is power of 2 size, but I am now making an SDL game engine and I am wondering, should all ...
0
votes
1answer
54 views

How to convert font size to pixels?

I'm trying to add text to my game using SDL_TTF, and it's working pretty well. Except for one thing : My text's SDL_Surface needs a width and a height, if I don't give it one it will automatically ...
0
votes
2answers
121 views

DeltaTime won't create smooth movement

The problem : I tried adding deltaTime into my game, which seems to not be working when I try to smoothly move a object in my game. How I calculate delta time : Delta Time variables : float ...
0
votes
1answer
84 views

My Sprite class generates a EXC_BAD_ACCESS error, and is sometimes NULL? Rect has weird values?

So, lets start off with the weird Sprite* object sometimes being NULL. I run my game, the EXC_BAD_ACCESS error comes and sometimes, only sometimes my Sprite* has a value when it crashes. Sometimes ...
0
votes
0answers
137 views

Filling polygons with texture/color using SDL2

I recently went on to making a 3D software renderer using SDL2 and Rust as a learning project. It has been going quite well, it can draw lines, polygons, and cubes. Now, it can only display ...
0
votes
1answer
201 views

Why does SDL render the background from the operating system to the window?

My code displays a fully transparent window that copies the background from the operating system. This is the code I use for rendering: void render() { SDL_RenderClear(renderer); ...
2
votes
2answers
243 views

Example/Tutorial of passing structured data over network C++

This is very general question, about strategies how to pack same informations about state of my game-world on server ( e.g. position/orientation of players, projectiles, etc. ) into data stream so ...