Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set video mode for SDL screen on embedded device

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?

like image 972
jakogut Avatar asked Dec 18 '10 05:12

jakogut


1 Answers

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.

like image 153
jakogut Avatar answered Oct 28 '22 00:10

jakogut