[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

0
votes
1answer
28 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
6 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
57 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
39 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
2answers
81 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
2answers
103 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
27 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
38 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
82 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 : ...
0
votes
1answer
44 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
43 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
66 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
101 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 ...
0
votes
1answer
23 views

Simulate Keyboard Button Press [SDL Library]

I am trying to simulate an SDL keyboard button press (using C). I have looked up the SDL info pages online but I still don't have anything that consistently works. I have the following (removed the ...
0
votes
1answer
90 views

Best way to structure SDL2/C++ game? [closed]

I was reading some SDL2 tutorials and I noticed that you need to pass your window surface handle to any drawRect calls. Should I create a global surface handle or pass the handle by reference into ...
0
votes
0answers
31 views

Implement camera in SDL

I'm trying to realize a simple camera in SDL which has its size and can be moved around. I have a vector of visible elements which will be drawn if the camera "sees" them. Now, I checked this answer ...
1
vote
1answer
58 views

SDL2 and frames per second

I'm diving into the world of SDL2 and C++ and have a few questions after my first few weeks in. Seems like a lot of the tutorials are (from what I understand) limiting the frames per second with a ...
1
vote
1answer
112 views

SDL2, OpenGL, Nvidia laptop screen tearing

EDIT 2016-03-06. Note 1: Apparently this is a known issue with Nvidia. If you've found here due to same problem, please stoke the collective "please fix it" by filing a "question" at ...
1
vote
1answer
22 views

Should I add error handling to SDL_GL_SetAttribute?

As the title says, I wonder if I should handle errors for : SDL_GL_SetAttribute Can it actually fail to set? And if it can, what could be a reason for it to fail?
0
votes
1answer
41 views

Creating texture and palette modification

I need to create a texture from a surface with indexed color palette and alter the colors. However, after I set new colors, the rendered texture gets blank. int main(int argc, char** argv) { ...
0
votes
0answers
26 views

Implementing multiple cameras for multiple objects

Now, I have a Camera, and whenever I need to render elements I call the render function on the element and pass a camera to it like this: elem.render(camera); // Renders only elem, using camera ...
0
votes
2answers
65 views

Why do SDL_Textures need to be created with a renderer?

I know how to create textures in SDL, but I don't get why they need to be created with a renderer: SDL_CreateTexture(SDL_Renderer* renderer, ...) When it comes to rendering, I can render my texture ...
1
vote
0answers
37 views

Awesomium custom surface scroll

I have a custom Awesomium::Surface implementation, and I need to create a Scroll function for it. The function asks me to manually move some pixels of my texture by the indicated X and Y offset. How ...
1
vote
2answers
73 views

SDL Convert pixel format

I have two pixes stored in a 32 bit unsigned integer (4 bytes per pixel, using SDL's types for convenience): Uint32 pixel1; // Source pixel, format: SDL_PIXELFORMAT_BGRA8888 Uint32 ...
2
votes
2answers
226 views

Create a new Surface type with SDL_Texture

So I started using Awesomium, and I'm experiencing some difficulties. I want to create a new type of Awesomium::Surface and implement it in my custom Awesomium::SurfaceFactory to render ...
3
votes
1answer
170 views

HTML UI with SDL2 [closed]

I realized that I need an HTML-like UI in my game, because by myself I wouldn't be able to achieve such effects (divs, text, coloring, and styling). So I started to look around for a HTML Engine for ...
1
vote
0answers
25 views

Can I use sdl_net2.0 with cocos2d-x? [closed]

Can I use sdl_net2.0 lib with cocos2d-x? And how it cconects to each other. Or analog lib to use?
3
votes
1answer
51 views

Will SDL_DestroyRenderer() destroy every texture created with it?

The documentation on the SDL wiki states: Use this function to destroy the rendering context for a window and free associated textures So does this mean that every texture I create will be freed ...
0
votes
3answers
173 views

Cannot load png images to textures with SDL2 in Visual Studio 2015

I'm learning SDL2 with Visual Studio 2015 and I'm trying to draw a 16x16 level with a .map file and 32x32 .png images for tiles (that's 256 tiles) on a 512x512 window. I have both SDL2 and SDL2 Image ...
2
votes
2answers
57 views

How can I update vSync settings after creating an SDL_Renderer?

I have an SDL_Renderer which I set to use or not use vSync depending on the user). In my options menu I have an option for enabling/disabling vSync. Can I edit my renderer to update the vSync ...
1
vote
1answer
94 views

OpenGL/SDL2 How to resize the render area with the window?

After calling SDL_SetWindowSize, the area being rendered to doesn't change with the window, so if the window gets bigger, it leaves a black area on the top and right sides. I am adjusting the OpenGL ...
0
votes
1answer
32 views

SDL Combining text and Geometry Rendering to one texture

Basically I'm trying to end up with a Texture class that can take in text and have it be drawn over simple geometry (such as a letter 'A' over a filled rectangle). However I'm running into issues when ...
0
votes
0answers
57 views

SDL touch input on Android (3D camera rotations)

I have a question regarding rotating a 3D camera on an Android device using SDL for touch inputs. The desired effect should be when the user touches and moves their finger on the screen the camera ...
2
votes
0answers
29 views

Bitmap font engine: When is color modulation not supported?

I am developing a bitmap font renderer for a 2D game using SDL 2. (If it matters, I'm using Debian 8 "jessie".) I had planned on storing the glyphs as a grayscale image, translating gray levels to ...
2
votes
2answers
83 views

How do I implement a flashlight in SDL2?

I'm a beginner trying to implement a flashlight in SDL2, but can't figure out a good way to do it. I've found a way to manipulate the background's color; changed it to dark and back to its normal ...
0
votes
1answer
24 views

How can I get the window associated with a SDL_Renderer?

As the title says, is there a member or function to get this? For example renderer->window? Or renderer.window? Or so?
-4
votes
1answer
70 views

Can we port any game written in C++ with SDL to Android platform or we would need to change some codes too? [closed]

Just wanted to lean a cross-platform library!! Since SDL library supports iOS too..
0
votes
1answer
51 views

SDL2 and density-independent pixel

I'm currently using SDL2 on Android and that's my first experience with that library (to be honest, mainly chosen because I'd like to learn it). What is puzzling me is how to deal with different ...
3
votes
1answer
69 views

How do I correctly use SDL_RegisterEvent to create SDL_UserEvents?

I've been looking to use SDL's own event messaging system to pass events around to different parts of my game, since it supports user events. However, the documentation isn't very clear. Here is the ...
2
votes
1answer
169 views

Why does SDL_RenderCopy result in a blank screen?

I'm trying to render a texture(picture), but SDL_RenderCopy keeps the window's background black. Here's the relevant code: SDL_Rect rect; rect.x = 0, rect.y = 0; while(!quit) { ...
2
votes
1answer
124 views

Making knockback in c++

I want to implement a "knockback" in my 2D game, but I have no idea how to do it. I've found some tutorials on google but nothing help. (My knowledge about math is a little limited when we're talking ...
3
votes
0answers
31 views

Is it necessary to call SDL_Quit() at the end of the game? [duplicate]

Is it necessary to call SDL_Quit() at the end of the game? Doesn't C/C++ handle all the variables destruction and memory freeing at the end of a program?
3
votes
1answer
35 views

How to check if renderer is not empty?

I have a SDL_Renderer in SDL2 that I use both to render textures on screen and to render textures on textures, my problem is that when I render to texture the renderer may have some content in it ...
3
votes
2answers
51 views

SDL2 not rendering larger texture to smaller texture

With SDL2 I created texture1 of 28800 x 28800 which contains a drawing of a grass background all over the texture. Then I created texture2 of 2880 x 1620. Then I set the render target to texture2. ...
2
votes
2answers
120 views

Do I need more than one UDP socket on the server?

I'm trying to make a UDP game server using the SDL_net library. This library offers SocketSets which are, according to the documentation, an analogy to the select function. Right now I have ...
2
votes
0answers
110 views

Render to texture and then to screen cause flickering

So I have my class vItem which has a vector (consider elements like layers) of textures, origin rects and destination rects plus other stuff. Basically whenever I update any of the layers in the ...
2
votes
1answer
88 views

Do I need to delete a texture after calling SDL_DestroyTexture()?

Let's suppose I have this texture: SDL_Texture* txt = IMG_LoadTexture(renderer, "path"); /* various code */ SDL_DestroyTexture(txt); delete txt; // <- Is this part really necessary? Doesn't ...
2
votes
0answers
74 views

SDL2 SDL_CreateTexture returns pointer to existing texture

I have an initialized renderer in SDL2 that works fine. I create some textures from images using SDL_CreateTextureFromSurface and store them in a vector. Afterwards, I create an empty texture so as ...
1
vote
0answers
31 views

SDL and smooth transition between changed movement direction

I have an object at position (x,x). Using SDL keyboard events every time the user presses one of the arrow keys the objects is to be translated (via a glTranslatef() call for the x and y axes) by a ...
2
votes
1answer
128 views

Android with SDL2

How to link native code (it has SDL_CreateWindow) with Java application code? In my case, there libSDL2.so, also my .so library that uses the SDL. My method contains functions SDL_CreateWindow and ...