sdl-2

How can set different function signature to the same function pointer?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:08:18
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 4 years ago . How can I set a function pointer depending on some condition to functions with different signature? Example: short int A() { return 0; } long int B() { return 0; } void main() { std::function<short int()> f = A; f(); if(true) { //error f = B; } } How can use the same function pointer for two functions with different signature? Is it possible? If is not,

On OS X, why the showimage example of SDL2_image needs to do RenderCopy() in the while loop?

风格不统一 提交于 2019-12-11 03:00:44
问题 For quick reference, the showimage.c example code in SDL2_image library has the following code: /* Show the window */ SDL_SetWindowTitle(window, argv[i]); SDL_SetWindowSize(window, w, h); SDL_ShowWindow(window); done = 0; while ( ! done ) { while ( SDL_PollEvent(&event) ) { /* some event handling code... */ } /* Draw a background pattern in case the image has transparency */ draw_background(renderer, w, h); /* Display the image */ SDL_RenderCopy(renderer, texture, NULL, NULL); SDL

glReadPixels() burns up all CPU cycles of a single core

纵饮孤独 提交于 2019-12-11 02:49:54
问题 I have an SDL2 app with an OpenGL window, and it is well behaved: When it runs, the app gets synchronized with my 60Hz display, and I see 12% CPU Usage for the app. So far so good. But when I add 3D picking by reading a single (!) depth value from the depth buffer (after drawing), the following happens: FPS still at 60 CPU usage for the main thread goes to 100% If I don't do the glReadPixels, the CPU use drops back to 12% again. Why does reading a single value from the depth buffer cause the

glewInit() fails with “Missing GL version”, SDL2 OpenGL context, cygwin compiler

十年热恋 提交于 2019-12-11 02:27:42
问题 The program following, is one that creates a window which does nothing except close when you press esc. When I compile it with cygwin, there are no errors. The GLEW I use is from Cygwin Ports, and the SDL2 is version 2.0.3, from their website's SDL2-devel-2.0.3-mingw.tar.gz download. I have SDL2.dll in the directory of the compiled executable. Links with: -lSDL2 -lSDL2main -lGLEW -lGLU -lGL -lSDL2 -lSDL2main -lGLEW -lGLU -lGL , twice to ensure everything is linked. Also compiled with: -std=c+

SDL_ttf cannot find “SDL.h”, but main.cpp can

六眼飞鱼酱① 提交于 2019-12-11 02:07:40
问题 I am writing a make file to compile a very simple SDL2 program. So far it compiles SDL2 just fine, and now I am working on compiling the extension frameworks SDL2_image and SDL_ttf. It seems that MAKE is finding the SDL_ttf.h properly, but then SDL_ttf.h cant find "SDL2/SDL.h". Here is the error: In file included from main.cpp:3: /Library/Frameworks/SDL2_ttf.framework/Headers/SDL_ttf.h:30:10: fatal error: 'SDL2/SDL.h' file not found #include <SDL2/SDL.h> ^ 1 error generated. make: *** [main.o

After SDL_SetWindowSize resizes, drawing is done offset down the screen

无人久伴 提交于 2019-12-11 01:57:22
问题 I'm using Ubuntu 19.0.4 with SDL version 2.0.9+dfsg1-1ubuntu1. The code works fine with Visual Studio and MinGW's g++, and if I read others' comments right, other versions of Unix. But with Ubuntu, my version, it shows the rectangle drawn ~200 pixels down the screen (should be at 0, 0). There's a commented-out section that seems to fix it by delaying, but a) that's weird and b) I don't entirely trust it. Am I doing something wrong? Surely there's a fix that makes sense. #include <SDL.h>

What's causing this runtime error and how can I rectify it?

你说的曾经没有我的故事 提交于 2019-12-11 01:06:35
问题 The following error occurred during runtime: The procedure entry point _ZSt24__throw_out_of_range_fmtPKcz could not be located in the dynamic link library "test.exe". I used a C++ demangler to find out which function is causing the entry point error. The function is: std::__throw_out_of_range_fmt(char const*, ...) I am linking to the following libraries: SDL2 (Dynamic, compiled from source by myself, same version of GCC that I'm using for my project (4.9.3)). GLEW (Added source to project) I

SDL_PollEvent seems to prevent window surface from updating

霸气de小男生 提交于 2019-12-11 00:30:44
问题 I'm currently walking through the Lazy Foo tutorials for SDL2 (I'm doing this on a Linux machine) and I'm encountering some kind of bug where the inclusion of SDL_PollEvent in my main loop seems to prevent SDL_UpdateWindowSurface from actually updating. If I leave the SDL_PollEvent loop out, the loaded bmp displays properly. However, if I include the SDL_PollEvent loop or even a call to SDL_PollEvent , then the window never gets updated with an image. Everything else seems to work fine, SDL

Playing sine soundwave with SDL2 - noise / scratch issue

末鹿安然 提交于 2019-12-10 23:49:30
问题 My goal is to create an SDL window plotting different waveforms and playing an indefinite sound of this wave. By pressing specific keys, the parameters of the wave, like the amplitude, frequency or waveform can be modified. The problem is that even a simple sine wave which looks nice when plotted, sounds noisy. I don't understand why. Code: #include "Graph.h" #include <thread> #include <iostream> #include <sstream> #include <string> int main(int argc, char* argv[]){ Graph* g = new Graph();

SDL2 sample build error with android ndk r14

北战南征 提交于 2019-12-10 23:16:01
问题 I have tested to build the sample in SDL2 source (2.0.5) on my ubuntu 16.04 machine. According to https://wiki.libsdl.org/Android, I installed android sdk and ndk r14 and setup my environment variables. But I have failed to build with following command in "Simple Build" chapter. cd /usr/src/SDL2/build-scripts/ ./androidbuild.sh org.libsdl.testgles ../test/testgles.c It makes following error. Error: The project either has no target set or the target is invalid. Please provide a --target to the