sdl-2

Is it possible to use SDL2 with smart pointers?

[亡魂溺海] 提交于 2019-12-05 21:22:23
I have this line of code //std::unique_ptr<SDL_Window> _window_; // this is somewhere else... _window_ = std::make_unique<SDL_Window>(SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _WIDTH_, _HEIGHT_, SDL_WINDOW_SHOWN)); it produces the following compiler error In file included from /usr/include/c++/6/memory:81:0, from /home/user/prj/src/main.cpp:4: /usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = SDL_Window; _Args = {SDL_Window*}; typename std::_MakeUniq<_Tp>::_

Big memory leak in SDL_Init

限于喜欢 提交于 2019-12-05 19:17:47
EDIT: updated with some new info (Bold'ed). Also, the code and Valgrinds output is updated. I recently started using SDL2 as my graphics library. After developing some stuff, I decided to run Valgrind and found out that I am leaking memory... a lot of memory. After narrowing it down I compiled this code (In C) : #include <SDL2/SDL.h> int main(int argc, char** argv) { SDL_Init(SDL_INIT_EVERYTHING); SDL_QuitSubSystem(SDL_INIT_EVERYTHING); SDL_Quit(); return 0; } This is the make file: CC = gcc CCFLAGS = -Wall -o0 LDFLAGS = -lSDL2 SOURCES= main.c OBJECTS=$(SOURCES:.c=.o) EXE = Test .PHONY: all: $

How to draw a rectangle outline in SDL 2.0

柔情痞子 提交于 2019-12-05 16:21:40
I'm trying to draw a rectangle outline in SDL 2.0 in order to use as a selection box. Does anyone know how to make one in SDL 2.0? You are looking for the SDL_RenderDrawRect : int SDL_RenderDrawRect(SDL_Renderer* renderer, const SDL_Rect* rect); Typical usage would be: SDL_Rect rectToDraw = {100,100,100,100} // Just some random rect //Set Color of Rect with SDL_SetRenderDrawColor if needed SDL_RenderDrawRect(renderer, &rectToDraw); To draw a filled rect it would then be with SDL_RenderFillRect 来源: https://stackoverflow.com/questions/20072639/how-to-draw-a-rectangle-outline-in-sdl-2-0

SDL2 - Check if OpenGL context is created

你离开我真会死。 提交于 2019-12-05 08:28:56
I am creating an application using SDL2 & OpenGL, and it worked fine on 3 different computers. But on another computer (an updated arch linux), it doesn't, and it crashes with this error: OpenGL context already created So my question is: How do I check if the OpenGL context has already been created? And then, if it is already created, how do I get a handle for it? If I can't do this, how do I bypass this issue? SDL2 does not in fact create an OpenGL context without you asking to make one. However, if you ask it to create an OpenGL context when OpenGL doesn't work at all, SDL2 likes to, erm ,

SDL_Image IMG_Load fails on png with: “Failed loading libpng16-16.dll:”

萝らか妹 提交于 2019-12-05 08:05:22
Whenever I try to load a PNG using SDL_Image's IMG_Load function it gives the error Failed loading libpng16-16.dll: . I have all the right dll's in the right path and I can use other parts of SDL_Image, but for some reason it can't load the libpng dll. How can I fix this? Any help is appreciated. See my article " SDL2: Loading Images with SDL_image ": If you're going to run from Visual Studio, make sure the image is in the same folder as your main.cpp file; otherwise if you're running straight from the executable, the image should be in the same folder with it. Needless to say, what I wrote

Where can I find the definition of 'SDL_Window'

独自空忆成欢 提交于 2019-12-05 06:41:52
问题 I've just started learning SDL2 in Linux. I am reading the very first tutorial from LazyFoo and I see have that code: //The window we'll be rendering to SDL_Window* window = NULL; Where can I find the definition of SDL_Window in order to read about it ? 回答1: This structure isn't exposed to user side; SDL_video.h file contains forward declaration of it: typedef struct SDL_Window SDL_Window; Forward declaration means you can only use it as pointer type because actual data layout is hidden from

Is SDL Renderer useless if I use opengl for drawing?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 01:39:19
问题 I'm am learning SDL2, but I am also using the imgui library that is using OpenGL calls. From what I read on various blogs online, I can't easily mix SDL2 renderer and opengl calls; I either use one or the other. Most of the tutorials I've read use the renderer, so I do not quite understand how to use SDL2 without the renderer for drawing primitives, or drawing sprites. Take this for example: http://lazyfoo.net/tutorials/SDL/11_clip_rendering_and_sprite_sheets/index.php He creates the sdl

How to disable key repeat in SDL2?

北战南征 提交于 2019-12-04 23:36:19
There used to be a function named SDL_EnableKeyRepeat() in SDL, but not anymore in SDL2. I searched around in SDL2-wiki but failed to locate anything relevant. Any ideas? When handling a keyboard event, just filter out any events that are repeat events, i.e. check the repeat field of the SDL_KeyboardEvent of the SDL_Event union. For example: SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit = true; } if (event.type == SDL_KEYDOWN && event.key.repeat == 0) { if (event.key.keysym.sym == SDLK_d) debug = debug ? false : true; // ... handle other keys } } See https

How to get screen size in SDL

[亡魂溺海] 提交于 2019-12-04 22:45:01
问题 I'm trying to make a program using SDL and C++. How can I get screen's width and height in pixels in SDL?I'm trying to get screen's width not the window's width. . . . 回答1: In SDL2, use SDL_GetCurrentDisplayMode or SDL_GetDesktopDisplayMode depending on your needs. Usage example: SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); auto Width = DM.w; auto Height = DM.h; On high-DPI displays this will return the virtual resolution, not the physical resolution. From the SDL2 wiki: There's a

SDL_RenderCopy with an array of Rectangles

心不动则不痛 提交于 2019-12-04 16:11:08
SDL_RenderCopy only accepts a single input rectangle and a single output rectangle. But if I have a lot of images that I want to be filled, my knowledge of opengl tells me that a bulk operation that draws all images at once can be much faster than one draw call per sprite. SDL_FillRects is already there with a count parameter. But I cant find anything suitable for drawing a lot of sprites. Is there some function in SDL2 that I am still missing, because I doubt that this optimization can be done automatically. 来源: https://stackoverflow.com/questions/20400544/sdl-rendercopy-with-an-array-of