View Single Post
Old 03-10-2008, 09:39 AM   #1
robinwatts
Junior Member
robinwatts began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2008
Location: Oxfordshire, UK
Device: iRex Iliad
Problems porting GTK apps

Hi all,

I've just been given an iRex Iliad and told to port an app to it. I can't really say what the app is (commerical reasons etc), but suffice to say it works on many different mobile platforms already.

One of the targets for the build is desktop linux using GTK, so I figured it shouldn't be too hard to get up and running.

Sadly, I'm getting very strange results; sometimes the window appears, sometimes it doesn't. When it does appear, sometimes the window is empty, sometimes the contents of the window are shifted around the place.

I've produced a cutdown test app to show the problems I'm experiencing... any hints anyone can give would be gratefully received, cos I'm running out of ideas...

I'm using firmware 2.12, with a copy of the devkit I downloaded the other day. Other apps (such as Gargoyle and Dillo) seem to run fine, just not those I've built myself. Has anyone else experienced such problems?

I attach the text of main.c below, and I compile it using the following script:

Code:
#!/bin/sh

export PKG_CONFIG_PATH=/usr/local/arm/oe/arm-linux/lib/pkgconfig
arm-linux-gcc `pkg-config --cflags gtk+-2.0` main.c -o gtk-test `pkg-config --libs gtk+-2.0` -Wl,-rpath /usr/local/arm/oe/arm-linux/lib
arm-linux-strip gtk-test
Code:
#include "assert.h"

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glib.h>
#include <gdk/gdkx.h>

#define Alien_DisplayWidth 768
#define Alien_DisplayHeight 1024

static void destroy(GtkObject *object,
                    gpointer   data)
{
    gtk_main_quit();
}

int main(int argc, char *argv[])
{
    GtkWidget *topLevel;
    GtkWidget *vbox;
    GtkWidget *dArea = NULL;

    /* Start GTK */
    gtk_set_locale();
    gtk_init(&argc, &argv);

    /* Create a window, set it to full size, and hook up the destroy */
    topLevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(topLevel,
                         Alien_DisplayWidth,
                         Alien_DisplayHeight);
    gtk_signal_connect(GTK_OBJECT(topLevel), "destroy",
                       GTK_SIGNAL_FUNC(destroy), NULL);

    gtk_widget_set_events(topLevel, GDK_EXPOSURE_MASK);

    /* Create a drawable area in that window */
    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(topLevel), vbox);
    dArea = gtk_drawing_area_new();
    gtk_drawing_area_size(GTK_DRAWING_AREA(dArea),
                          Alien_DisplayWidth,
                          Alien_DisplayHeight);
    gtk_box_pack_start(GTK_BOX(vbox), dArea, TRUE, TRUE, 0);

    /* Create the window */
    gtk_widget_realize(topLevel);
    gtk_widget_show_all(topLevel);

    /* Make a bitmap and fill the drawing area with it */
    {
	unsigned char *p;
	int x, y;
        unsigned char *rgbBitmap = calloc(Alien_DisplayWidth*Alien_DisplayHeight, 3);

        if(rgbBitmap == NULL)
        {
            printf("Failed to allocate temporary bitmap!\n");
            exit(1);
        }

        p = rgbBitmap;
        for(y = 0; y < Alien_DisplayHeight; y++)
        {
            for (x = 0; x < Alien_DisplayWidth; x++)
            {
                *p++ = 256*y/Alien_DisplayHeight;
                *p++ = 256*x/Alien_DisplayWidth;
                *p++ = p[-1];
            }
        }
        p = rgbBitmap;
        for (x = 0; x < Alien_DisplayWidth; x++)
        {
            *p++ = 255;
            *p++ = 255;
            *p++ = 255;
        }
        for (y = 1; y < Alien_DisplayHeight; y++)
        {
            *p++ = 255;
            *p++ = 255;
            *p++ = 255;
            p += (Alien_DisplayWidth-2)*3;
            *p++ = 0;
            *p++ = 0;
            *p++ = 0;
        }
        for (x = 0; x < Alien_DisplayWidth; x++)
        {
            *--p = 0;
            *--p = 0;
            *--p = 0;
        }

        gdk_rgb_init();
        gdk_draw_rgb_image(dArea->window,
                           dArea->style->fg_gc[GTK_STATE_NORMAL],
                           0, 0, Alien_DisplayWidth, Alien_DisplayHeight,
                           GDK_RGB_DITHER_NONE,
                           rgbBitmap, Alien_DisplayWidth*3);
    }

    assert( dArea->window != NULL );

    /* MAIN LOOP */
    gtk_main();

    assert( dArea->window == NULL );

    gtk_exit(0);

    return 0;
}
Thanks in advance for any help you can offer!

Robin
robinwatts is offline   Reply With Quote