sdl-2

SDL_GetRendererInfo crash

醉酒当歌 提交于 2019-12-25 06:34:08
问题 the following program runs until SDL_GetRendererInfo is called (in function RenderInit()), and then stops working before SDL_GetError can do anything. replacing global_renderer with a null SDL_Renderer pointer doesn't cause a crash and the expected sdl error is gotten. #include <iostream> #include <list> #include "SDL.h" using namespace std; //global variables: bool run = true; // whether or not the program should be running int global_window_width = 50; //width of window in tiles int global

Can't use SDL2 variables in Block scope

半腔热情 提交于 2019-12-24 20:33:15
问题 I'm programming with SDL2, but I cannot grasp the reason behind the following. This works: SDL_Window *window; SDL_Surface *screen_surface; SDL_Surface *picture; auto initWindow(void) {…} auto loadMedia(void) {…} auto close(void) {…} int main(void) { initWindow(); loadMedia(); … close(); } However this does not: auto initWindow(SDL_Window *window, SDL_Surface *screen_surface) {…} auto loadMedia(SDL_Surface *picture, std::string resource) {…} auto close(SDL_Window *window, SDL_Surface *picture

SDL_CreateWindowFrom() with Qt widget under Mac OS

六眼飞鱼酱① 提交于 2019-12-24 15:19:21
问题 I am using libSDL2 in a Qt app. The code is working well under Linux and Windows but is failing under Mac OS. Here is the crash output: 2015-05-12 10:24:35.598 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0 2015-05-12 10:24:35.643 testapp[4621:105425] An uncaught exception was raised 2015-05-12 10:24:35.643 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0 2015-05-12 10:24:35.643 testapp[4621:105425] ( 0

Segmentation fault initializing SDL2. What am I doing wrong with memory?

守給你的承諾、 提交于 2019-12-24 10:55:49
问题 This is just suppose to display a bmp image to the SDL window front buffer. I played around with the code. And I think there is something wrong with my init() function. I'm new to SDL. But there must be a problem with my pointers or something I'm missing about SDL's fucntions EDIT: I used GDB and it turned out my close() function was the problem. I believe it was because I was freeing memory that was set to NULL? I got rid of the close fucntion and just freed mem after my delay function.

Cannot draw a filled circle with SDL2 gfx

笑着哭i 提交于 2019-12-24 07:26:41
问题 There is the following code. The desired result is that a window is created and a filled circle is drawn: #include <SDL2/SDL.h> #include <iostream> #include <SDL2/SDL2_gfxPrimitives.h> int main() { SDL_Window* window = nullptr; SDL_Renderer* renderer = nullptr; if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { std::cout << "Could not initialise" << std::endl; return 1; } window = SDL_CreateWindow("MyGame", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); if(!window) { std:

SDL Error while Creating Window?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 06:06:37
问题 #include<SDL2/SDL.h> #include<stdio.h> #include<stdbool.h> bool init(char *title, int width, int height); void close(); SDL_Window *window = NULL; SDL_Surface *screen = NULL; bool init(char *title, int width, int height){ bool success = true; // SDL_Init 0 on success and returns negative on failure if( SDL_Init(SDL_INIT_EVERYTHING) != 0 ){ SDL_Log("Couldn't initialize SDL: %s",SDL_GetError()); success = false; } // creating Window and Surface window = SDL_CreateWindow(title, SDL_WINDOWPOS

Get window handle of SDL 2 application

杀马特。学长 韩版系。学妹 提交于 2019-12-24 05:09:05
问题 I would like to get the handle of a SDL2 window, to use it with WinApi. I retrieve that handle with the following code : /* All the SDL initalisation... */ SDL_Window* window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESX, RESY, SDL_WINDOW_SHOWN); SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (window == NULL || renderer == NULL) { MessageBox(NULL, L"SDL initialisation error", NULL, MB_OK); exit(-1); } SDL

How to install SDL2 library in Fedora 20

血红的双手。 提交于 2019-12-24 03:29:23
问题 There is a question about the SDL package (SDL 1.2) in Fedora in StackOverflow. But I can't found any about SDL2 in Fedora, and I am having troubles to install the SDL2 package. I search and the command to install SDL2 in Fedora is: sudo yum install SDL2* But still having problems to found the #include "SDL2/SDL.h". . After looking in usr/include/, I wasn't able to found the SDL.h... So how can I install SDL2 package and make it work in Fedora 20 distro? 回答1: Make Sure to have SDL2 and

Greyscale image in SDL2

痴心易碎 提交于 2019-12-24 03:07:10
问题 I have an array of uint8_t which represents a greyscale picture, where each pixel is one uint8_t . I would like to display this in a window using the SDL2 library. I have tried to create an SDL_Surface from the array by doing mSurface = SDL_CreateRGBSurfaceFrom(mData, mWidth, mHeight, 8, mWidth, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000); However, the problem is that when a depth of 8 bits is passed to SDL_CreateRGBSurfaceFrom (as I have done here), according to the SDL2 wiki "If depth is 4 or 8

Displaying an .bmp image in C++/SDL2

陌路散爱 提交于 2019-12-24 00:54:07
问题 I have been having trouble displaying an image in an SDL window and I am not quite sure what I am doing wrong. The code compiles just fine and the image has been placed in the debug folder with my .exe so I am not sure why it is not displaying. Is there something minor I may have missed? #include <iostream> #include <stdio.h> #include <SDL.h> #undef main using namespace std; const int screenWidth = 640; const int screenHeight = 480; int main(int argc, char* args[]) { SDL_Window* window = SDL