嗨,我想知道是否可以简单地用SDL2截取屏幕截图.我试过SDL_GetWindowSurface但是我得到一个错误说:
没有可用的硬件加速渲染器.
我从这里拿了代码.
我想到的另一个解决方案是将纹理转换为表面,但我没有设法做到这一点......
你有什么解决方案吗?
我在使用我的程序停用全屏模式时遇到问题.输入全屏正确,但尝试返回窗口模式不起作用,唯一的效果是光标再次显示.
这是为我重现问题的MCVE/SSCCE:
void ToggleFullscreen(SDL_Window* Window) {
    Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN;
    bool IsFullscreen = SDL_GetWindowFlags(Window) & FullscreenFlag;
    SDL_SetWindowFullscreen(Window, IsFullscreen ? 0 : FullscreenFlag);
    SDL_ShowCursor(IsFullscreen);
}
int main() {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* Window = SDL_CreateWindow("",
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
    bool Exit = false;
    for (SDL_Event Event; !Exit;) {
        SDL_WaitEvent(&Event);
        if (Event.type == SDL_KEYDOWN) {
            switch (Event.key.keysym.sym) {
                case SDLK_f: ToggleFullscreen(Window); break;
                case SDLK_q: Exit = true; break;
            }
        }
    }
    SDL_DestroyWindow(Window);
    SDL_Quit();
}
SDL_SetWindowFullscreen返回0,就像操作成功一样.我究竟做错了什么?(我在OS X 10.10.3上使用SDL 2.0.3.)
我正在使用Visual Studio 2015在64位Windows 10上使用SDL2编写C++项目.我最近购买了一台新的Windows 10笔记本电脑并从github克隆了我的项目.我的项目编译正确,但运行时出现以下错误:
应用程序无法正确启动(0xc000007b).单击"确定"关闭应用程序.
根据我目前的研究,这个错误通常是由加载不兼容的DLL引起的,例如64位版本而不是32位版本.到目前为止我发现的建议包括:
我的项目设置为Win32构建,我确保我使用的是我明确链接的所有DLL的32位版本(libfreetype-6,libpng16-16,SDL2,SDL2_image,SDL2_mixer和SDL2_ttf) .我已确认x86 VC++ Redistributable已安装在我的机器上.
最后,我尝试使用Dependency Walker来确定可能导致问题的DLL(虽然我已经读到了Dependency Walker有很多误报的警告).这些是结果:
在那之后,探查器冻结并且永远不会继续.请注意,SDL组件和VC运行时正在加载而没有错误.
该程序在我的两台旧机器上正确编译和加载,一台运行32位Windows 7,一台运行64位Windows 10.
现在是实际问题.我可以采取哪些其他步骤来调试此崩溃?或者有人从我提供的信息中看到我做错了什么?
相关问题:
正如rflobao建议的那样,我在32位exe上使用了64位版本的Dependency Walker.以下是我的分析运行的新输出:
此时,和以前一样,Dependency Walker冻结了.我仍然完全迷失了,并且不觉得我更接近能够确定导致问题的原因.
一天前我安装了一个SDL2库.它还没有在Debian Wheezy中,所以我使用了configure, make, make install命令.
毕竟,当我尝试使用SDL_Texture时,我收到此错误:
error: forward declaration of ‘SDL_Texture {aka struct SDL_Texture}’
invalid use of incomplete type ‘SDL_Texture {aka struct SDL_Texture}’
在寻找声明后,我发现的所有内容都是SDL_render.h中的这两行:
struct SDL_Texture;
typedef struct SDL_Texture SDL_Texture; 
根本没有定义.我认为我的安装缺少文件SDL_sysrender.h.它是在我下载的源代码中,但不是在SDL2中包含路径.
哪里应该是问题?有必要使用任何标志配置文件?谢谢你的帮助.
使用Cairo可以渲染到SDL_Surface,但我的应用程序使用SDL_Renderer和SDL_Texture来利用2D加速渲染.
我目前正在创建一个SDL_Surface并将其复制到纹理中SDL_CreateTextureFromSurface(),但这个过程很麻烦且可能很慢(尽管它不是瓶颈.)是否有直接的方法来绘制SDL_Texture?
我有一个问题,因为我目前正在Windows 10上运行Ubuntu终端.我还安装了XMing作为我的X服务器(我使用XMing作为qemu等等).我正在尝试运行这个SDL2计划.所以我对main.cpp有这个:
#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <SDL2/SDL.h> 
#include <GL/gl.h> 
int main(int argc, char *argv[]) 
{ 
        int final_status = 1; 
        SDL_Window *window; 
        SDL_GLContext openGL_context; 
        if (SDL_Init(SDL_INIT_VIDEO)) { 
                fprintf(stderr, "Unable to initialize SDL: %s\n", 
                        SDL_GetError()); 
                return 1; 
        } 
        window = SDL_CreateWindow("My Demo", SDL_WINDOWPOS_CENTERED, 
                                  SDL_WINDOWPOS_CENTERED, 640, 480, 
                                  SDL_WINDOW_OPENGL); 
        if (!window) { 
                fprintf(stderr, "Can't create window: %s\n", SDL_GetError()); 
                goto finished; 
        } 
        openGL_context = SDL_GL_CreateContext(window); 
        if (!openGL_context) { 
                fprintf(stderr, "Can't create openGL context: %s\n", 
                        SDL_GetError()); 
                goto close_window; 
        } 
        /* drawing code removed …我希望开发一些使用 SDL2 在 7" RPi 触摸屏上显示图形的代码,但我宁愿不安装完整的桌面操作系统。我已经安装了 Raspbian Buster Lite。一些简单的测试代码在我尝试运行它:
user@rpi4:~/01_hello_SDL $ ./hw
Window could not be created! SDL_Error: Could not initialize EGL
user@rpi4:~/01_hello_SDL $ sudo ./hw
error: XDG_RUNTIME_DIR not set in the environment.
Window could not be created! SDL_Error: Could not initialize EGL
我正在尝试创建窗口
SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL )
我找到了一个帖子,其中引用了有关如何在没有 X 的情况下构建 SDL2 的说明,但我希望有人能教我更多关于 SDL 如何在各种环境中找到显示的信息,以及是否有可能做我想做的事情。
几年前,我使用 SDL 1.2 在运行 Debian 版本的 Beaglebone Black 上制作全屏图形,但我似乎丢失了该安装,并且不记得它是如何设置的。我依稀记得一些关于 fbdev 的问题,它是非加速图形,但这在当时并不重要(虽然我现在想获得加速图形,但这并不重要)。
示例代码:
/*This source code copyrighted …我正在尝试在 Xcode 11.2.1 上使用 SDL2 和 C++ 制作一个简单的游戏;但是,我的进度因错误而停止。
遇到这些错误所需要的只是初始化 SDL。只是调用这个函数会导致程序崩溃:
SDL_Init(SDL_INIT_EVERYTHING);
给出这些错误:
Westerino[16795:847932] Metal API Validation Enabled
Westerino[16795:848288] flock failed to lock maps file: errno = 35
Westerino[16795:848288] flock failed to lock maps file: errno = 35
Westerino[16795:847932] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x102157f00> F8BB1C28-BAE8-11D6-9C31-00039315CD46
Westerino[16795:847932]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Westerino[16795:847932]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
我尝试清除缓存、清理构建、删除首选项、重新安装框架等,但还没有任何帮助。
当我更新 Xcode 时,这些问题似乎已经开始,但我无法确认。
刚刚从SDL1.2跳转到SDL2,转换了我的代码,但无法弄清楚如何调整窗口大小.这是我现在的代码:
SDL_DestroyWindow(Window);
Window = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenSizeX, ScreenSizeY, SDL_WINDOW_SHOWN);
screen = SDL_GetWindowSurface(Window);
你可以看到只是破坏窗口并创建一个新窗口.邋but但它的工作原理.我想要的只是调整窗口大小,是否可能?
   #include "SDL2/SDL.h"
   int main(int argc, char* args[])
   {
       SDL_Init(SDL_INIT_EVERYTHING);
       SDL_QUIT();
       return 0;
  }
我已经通过debian存储库安装了SDL2,我正在运行
g++ -o test.cpp a.out -lSDL2 
我收到了很多错误:
a.out:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
a.out: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o:(.data+0x0): first defined here
a.out: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
a.out: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
a.out: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined …sdl-2 ×10
c++ ×8
sdl ×5
linux ×3
cairo ×1
debian ×1
dll ×1
framebuffer ×1
fullscreen ×1
g++ ×1
glx ×1
macos ×1
raspbian ×1
screenshot ×1
window ×1
windows-10 ×1
windows-subsystem-for-linux ×1
xcode ×1