sdl-2

SDL2 strange behaviour of hardware rendering

白昼怎懂夜的黑 提交于 2019-12-04 15:24:54
I want to create my first game. Nothing special, just blue rectangle moving when WSAD keys are pressed. The problem is that when I run my game, there are bugs with rectangle(See image below). Bugs appears only during horizontal movement, and not vertical. Which is interesting, when I changed line: renderer = SDL_CreateRenderer(display, -1, SDL_RENDERER_ACCELERATED) to: renderer = SDL_CreateRenderer(display, -1, SDL_RENDERER_SOFTWARE) everything is OK I am using Windows 10, MinGw with CMake(C++14), and SDL 2.0.8, Intel core i5 7th gen, Radeon M7 R465 Im my code OnRender function is responsible

Sample SDL program gives an empty window

笑着哭i 提交于 2019-12-04 14:19:47
config: archlinux with awesome desktop environment I just installed sdl2, and tried to run this sample code: https://github.com/xyproto/hello_sdl2/blob/master/c%2B%2B/main.cpp The result is an empty window (I can see my console through it) in the middle of the screen. Even when I hit mod4+Enter, it doesn't tile up nicely with the others. Why is that? (I updated my system, reinstalled sdl2. I also couldn't find any relevant hit browsing google.) All windowing systems require you to handle messages by pumping a message queue. See this chapter for some SDL specific examples but the essence is

CMake failing to statically link SDL2

◇◆丶佛笑我妖孽 提交于 2019-12-04 10:12:42
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_directories(${SDL2_INCLUDE_DIRS}) link_directories(${SDL2_LIBRARY_DIRS}) link_libraries(${SDL2_LIBRARIES})

How to use SDL_CreateTexture

扶醉桌前 提交于 2019-12-04 09:48:14
I would like to know ho to use SDL_CreateTexture function. I just want to create texture, give it a color and draw it somewhere on the screen. I dont wanna load any picture into it. I thought I can use SDL_CreateTexture, SDL_SetTextureColorMod, SDL_RenderCopy, SDL_RenderPresent in that order, but I always get just a black rectangle instead of red one . #include <SDL.h> int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window *MainWindow = SDL_CreateWindow("My Game Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_SHOWN ); SDL_Renderer *renderer

Kivy support for SDL2 in Virtualenv

扶醉桌前 提交于 2019-12-04 07:14:05
I followed following steps to install kivy in virtualenv (Mac OSX) with support of sdl2 $ brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer $ pip install -I Cython $ USE_OSX_FRAMEWORKS=0 pip install kivy but when tried to run basic documentation code from kivy.app import App from kivy.uix.gridlayout import GridLayout from kivy.uix.label import Label from kivy.uix.textinput import TextInput class LoginScreen(GridLayout): def __init__(self, **kwargs): super(LoginScreen, self).__init__(**kwargs) self.cols = 2 self.add_widget(Label(text='User Name')) self.username = TextInput(multiline

SDL event handling not working

一世执手 提交于 2019-12-04 04:16:43
问题 I'm currently learning SDL by reading Lazy foo tutorials. I'm using code blocks 13.12 on Linux. I'm unable to get event handling to work correctly. I'm basically trying to display an image (which works great), but no matter how many times I click on the close button, it won't close Code: #include <SDL2/SDL.h> #include <stdio.h> //Declaring the main window, the main surface and the image surface SDL_Window *window = NULL; SDL_Surface *scrsurface = NULL; SDL_Surface *imgSurface = NULL; SDL

Can't install sdl2 via cabal

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:28:46
问题 I am trying to install helm . When I try to install it, however I get this error: $ cabal install helm Resolving dependencies... Configuring sdl2-1.1.0... cabal: The pkg-config package 'sdl2' version >=2.0.3 is required but it could not be found. Failed to install sdl2-1.1.0 cabal: Error: some packages failed to install: helm-0.6.1 depends on sdl2-1.1.0 which failed to install. sdl2-1.1.0 failed during the configure step. The exception was: ExitFailure 1 When I go to install sdl2 by itself, I

Where can I find the definition of 'SDL_Window'

和自甴很熟 提交于 2019-12-03 22:21:27
I've just started learning SDL2 in Linux. I am reading the very first tutorial from LazyFoo and I see have that code: //The window we'll be rendering to SDL_Window* window = NULL; Where can I find the definition of SDL_Window in order to read about it ? keltar This structure isn't exposed to user side; SDL_video.h file contains forward declaration of it: typedef struct SDL_Window SDL_Window; Forward declaration means you can only use it as pointer type because actual data layout is hidden from you. Actual type struct SDL_Window is currently declared in src/video/SDL_sysvideo.h (in SDL Source

Is SDL Renderer useless if I use opengl for drawing?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 16:42:30
I'm am learning SDL2, but I am also using the imgui library that is using OpenGL calls. From what I read on various blogs online, I can't easily mix SDL2 renderer and opengl calls; I either use one or the other. Most of the tutorials I've read use the renderer, so I do not quite understand how to use SDL2 without the renderer for drawing primitives, or drawing sprites. Take this for example: http://lazyfoo.net/tutorials/SDL/11_clip_rendering_and_sprite_sheets/index.php He creates the sdl renderer: gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED ); Which he then uses to

How to get screen size in SDL

主宰稳场 提交于 2019-12-03 15:05:17
I'm trying to make a program using SDL and C++. How can I get screen's width and height in pixels in SDL?I'm trying to get screen's width not the window's width. . . . In SDL2, use SDL_GetCurrentDisplayMode or SDL_GetDesktopDisplayMode depending on your needs. Usage example: SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); auto Width = DM.w; auto Height = DM.h; On high-DPI displays this will return the virtual resolution, not the physical resolution. From the SDL2 wiki: There's a difference between [ SDL_GetDesktopDisplayMode ()] and SDL_GetCurrentDisplayMode () when SDL runs fullscreen