sdl-2

Can cairo use SDL_Texture as a render target?

冷暖自知 提交于 2019-12-03 12:37:00
问题 Rendering to an SDL_Surface is possible with Cairo, but my application uses SDL_Renderer and SDL_Texture to take advantage of 2D accelerated rendering. I am currently creating an SDL_Surface and copying it to a texture with SDL_CreateTextureFromSurface(), but this process is cumbersome and possibly slow (although it's not a bottleneck.) Is there a direct way to draw to a SDL_Texture? 回答1: I've figured it out. Streaming SDL_Textures can expose the raw pixels in the ARGB8888 format, which is a

What is the difference between an SDL physical key code and an SDL virtual key code?

和自甴很熟 提交于 2019-12-03 10:35:18
The struct SDL_Keysym has SDL_Scancode and SDL_Keycode members. What is the difference between them? The documentation does not really clear it up for me. I tried both and they seem to do the same thing. See the SDL documentation . Scancodes represent the physical position of the keys, modeled after a standard QWERTY keyboard, while Keycodes are the character obtained by pressing the key. On an AZERTY keyboard, pressing A will emit a 'Q' scancode and an 'a' keycode. Generally, scancode s are the true values emitted by the keyboard (hardware) to the OS while keycode is what the OS/library maps

SDL_PollEvent vs SDL_WaitEvent

六眼飞鱼酱① 提交于 2019-12-03 05:47:27
问题 So I was reading this article which contains 'Tips and Advice for Multithreaded Programming in SDL' - https://vilimpoc.org/research/portmonitorg/sdl-tips-and-tricks.html It talks about SDL_PollEvent being inefficient as it can cause excessive CPU usage and so recommends using SDL_WaitEvent instead. It shows an example of both loops but I can't see how this would work with a game loop. Is it the case that SDL_WaitEvent should only be used by things which don't require constant updates ie if

How do I take and save a BMP screenshot in SDL 2?

╄→гoц情女王★ 提交于 2019-12-03 05:20:45
Using just a given SDL_Window* and SDL_Renderer*, how can I create and save a screenshot in SDL 2.0? Neil Flodin Below is a function for saving a screenshot in SDL 2 taken from a library I'm currently writing. bool saveScreenshotBMP(std::string filepath, SDL_Window* SDLWindow, SDL_Renderer* SDLRenderer) { SDL_Surface* saveSurface = NULL; SDL_Surface* infoSurface = NULL; infoSurface = SDL_GetWindowSurface(SDLWindow); if (infoSurface == NULL) { std::cerr << "Failed to create info surface from window in saveScreenshotBMP(string), SDL_GetError() - " << SDL_GetError() << "\n"; } else { unsigned

Is there a way to store a texture inside a struct using rust-sdl2? [duplicate]

流过昼夜 提交于 2019-12-02 20:06:27
问题 This question already has answers here : Cannot infer an appropriate lifetime for autoref due to conflicting requirements (1 answer) Why can't I store a value and a reference to that value in the same struct? (2 answers) Closed 7 months ago . I'm using the rust-sdl2 crate to paint a buffer on a window screen, so I decided to abstract the SDL calls. I tried to follow this example from the rust-sdl2 repo and my first thought was to create something like this: pub struct SDLDisplay { sdl_context

SDL_PollEvent vs SDL_WaitEvent

左心房为你撑大大i 提交于 2019-12-02 19:08:02
So I was reading this article which contains 'Tips and Advice for Multithreaded Programming in SDL' - https://vilimpoc.org/research/portmonitorg/sdl-tips-and-tricks.html It talks about SDL_PollEvent being inefficient as it can cause excessive CPU usage and so recommends using SDL_WaitEvent instead. It shows an example of both loops but I can't see how this would work with a game loop. Is it the case that SDL_WaitEvent should only be used by things which don't require constant updates ie if you had a game running you would perform game logic each frame. The only things I can think it could be

Memory leak SDL while using SDL_CreateTextureFromSurface

懵懂的女人 提交于 2019-12-02 12:53:19
问题 I'm learning SDL and I've noticed that I have memory leak when I have this line in my code: m_TextureMap["napis"]= SDL_CreateTextureFromSurface( getRenderer(), textSurface ); I have SDL_FreeSurface(textSurface); right after the first one. When I comment out only this line, there's no memory leak. What am I doing wrong? Is there anything else I need to clean except for SDL_FreeSurface(textSurface) ? P.S. getRenderer is function that returns global SDL renderer, I use this function a lot in

Is there a way to store a texture inside a struct using rust-sdl2? [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-02 12:19:57
This question already has an answer here: Cannot infer an appropriate lifetime for autoref due to conflicting requirements 1 answer Why can't I store a value and a reference to that value in the same struct? 2 answers I'm using the rust-sdl2 crate to paint a buffer on a window screen, so I decided to abstract the SDL calls. I tried to follow this example from the rust-sdl2 repo and my first thought was to create something like this: pub struct SDLDisplay { sdl_context: Sdl, video_subsystem: VideoSubsystem, canvas: WindowCanvas, texture_creator: TextureCreator<sdl2::video::WindowContext>,

How to render SDL2 texture into GTK3+ window?

戏子无情 提交于 2019-12-02 08:20:33
I am creating a music player and trying to use GTK3+ for creating user interface. I am using SDL_CreateWindowFrom function to let SDL2 use GTK3+ window rather than creating one but cann't figure out the steps I need to follow in order to render the SDL2 textures into GTK3+ window. Code getting GTK3 window ID window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "---"); gtk_widget_show(window); gdkWin = gtk_widget_get_window(GTK_WIDGET(window)); data->playContext->winID = GDK_WINDOW_XID(gdkWin); gtk_main(); Code Setting SDL2 window playContext->display->window =

SDL_DisplayFormat not declared in this scope: Using SDL2

喜你入骨 提交于 2019-12-02 06:08:13
问题 Compiler doesn't return missing SDL.h, but rather that SDL_DisplayFormat is not declared in scope of a class member function located on a different header even though I have it initialized in main. SDL_Surface *SpriteLoad::Load(char *File) { SDL_Surface *temp = NULL; SDL_Surface *opt = NULL; if ((temp = IMG_Load(File)) == NULL) { return NULL; } opt = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); return opt; } Where my main inits SDL through a class and member function: int main (int args,