sdl

SDL2 program only works if Renderer is created with SDL_RENDERER_SOFTWARE

独自空忆成欢 提交于 2019-12-17 17:15:18
问题 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.

What is an SDL renderer?

怎甘沉沦 提交于 2019-12-17 14:58:59
问题 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; }

SDL2学习(一): 显示一张图片

ぃ、小莉子 提交于 2019-12-17 12:54:45
SDL是一个跨平台的多媒体库,它通过OpenGL和2D视频帧缓冲,提供了针对音频、视频、键盘、鼠标、控制杆及3D硬件的低级别的访问接口。这里使用较新的SDL2库。 1. 配置SDL开发环境 1.1 下载SDL开发库 下载地址: http://www.libsdl.org/download-2.0.php ;选择 SDL2-devel-2.0.10-VC.zip 。解压后的目录如下: 1.2 配置环境 使用VS新建一个C++控制台工程,并做如下配置: 将解压后的SDK库拷贝到工程目录下,然后配置VS工程; "C/C++"-->"常规"-->"附加包目录",填入SDL的相对include目录; "链接器"-->"常规"-->"附加库目录",填入SDL的相对lib目录。 "C++"-->"代码生成"-->"运行库",选择"多线程 DLL(/MD)" "链接器"-->"系统"-->"子系统"更改为"窗口" 最后,为了不每次都需要将dll拷贝到exe所在目录,配置"调试"-->"环境",设置为"PATH=sdl/lib/x86;%PATH%",但是要注意如果是直接运行exe,还需要将对应的dll拷贝到和exe一起。 2. 编写代码实现 首先,通过以下代码验证SDL配置成功: #include "SDL.h" #pragma comment(lib, "SDL2.lib") #pragma

How to suppress console output in Python?

强颜欢笑 提交于 2019-12-17 09:36:16
问题 I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its get_hat() method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with SDL_JoystickGetHat value:0: 60 times every second. Is there a way I can disable this? Either through an option in Pygame/SDL or suppress console output while the function calls? I saw no mention of this in the Pygame documentation. edit: This turns out to be due to

How to use SDL2 and SDL_image with cmake

让人想犯罪 __ 提交于 2019-12-17 06:38:10
问题 I'm looking for the simplest way to compile a c++ program using SDL2 and SDL_image with cmake. Here is my best attempt, after hours of searching: CMakeLists.txt project(shooter-cmake2) cmake_minimum_required(VERSION 2.8) set(SOURCES shooter.cpp classes.cpp utils.cpp ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") add_executable(${PROJECT_NAME} ${SOURCES}) INCLUDE(FindPkgConfig) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) PKG_SEARCH_MODULE(SDL2_image REQUIRED sdl2_image) INCLUDE_DIRECTORIES($

OpenGL Scale Single Pixel Line

£可爱£侵袭症+ 提交于 2019-12-17 05:14:15
问题 I would like to make a game that is internally 320x240, but renders to the screen at whole number multiples of this (640x480, 960,720, etc). I am going for retro 2D pixel graphics. I have achieved this by setting the internal resolution via glOrtho(): glOrtho(0, 320, 240, 0, 0, 1); And then I scale up the output resolution by a factor of 3, like this: glViewport(0,0,960,720); window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 960, 720, SDL_WINDOW_OPENGL); I

SDL Saving window as BMP

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-16 18:03:45
问题 I am writing a program in SDL and C and I want to be able to save the window as an image. This is my code: screen = SDL_GetWindowSurface(win); SDL_SaveBMP(screen,"screen"); But when I execute it I get: Segmentation Fault From other sources I gather that its about pointers and memory access. Any help? 回答1: Call SDL_LockSurface on a window surface before saving bitmap, and SDL_UnlockSurface after that. 回答2: SDL_Surface *sshot = SDL_CreateRGBSurface(0, 750, 750, 32, 0x00ff0000, 0x0000ff00,

软考之用例模型

删除回忆录丶 提交于 2019-12-15 15:18:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 用例概念理解 用例模型主要由以下模型元素构成: 参与者(Actor) 参与者是指存在于被定义系统外部并与该系统发生交互的人或其他系统,他们代表的是系统的使用者或使用环境。 用例(Use Case) 用例用于表示系统所提供的服务,它定义了系统是如何被参与者所使用的,它描述的是参与者为了使用系统所提供的某一完整功能而与系统之间发生的一段对话。 通讯关联(Communication Association) 通讯关联用于表示参与者和用例之间的对应关系,它表示参与者使用了系统中的哪些服务(用例),或者说系统所提供的服务(用例)是被哪些参与者所使用的。 这大三种模型元素在UML中的表述如下图所示 通讯关联表示的是参与者和用例之间的关系,箭头表示在这一关系中哪一方是对话的主动发起者,箭头所指方是对话的被动接受者;如果你不想强调对话中的主动与被动关系,可以使用不带箭头的关联实线。在参与者和用例之间的信息流不是由通讯关联来表示的,该信息流是缺省存在的(用例本身描述的就是参与者和系统之间的对话),并且信息流向是双向的,它与通讯关联箭头所指的方向亳无关系。 事件流 用例描述的是参与者与系统之间的对话,对话的细节 用事件流进行描述。 事件流分类 基本事件流 描述正常流程 备选事件流 描述异常终止流程 小结 优点:

Can a function continue after a return statement?

一世执手 提交于 2019-12-14 04:14:49
问题 Consider the following C++ function: SDL_Surface* loadBMP(std::string path, SDL_Surface* loadedBMP){ //Load bitmap SDL_Surface* loadedBMP = SDL_LoadBMP(path); if (loadedBMP == NULL){ printf("Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); } return loadedBMP; //Magic SDL_FreeSurface(loadedBMP); } Now, for the sake of this question, assume that loadedBMP is a previously declared global variable. Here is my question: Is there a way to let a function continue running

SDL2 Invalid renderer on SDL_GetWindowSurface and/or SDL_CreateRenderer on OSX

跟風遠走 提交于 2019-12-14 02:22:32
问题 So I've been playing around with SDL2 to see if it would suit my needs. I was following introductory examples (from lazyfoo mostly) and made a simple test. #include <stdio.h> #include <SDL.h> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int main(int argc, char const *argv[]) { /* The window handle */ SDL_Window* window = NULL; /* The surface contained in the window */ SDL_Surface* screen_surface = NULL; /* Init SDL */ if(SDL_Init(SDL_INIT_VIDEO) < 0) { printf("SDL could not