sdl-2

SDL2 program only works if Renderer is created with SDL_RENDERER_SOFTWARE

跟風遠走 提交于 2019-11-28 02:24:48
I've written a program using C++ and SDL2 which: creates a window gets the window's surface creates a renderer for the window renders some filled rectangles onto the window creates a texture from the window's surface clears the screen renders some filled circles onto the window creates a second texture from the window's surface enters an event loop, where every time a key is pressed: if circles are currently being displayed, SDL_RenderCopy() is used to copy the squares texture to the window. else if squares are currently being displayed, the circles texture is copied to the window. The program

Drawing 2D stuff with SDL_Renderer and OpenGL stuff with SDL_GLContext

江枫思渺然 提交于 2019-11-28 02:04:55
I have been learning about SDL 2D programming for a while and now I wanted to create a program using SDL and OpenGL combined. I set it up like this: SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("SDL and OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); context = SDL_GL_CreateContext(window); The program is for now just a black window with a white line displayed using OpenGl. Here is the code for the rendering: glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINES); glVertex2d(1, 0); glVertex2d(-1, 0); glEnd(); SDL_GL

Using homebrew installed SDL2 with Xcode

China☆狼群 提交于 2019-11-27 21:45:12
问题 I have installed SDL2 using Homebrew but now I don't know how to make sure Xcode can use it! I imported the created library and added it to the build phases tab of my project. But when I try to build I get the error 'SDL2/SDL.h' not found 回答1: To be able to use SDL2 on Xcode you must set two things (which are required for SDL in general): where to find header files (so that Clang can compile with -Iheader/path ) where to find the .dylib to link it to the project (since with brew you don't

Smart pointers with SDL

不想你离开。 提交于 2019-11-27 19:31:57
For my game should I use a raw pointer to create SDL_Window , SDL_Renderer , SDL_Texture etc. as they have specific delete functions SDL_DestroyTexture(texture); or should I add a custom deleter when I create a unique_ptr or shared_ptr and if so how would I do this with SDL types? You could create a functor that has several overloaded operator() implementations, each of which call the correct destroy function for the respective argument type. struct sdl_deleter { void operator()(SDL_Window *p) const { SDL_DestroyWindow(p); } void operator()(SDL_Renderer *p) const { SDL_DestroyRenderer(p); }

“winapifamily.h: No such file or directory” when compiling SDL in Code::Blocks

允我心安 提交于 2019-11-27 17:58:09
I am following along with the SDL2.0 tutorials by LazyFoo, using Code::Blocks 13.12. I have had no trouble getting SDL2 linked and running in VS2010 but have changed IDE and come across this error: winapifamily.h: No such file or directory I think everything is linked correctly. I have pointed the program to my SDL2 include and lib directories. Buildlog: (error is occuring in file: ..\include\SDL2\SDL_platform.h) === Build: Debug in SDL2_Setup (compiler: GNU GCC Compiler) === fatal error: winapifamily.h: No such file or directory === Build fails: 1 error(s), 0 warning(s) (0 minute(s), 0 second

I'm using the SDL functions without the SDL_main be defined. Is that fine?

可紊 提交于 2019-11-27 17:00:50
问题 that's my code: Lib.h #ifdef ExportLib #define Lib __declspec(dllexport) #else #define Lib __declspec(dllimport) #endif extern void Lib Launch(); Lib.cpp #include <SDL/SDL.h> #include "Lib.h" void Launch() { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window* win = SDL_CreateWindow("Untitle", 100, 100, 400, 400, 0); SDL_DestroyWindow(win); SDL_Quit(); } I build this code to a static library. Then I created a new source file and used this library. main.cpp #include "Lib.h" int main() { Launch(); return

What is an SDL renderer?

你说的曾经没有我的故事 提交于 2019-11-27 16:37:44
I'm starting with SDL2 and having some trouble trying to understand what an SDL_Renderer is. What is it? What does it do? What's the difference between SDL_Renderer, SDL_Window, SDL_Surface and SDL_Texture and how they are related? I had issues with this when trying to understand this introductory code: #include <iostream> #include <SDL2/SDL.h> int main() { /* Starting SDL */ if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl; return 1; } /* Create a Window */ SDL_Window *window = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL

Kivy error (python 2.7) : sdl2 import error

China☆狼群 提交于 2019-11-27 16:24:00
I'm trying to use kivy on my Python 2.7 project (in a PyCharm - Windows 10 environment), but I get the following error. If someone can help me ? Thanks ! PS : I tried many times uninstalling/reinstalling libraries etc and doing what suggested on posts like this one, but it doesn't work : Kivy not working (Error: Unable to find any valuable Window provider.) [INFO ] [Logger ] Record log in C:\Users\cyril\.kivy\logs\kivy_18-03-25_0.txt C:\Users\cyril\venv\lib\site-packages\kivy\modules\__init__.py:128: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode -

SDL_PollEvent() stuttering while idle?

一笑奈何 提交于 2019-11-27 14:25:00
I've cobbled together a very basic game loop in C++ using SDL2, and I've noticed that every few seconds, SDL_PollEvent seems to be unusually slow, even when nothing is happening. I sent my deltaTime to console every loop, and its about 100ms difference on the cycles that SDL_PollEvent is lagging. I've already confirmed that it's something with this function by moving my timers around, but I'm not sure where to diagnose the issue further. My loop: while (!quit) { uint32_t startTime = SDL_GetTicks(); while (SDL_PollEvent(&e) != 0) { std::cout << "Event: "<< e.type << std::endl; // Added later,

Difference between surface and texture (SDL / general)

ⅰ亾dé卋堺 提交于 2019-11-27 10:54:46
Can anyone explain to me in simple words what is the difference between texture and surface? I saw it used in SDL2 as SDL_Surface and SDL_Texture . SDL_Texture is created from SDL_Surface which in turn is created from image/bitmap. Both are collection of pixels. But I do not see the main difference between them (has to do something with GPU?) I tried to google it but all explanations I found were too complex to understand them without digging deeper into computer graphics stuff. Petr Abdulin Basically your assumption "has to do something with GPU?" is right. SDL_Surface is used in software