GP2X Beginner's Request


nickspoon

vultum stultum habes
Joined
Nov 4, 2005
Messages
4,234
Age
32
Location
Essex, UK
Website
Visit site
I've noticed quite a lot of people on the forums (including me) want to get started with GP2X coding, but have no idea how.

So, could somebody who has some experience please make:
A guide to setting up your system for GP2X coding.
A guide to compiling for a GP2X.
A sample program or two (Button Test, Hello World, etc.)

Anyone who feels anything else is needed, feel free to add.

Thanks in advance.
 
theres a gp2x wiki around that should help

and guyfawkes has just made a guidey tingy
 
Well, I just recently checked the wiki, and the closest it comes to that is telling you how to set up different environments to compile SDL programs for the PC... I guess it doesn't help that there is no mature devkit or anything yet... For now there is WinterMutes current release of DevkitGP2X (which I'm still trying to figure out ;)). If you know how to use that you may well be cooking :).

And emuholics.com appeared to be down when I tried the link to GuyFawkes user guide... but from its name alone ("users" rather than "developers" guide) I wouldn't have thought it would have information for developing?
 
I'm also trying to figure out DevKitGP2X.

I'd also like to know exactly what to do to display SDL output and read input from the buttons, if anyone knows how to do that.
 
Same here. Well, sort of... I've managed to install WinterMute's DevKit (btw, thanks very much for your work) in XP following the instructions on DevKit's website and I've already compiled my game through MSys, but it doesn't want to link because of SDL (doesn't find SDL_main, SDL_Quit, etc., even though Makefile points to the folder where the libraries are). I don't remeber where did I get SDL for GP2X from but I guess they are not the right ones...
 
Add me to the list of people who would like to see a dev begginers guide.

I have been writting alot of code based in SDL using Dev-C++ but I can't seem to get the same code to compile using WM's DevKitPro.

I created a new compiler config in Dev-C++ by doing the following:

-Tools>Compiler Options...
-I made a new compiler config then went to the "Programs Tab"
-I changed "gcc.exe" to "MY_PATH_TO\arm-linux-gcc.exe"
-I changed "g++.exe" to "MY_PATH_TO\arm-linux-g++.exe"

I left the make.exe 'as is' because I wasn't sure which binary was the arm-linux-make.exe supplied with devKitGP2x.

After changing these files and making sure that this is the compiler config for my project... all files seem to compile... but my output is still *.exe not *.gpe.....

Anyways... I still don't have my GP2X because lik-sang.com still haven't got their shipment in.... and now it looks like they are waiting for Version 2 to be release before they start shipping them out.... not happy... I can't wait until Q1 2006 for my GP2x..... :(

Anyways... let me know if I am doing it right or wrong or whatever... I really would like to port my new game over to gp2x.

EDIT: I DO realise I have to re-compile SDL for arm-linux, but I really am not sure if I will benefit from this ATM as my GP2X is so far away.... i just need to know if what I have done is going to work when I DO need it.
 
-Tools>Compiler Options...
-I made a new compiler config then went to the "Programs Tab"
-I changed "gcc.exe" to "MY_PATH_TO\arm-linux-gcc.exe"
-I changed "g++.exe" to "MY_PATH_TO\arm-linux-g++.exe"

I'm not using Dev-C++ but a plain Makefile (well, in fact, it's Code::Blocks what I'm working with, but in order to compile it for GP2X through MSys I generated a Makefile by hand). But my guess is that you should also change the include and library paths so that they point to DevKit's ones ("include" and "lib" under "devkitGP2X").
 
Last edited by a moderator:
On the GP32 SDL there is no libSDL_Main, just libSDL, libSDL_image, etc. So when compiling on GP32, I have to omit -lSDL_Main, then it compiles. Dunno about GP2X and SDL_Quit, but perhaps its a similar situtation.
 
On the GP32 SDL there is no libSDL_Main, just libSDL, libSDL_image, etc. So when compiling on GP32, I have to omit -lSDL_Main, then it compiles. Dunno about GP2X and SDL_Quit, but perhaps its a similar situtation.
I tried it but I got the same results. Thanks anyway. In fact, I realised that after the compilation process, which works, the first error is non-SDL related (or that's what I understand):

Code:
MY_PATH_TO_DEVKITPRO/devkitgp2x/bin/../sysroot/usr/lib/crt1.o: In function `_start':
../sysdeps/arm/elf/start.S:94: undefined reference to `main'
...which, of course :(, I have no clue about how to solve it...

Just in case, here is my Makefile. It works on Linux (using proper paths).

Code:
CC=arm-linux-g++
CFLAGS=-c -Wall -IMY_PATH_TO_DEVKITPRO/devkitGP2X/include -Dmain=SDL_main
LDFLAGS= -LMY_PATH_TO_DEVKITPRO/devkitGP2X/lib -lSDLmain -lSDL -lSDL_image -lSDL_mixer
SOURCES=Tilematch.cpp Motor.cpp MotorTilematch.cpp Peca.cpp Puntuacions.cpp Text.cpp Cursor.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=Tilematch.gpe

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
	$(CC) $(CFLAGS) $< -o $@

Edit: I've just noticed that removing the -Dmain=SDL_main from the compiler flags makes the ../sysdeps/arm/elf/start.S:94: undefined reference to `main' disappear. But I still get the SDL undefined references...
 
Last edited by a moderator:
-Tools>Compiler Options...
-I made a new compiler config then went to the "Programs Tab"
-I changed "gcc.exe" to "MY_PATH_TO\arm-linux-gcc.exe"
-I changed "g++.exe" to "MY_PATH_TO\arm-linux-g++.exe"

I'm not using Dev-C++ but a plain Makefile (well, in fact, it's Code::Blocks what I'm working with, but in order to compile it for GP2X through MSys I generated a Makefile by hand). But my guess is that you should also change the include and library paths so that they point to DevKit's ones ("include" and "lib" under "devkitGP2X").

I have changed the lib and include directories under dev-c++ so that they are using the devkitgp2x dirs (they do however fallback on the originals if need be).

I can get simple code to compile, such as HelloWorld examples etc... but the output is still *.exe shouldn't it be *.gpe ???? If so then I guess that my setup is still not working.
 
Last edited by a moderator:
but the output is still *.exe shouldn't it be *.gpe ????

No, I'm sure someones mentioned this already, IIRC. The binary ought to be fine, just replace .exe with .gpe.

do the binaries produced work under windows though? If so then something is definitely wrong...

@Timbobsteve: ah, that's how you set up a new compiler with Devcpp? excellent! :)
 
I've tried to get this up and running as well, and thanks to the posts here, I have something that now compiles, links, and attempts to run but doesn't do anything <_<

I followed Timbobsteve's description for setting up a new compiler in Devcpp, and downloaded the SDL libraries from http://gp2x.org/gp2x/libs/ which is posted on the wiki.

I then compiled the code from the wiki (with slight modification to show more pixels):
Code:
#include "SDL.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8

int main(int argc, char *argv[]) {
     SDL_Surface *screen;
     Uint8       *p;
     int         x = 10; //x coordinate of our pixel
     int         y = 20; //y coordinate of our pixel
     
     /* Initialize SDL */
     SDL_Init(SDL_INIT_VIDEO);
     
     /* Initialize the screen / window */
     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
     
     for(int iy = 0; iy < 10; iy++)
     {
         for(int ix = 0; ix < 10; ix++)
         {
             /* Make p point to the place we want to draw the pixel */
             p = (Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel;
             
             /* Draw the pixel! */
             *p=0xff;
         }
     }
     
     /* update the screen (aka double buffering) */
     SDL_Flip(screen);
     while(1);
}

The makefile created by Devcpp is
Code:
# Project: Testing
# Makefile created by Dev-C++ 4.9.9.2

CPP  = arm-linux-g++.exe
CC   = arm-linux-gcc.exe
WINDRES = windres.exe
RES  = 
OBJ  = main.o $(RES)
LINKOBJ  = main.o $(RES)
LIBS =  -L"C:/Dev-Cpp/devkitGP2X/lib" -L"C:/Dev-Cpp/lib" -lSDLmain -lSDL -lSDL_image -lSDL_mixer  
INCS =  -I"C:/Dev-Cpp/devkitGP2X/include"  -I"C:/Dev-Cpp/include" 
CXXINCS =  -I"C:/Dev-Cpp/devkitGP2X/lib/gcc/arm-linux/4.0.2/include"  -I"C:/Dev-Cpp/devkitGP2X/include/SDL"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2/backward"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2/arm-linux"  -I"C:/Dev-Cpp/devkitGP2X/include/c++/4.0.2"  -I"C:/Dev-Cpp/devkitGP2X/include"  -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include" 
BIN  = Testing.gpe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS)  
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Testing.gpe all-after


clean: clean-custom
	${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CPP) $(LINKOBJ) -o "Testing.gpe" $(LIBS)

main.o: main.cpp
	$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

All I get on the GP2X is a blank screen.

Hope this helps someone help me :D
 
#define SCREEN_DEPTH 8
The GPH version of SDL doesn't support 8 bit screens, only 16 bit.

Thanks for that info, and I've now modified the code to
Code:
#include "SDL.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 16

#ifdef WIN32
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	int argc = 1;
	char *argv[1] = {"Testing"};
#else
int main(int argc, char *argv[])
{
#endif
	SDL_Surface *screen;
	Uint16       *p;
	int         x = 10; //x coordinate of our pixel
	int         y = 20; //y coordinate of our pixel

	/* Initialize SDL */
	SDL_Init(SDL_INIT_VIDEO);

	/* Initialize the screen / window */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);

	for(int iy = 0; iy < 10; iy++)
	{
  for(int ix = 0; ix < 10; ix++)
  {
  	/* Make p point to the place we want to draw the pixel */
  	p = (Uint16 *)((Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel);
         
  	/* Draw the pixel! */
  	*p=0xffff;
  }
	}

	/* update the screen (aka double buffering) */
	SDL_Flip(screen);
#ifdef WIN32
	while(!GetAsyncKeyState(VK_ESCAPE));
#else
	while(1);
#endif

	return 0;
}

Unfortunately, this still shows just a blank screen on the GP2X, although it shows a nice little window when running it on XP :D

EDIT:If someone who does have the toolchain working can test my code on the GP2X that'd be a great help - at least then we'd know if its a code or compile/link error
 
Last edited by a moderator:
Hmmm, looks like I was wrong about 8bit not being supported (I'm sure that didn't work last time I tried it :blink:). Both your 8bit and 16bit code work fine for me and produce a small white box in the top left corner (and also the mouse cursor is in the top left corner because you've forgotten to turn it off). However, looking at your makefile I'd assume you're trying to use the libs on the device and not the ones you've downloaded, which won't work as the libs on the device require the app to be compiled using gcc 2.95 and you're using 4.0.2. Change '$(CPP) $(LINKOBJ) -o "Testing.gpe" $(LIBS)' to ' $(CPP) -static $(LINKOBJ) -o "Testing.gpe" $(LIBS)' and give that a try.
 
Hmmm, looks like I was wrong about 8bit not being supported (I'm sure that didn't work last time I tried it :blink:). Both your 8bit and 16bit code work fine for me and produce a small white box in the top left corner (and also the mouse cursor is in the top left corner because you've forgotten to turn it off). However, looking at your makefile I'd assume you're trying to use the libs on the device and not the ones you've downloaded, which won't work as the libs on the device require the app to be compiled using gcc 2.95 and you're using 4.0.2. Change '$(CPP) $(LINKOBJ) -o "Testing.gpe" $(LIBS)' to ' $(CPP) -static $(LINKOBJ) -o "Testing.gpe" $(LIBS)' and give that a try.

Yup, that does it, thanks a lot. Hope this also helps others get the toolchain working.

Now, how do I switch off the mouse pointer? lol
Ok, so I'm an SDL n00b :p

EDIT:Can't seem to find the max bitdepth for the gp2x on the wiki/faq/specs, but 32 bit compiled and ran fine - is this just choosing the closest matching 16bit colour, or is it 32(24 with 8bit alpha?)???
 
Last edited by a moderator:
What libs do you use and where do you get them? Are they standard SDL or modified for the 2X?
Look further up this thread, I posted the link, but here it is again for good measure :D
http://gp2x.org/gp2x/libs/


In answering my own question about bitdepth, I added this code in to check the variances in red, green, and blue:
Code:
	for(int iy = 0; iy < 20; iy++)
	{
  for(int ix = 0; ix < 256; ix++)
  {
  	/* Make p point to the place we want to draw the pixel */
  	p = (Uint32 *)((Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel);
         
  	/* Draw the pixel! */
  	*p= ix << 16;
  }
	}
	for(int iy = 30; iy < 50; iy++)
	{
  for(int ix = 0; ix < 256; ix++)
  {
  	/* Make p point to the place we want to draw the pixel */
  	p = (Uint32 *)((Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel);
         
  	/* Draw the pixel! */
  	*p= ix << 8;
  }
	}
	for(int iy = 60; iy < 80; iy++)
	{
  for(int ix = 0; ix < 256; ix++)
  {
  	/* Make p point to the place we want to draw the pixel */
  	p = (Uint32 *)((Uint8 *)screen->pixels + (y+iy) * screen->pitch + (x+ix) * screen->format->BytesPerPixel);
         
  	/* Draw the pixel! */
  	*p= ix;
  }
	}

Yeah, I know I could do it more efficiently, but it works good enuff for me :)
Anyway, if you manage to get this running on the device, you should be able to see quite clearly, different bands within the gradients instead of a smooth gradient of 24bit colour. So it's 16bit, and the green has smaller bands, so looks like the format is 565. I know you gurus will probably already know that, but for us n00bs, it might be handy if it was actually posted so we know <--- and now it is :D
 
Last edited by a moderator:
Yup, that does it, thanks a lot. Hope this also helps others get the toolchain working.
Ok. I've installed Dev-C++, changed paths and compilers, created a project which contains your main.cpp, changed the Makefile.win so that it matches yours and renamed to Makefile, compiled using command line and... worked! Thanks!

But... Even though in your Makefile there are references to SDL_mixer and SDL_image, your code obviously doesn't use them (just try removing " -lSDL_image -lSDL_mixer" from LIBS and it will make no difference). But the game I've finished and I'm trying to compile for GP2X does. When I call make, it works until it finds thousands of undefined references like this:

Code:
C:/Informatica/devkitPro/devkitGP2X/lib\libSDL_image.a(IMG_bmp.o): In function `
IMG_LoadBMP_RW':
IMG_bmp.c:(.text+0xa4): undefined reference to `SDL_LoadBMP_RW'
C:/Informatica/devkitPro/devkitGP2X/lib\libSDL_image.a(IMG_jpg.o): In function `
jpeg_SDL_RW_src':
IMG_jpg.c:(.text+0x38c): undefined reference to `jpeg_resync_to_restart'
C:/Informatica/devkitPro/devkitGP2X/lib\libSDL_image.a(IMG_jpg.o): In function `
IMG_LoadJPG_RW':
IMG_jpg.c:(.text+0x404): undefined reference to `jpeg_std_error'
IMG_jpg.c:(.text+0x444): undefined reference to `jpeg_destroy_decompress'
IMG_jpg.c:(.text+0x478): undefined reference to `jpeg_CreateDecompress'
IMG_jpg.c:(.text+0x498): undefined reference to `jpeg_read_header'
IMG_jpg.c:(.text+0x4b4): undefined reference to `jpeg_calc_output_dimensions'
IMG_jpg.c:(.text+0x524): undefined reference to `jpeg_start_decompress'
IMG_jpg.c:(.text+0x564): undefined reference to `jpeg_read_scanlines'
IMG_jpg.c:(.text+0x580): undefined reference to `jpeg_finish_decompress'
IMG_jpg.c:(.text+0x58c): undefined reference to `jpeg_destroy_decompress'

Any ideas? What am I doing wrong? It clearly seems like it's related to SDL_image and SDL_mixer... Thanks in advance.

Now, how do I switch off the mouse pointer? lol
Ok, so I'm an SDL n00b :p
Just use SDL_ShowCursor(SDL_DISABLE).
 
Last edited by a moderator:
For anybody else that, like me, was having difficult creating a working program for the GP2X, I have coded a very simple framework.

http://dstobbs.evogame-dev.co.uk/very_basi...x_framework.zip

I've put in a basic structure for compiling with VS .NET for windows, or using Dev-CPP for the gp2x (or you can use the makefile with any other toolchain). Just update the paths the project uses to the appropriate paths on your system.

I hope this helps some of you, and if there's still any linker problems, I'll try and help out if I can (but I'm a n00b so don't expect too much :p ).
 
Back
Top