6
votes

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?

1
Is SDL built trying to use the framebuffer device (/dev/fb...)? Can you set the frame buffer using fbset? - Yann Ramin
I figured it out. The video mode wasn't being set because SDL wasn't initializing properly. I didn't catch the fact that SDL wasn't initializing properly because my code prints an error message only when SDL_Init returns zero, instead of when SDL does not return zero. SDL wasn't initializing because this device has no X server, and no mouse. I set the environment variable SDL_NOMOUSE, and it worked. - jakogut
Glad to hear you solved your own question! Could you please post it as an answer and accept it and remove the "SOLVED" from the subject, which is the norm here. Thanks. - moinudin
I second marcog : Write a detailled answer and accept it as the right one. it could help others. - neuro
Also, once your question has answers posted you'll be able to select one of them as the officially Accepted answer. No need to add indicators like "SOLVED" to the title. - Bill the Lizard

1 Answers

3
votes

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.