sdl-2

How to disable key repeat in SDL2?

别说谁变了你拦得住时间么 提交于 2019-12-06 18:20:07
问题 There used to be a function named SDL_EnableKeyRepeat() in SDL, but not anymore in SDL2. I searched around in SDL2-wiki but failed to locate anything relevant. Any ideas? 回答1: When handling a keyboard event, just filter out any events that are repeat events, i.e. check the repeat field of the SDL_KeyboardEvent of the SDL_Event union. For example: SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit = true; } if (event.type == SDL_KEYDOWN && event.key.repeat == 0

How to show interstitial ads?

情到浓时终转凉″ 提交于 2019-12-06 14:55:24
How to show interstitial ads? @Override protected void onCreate(Bundle savedInstanceState) { //Log.v("SDL", "onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.main); interstitial = new InterstitialAd(this); interstitial.setAdUnitId("ca-app-pub-2188258702xxxxxxxxxxx"); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("XXXXXXXXXXXXX") .build(); interstitial.loadAd(adRequest); // So we can call stuff from static callbacks mSingleton = this; // Set up the surface mEGLSurface = EGL10.EGL_NO_SURFACE; mSurface = new

Only glsl shader version 120 works on mac OS X

家住魔仙堡 提交于 2019-12-06 12:57:29
问题 I have a problem with the glsl's version on my mac os X 10.9.2. I'm making a program in c++ with OpenGL and SDL2 I can't upgrade from my version 120 to any version higher. How I can upgrade please ? I compile like this : g++ and my flag is : -framework SDL2 -lSDLmain -framework OpenGL -framework SDL2_image -framework cocoa ERROR: 0:3: '' : version '330' is not supported 回答1: On OS/X 10.9 to create an OpenGL 3.3/4.1 context you need to add the following snippet before SDL_CreateWindow . SDL

SDL_RenderCopy with an array of Rectangles

穿精又带淫゛_ 提交于 2019-12-06 11:42:01
问题 SDL_RenderCopy only accepts a single input rectangle and a single output rectangle. But if I have a lot of images that I want to be filled, my knowledge of opengl tells me that a bulk operation that draws all images at once can be much faster than one draw call per sprite. SDL_FillRects is already there with a count parameter. But I cant find anything suitable for drawing a lot of sprites. Is there some function in SDL2 that I am still missing, because I doubt that this optimization can be

Set Logitech Steering Wheel position/angle from SDL?

偶尔善良 提交于 2019-12-06 11:00:35
I'm writing C code that controls a Logitech gaming wheel using SDL. So far I have successfully implemented the code that sets the steering wheel in autocenter mode with: SDL_HapticSetAutocenter(haptic, STRENGTH); //set autocenter I would like to be able to use the motor of the steering wheel to rotate it as desired to particular angle positions. After checking in the documentation of the API , I did not find a simple way to do it. I wonder if anyone has some advice on this. 来源: https://stackoverflow.com/questions/50665809/set-logitech-steering-wheel-position-angle-from-sdl

C++ SDL2 Error when trying to render SDL_Texture: Invalid texture

家住魔仙堡 提交于 2019-12-06 07:35:01
I'm trying to make a simple game and when I try rendering my SDL_Texture , I get an inexplicable error. I've set up everything right, I'm able to successfully clear the screen with SDL_RenderClear , and my texture isn't null, so it should have been created properly. But when I try calling the render() function I get an error, and SDL_GetError() returns "Invalid texture". Edit: I have now created an MCVE as requested, and I tested it to verify that it reproduces the error. It should display the image at the path "gfx/grid.bmp" in the window, but instead it gives me the error. Here is the full

SDL2: two displays, two windows and fullscreen mode

扶醉桌前 提交于 2019-12-06 05:29:00
I'm trying to create two windows on two displays. But I have a problem: the second window is displayed in full screen mode, but the first window is minimized, and I need to click on it on the taskbar to expand to full screen. I create windows in loop with code: windows_data.window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED_DISPLAY(i), SDL_WINDOWPOS_CENTERED_DISPLAY(i), width, height, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_SHOWN); Adding the flag SDL_WINDOW_MAXIMIZED does not solve the problem. My system is Windows 8.1 Proffesional. I debug step by step and found the reason in SDL

Render TTF SDL2.0 opengl 3.1

回眸只為那壹抹淺笑 提交于 2019-12-06 03:31:04
I'm working with SDL2.0, and using a (semi modern) opengl (3.1). I'm looking to add a text overlay to my application, and to render TTF in the application. How would I go about this using modern OpenGL? EDIT: As per the suggestion of genpfault, I've tried using the SDL_TTF library, but All I'm getting is garbage on screen http://i.stack.imgur.com/FqyCT.png I've attached a gist of my shaders, which are very simple for this program, and also the snipped I'm using to load the text into surface, and to bind it to the texture. I'm not trying to do anything crazy here at all. Is there anything I'm

CMake failing to statically link SDL2

折月煮酒 提交于 2019-12-06 02:25:57
问题 I'm trying to build a simple SDL2 game with CMake and MSYS Makefiles. I want to statically link SDL2 so I can distribute a single executable without having to include the SDL2.dll. Here's my CMakeLists.txt file: project(racer-sdl) cmake_minimum_required(VERSION 2.8) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_EXE_LINKER_FLAGS "-static") include(FindPkgConfig) pkg_search_module(SDL2 sdl2) if (SDL2_FOUND) message(STATUS "Using SDL2") add_definitions(-DUSE_SDL2) include

How to load file font into RAM using C/C++ and SDL2?

感情迁移 提交于 2019-12-06 01:00:46
Accordingly to the ''best practices'' I have learned, we should load the resources we need to our programs into RAM, avoiding unnecessary requests to user's hard drive. Using SDL2, I always free image files after loading them into RAM. (File -> Surface -> Texture -> Free File/Surface). So, if I other application changes the file, my program ignores it, as the file is not in use by it anymore. Now in lesson 16 I am learning to use the Add-on SDL_ttf . However, using SDL_ttf addon I could not find a way to free the font.ttf file, loading it into RAM too. I can only see it through a pointer. It