无法在嵌入式设备上设置 SDL 屏幕的视频模式

发布于 2024-10-08 09:09:01 字数 1495 浏览 0 评论 0原文

在过去的几天里,我一直在开发一个带有内置屏幕的基于 ARM 的设备(Freescale i.MX27 ADS)。该设备运行的是经过修改的最小 GNU/Linux 系统,没有窗口管理或图形服务器。默认情况下,设备只能运行其附带的一个应用程序。

我以前从未做过任何图形编程,所以这对我来说是一次学习经历。我尝试编写一个简单的 SDL 程序在设备上运行,该程序将读取位图,并将图像显示在嵌入式设备的屏幕上。

我遇到的问题是,无论我尝试什么分辨率、深度或标志,视频模式总是无法应用,而且我什么也得不到。

我知道我的代码不是问题,但无论如何我都会发布它。

#include "SDL/SDL.h"

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_DEPTH 24

int main(int argc, char *argv[])
{
    SDL_Surface *screen;

    if(!SDL_Init(SDL_INIT_VIDEO))
    {
            printf("Unable to initialize SDL.\n");
            return 1;
    }

    // It always fails right here
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
    if(screen == NULL)
    {
            printf("Unable to set video mode.\n");
            return 1;
    }

    SDL_Surface* image;
    SDL_Surface* temp;

    temp = SDL_LoadBMP("hello.bmp");
    if(temp == NULL)
    {
            printf("Unable to load bitmap.\n");
            return 1;
    }

    image = SDL_DisplayFormat(temp);
    SDL_FreeSurface(temp);

    SDL_Rect src, dest;

    src.x = 0;
    src.y = 0;
    src.w = image->w;
    src.h = image->h;

    dest.x = 100;
    dest.y = 100;
    dest.w = image->w;
    dest.h = image->h;

    SDL_BlitSurface(image, &src, screen, &dest);

    printf("Program finished.\n\n");

    return 0;
}

据我所知,应该在此设备上运行的应用程序使用 Qtopia。再说一次,我是图形编程的新手,所以我不知道如何在这样的嵌入式环境中控制图形输出。

有什么想法吗?

I've been hacking away on an ARM based device (Freescale i.MX27 ADS) with a built-in screen for the past few days. The device is running a modified, minimal GNU/Linux system, with no window management or graphical server. By default, the device is only supposed to run the one application that came with it.

I've never done any graphical programming before, so this is a learning experience for me. I tried writing a simple SDL program to run on the device, which would read a bitmap, and display the image on the embedded device's screen.

The problem I'm having is that no matter what resolution, depth, or flags I try, the video mode always fails to apply, and I get nothing.

I know my code isn't the problem, but I'm going to post it anyway.

#include "SDL/SDL.h"

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_DEPTH 24

int main(int argc, char *argv[])
{
    SDL_Surface *screen;

    if(!SDL_Init(SDL_INIT_VIDEO))
    {
            printf("Unable to initialize SDL.\n");
            return 1;
    }

    // It always fails right here
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
    if(screen == NULL)
    {
            printf("Unable to set video mode.\n");
            return 1;
    }

    SDL_Surface* image;
    SDL_Surface* temp;

    temp = SDL_LoadBMP("hello.bmp");
    if(temp == NULL)
    {
            printf("Unable to load bitmap.\n");
            return 1;
    }

    image = SDL_DisplayFormat(temp);
    SDL_FreeSurface(temp);

    SDL_Rect src, dest;

    src.x = 0;
    src.y = 0;
    src.w = image->w;
    src.h = image->h;

    dest.x = 100;
    dest.y = 100;
    dest.w = image->w;
    dest.h = image->h;

    SDL_BlitSurface(image, &src, screen, &dest);

    printf("Program finished.\n\n");

    return 0;
}

From what I can tell, the application that's supposed to run on this device uses Qtopia. Again, I'm new to graphics programming, so I have no idea how one should control graphical output in an embedded environment like this.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-10-15 09:09:01

我的代码隐藏了这样一个事实:问题在于初始化 SDL,而不是设置视频模式。 SDL 没有初始化,因为我的嵌入式系统没有 X 服务器,也没有鼠标。设置SDL_NOMOUSE后,问题解决。

My code was hiding the fact that the problem was with initializing SDL, not setting the video mode. SDL wasn't initializing because my embedded system has no X server, and no mouse. After setting SDL_NOMOUSE, the problem was resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文