sdl

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

How to output to the console in C++/Windows

为君一笑 提交于 2019-11-27 22:54:23
When using iostream in C++ on Linux, it displays the program output in the terminal, but in Windows, it just saves the output to a stdout.txt file. How can I, in Windows, make the output appear in the console? MSN Since you mentioned stdout.txt I google'd it to see what exactly would create a stdout.txt; normally, even with a Windows app, console output goes to the allocated console, or nowhere if one is not allocated. So, assuming you are using SDL (which is the only thing that brought up stdout.txt), you should follow the advice here . Either freopen stdout and stderr with "CON", or do the

Saving the openGL context as a video output

北战南征 提交于 2019-11-27 20:25:25
问题 I am currently trying to save the animation made in openGL to a video file. I have tried using openCV 's videowriter but to no advantage. I have successfully been able to generate a snapshot and save it as bmp using the SDL library. If I save all snapshots and then generate the video using ffmpeg , that is like collecting 4 GB worth of images. Not practical. How can I write video frames directly during rendering? Here the code i use to take snapshots when I require: void snapshot(){ SDL

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); }

Using SDL_ttf with OpenGL

£可爱£侵袭症+ 提交于 2019-11-27 18:02:15
I'm using OpenGL and SDL to create a window in my program. How do I use SDL_ttf with an OpenGL window? For example I want to load a font and render some text. I want to draw the text using an SDL OpenGL surface. Here's how to do it: Initialize SDL and SDL_ttf, and create a window using SDL_SetVideoMode() . Make sure you pass the SDL_OPENGL flag. Initialize your OpenGL scene ( glViewport() , glMatrixMode() etc.). Render your text with SDL_ttf using e.g. TTF_RenderUTF8_Blended() . The render functions return an SDL_surface, which you have to convert into an OpenGL texture by passing a pointer to

“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

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,