我写了一个简单的测试程序,使用KMSDRM
对SDL2
的支持:
#include <SDL.h>
#include <cstring>
#include <iostream>
#include <thread>
#include <SDL_opengles2.h>
using namespace std::chrono_literals;
using std::clog;
using std::endl;
int main()
{
auto init_re = SDL_VideoInit("KMSDRM");
if (init_re != 0)
exit(EXIT_FAILURE);
SDL_Window *window = SDL_CreateWindow("SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
if (nullptr == window)
{
std::cerr << "SDL_CreateWindow(): " << SDL_GetError() << '\n';
exit(EXIT_FAILURE);
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
auto gl = SDL_GL_CreateContext(window);
clog << "create OpenGL context " << gl << endl;
auto make_current_re = SDL_GL_MakeCurrent(window, gl);
clog << "make current ctx returned " << make_current_re << endl;
clog << "OpenGL version: " << (const char *)glGetString(GL_VERSION) << ", GLSL "
<< (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
glClearColor(0.5, 0.5, 0.5, 1.0);
size_t frame_count = 0;
SDL_Event e;
bool should_break = false;
while (!should_break)
{
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
should_break = true;
else if (e.type == SDL_KEYDOWN)
if (e.key.keysym.sym == SDLK_ESCAPE)
should_break = true;
}
frame_count += 1;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
clog << "frame " << frame_count << endl;
std::this_thread::sleep_for(2ms);
}
SDL_GL_DeleteContext(gl);
SDL_DestroyWindow(window);
SDL_Quit();
}
测试程序运行并打印帧计数日志,但未绘制640 x480灰色区域。
KMS是否需要做任何进一步的事情来使其绘制?
此外,它在左上角绘制了一个鼠标指针,这真的出乎我的意料。但指针不随我的鼠标移动。如何让鼠标在KMSDRM
模式下运行?
下面是我运行的system/config:
- 32位Raspbian bullseye,最新更新。
- 为了让世界变得干净,我卸载了整个X服务器。
- SDL 2由apt从Raspbian repo安装。
config.txt
中的相关设置:
dtoverlay=vc4-kms-v3d,composite
max_framebuffers=2
gpu_mem=256
1条答案
按热度按时间mitkmikd1#
我太笨了,忘了在每帧结束时调用交换缓冲区
SDL_GL_SwapWindow(window)
。这就是为什么一切都没有刷新的原因。