New To Sdl


Vynx

Member
Joined
May 1, 2006
Messages
253
Right, I really want to get into writing games for the GP2X, and I've taken a look at some SDL tutorials and I didn't have any problems with understanding them, but a few of my questions remain unanswered, i'm sorry if they seem incredibly newbish, but we all have to start somewhere, right? I'm a quick learner, but without the material to learn what I need, I have to resort to these slightly embarassing threads ;)

I'm just lucky I got into C++ 2 years ago, so I don't need any help with the basics of that.

For reference, i'm using the windows GP2X SDK.

1: How do I create an app specifically for the GP2X? Not an exe, but a .gpe that will work - is there much to do in making an SDL app GP2X compatible? Other than the obvious things like screen resolution.

2: My only source for tutorials is http://lazyfooproductions.com/SDL_tutorials/index.php, could someone recommend others? Preferably for a newbie like myself. Books arn't out of the question, if they're useful.

3: Displaying text. I understand the SDL function that does this, but what if I wanted to display pages of text? How would I even begin to do that in SDL? Would I need to redirect Cout, or create an entirely new function to do so? Or is there a way of using this function to do this task? I've taken a look at SDL_ttf documentation, but I found it pretty baffling.

Thankyou for your time :)
 
(not awnsering to 1 because of lack of GP2x yet)

2) Those tutorials seem pretty nice. But I found the best learning tool is to try, try to make something and you'll learn 100x more then by reading tutorials in the same time. Ofcourse you need some help to get started. But the more you figure out yourself, the less you have to lookup again and again.

3) the TTF library makes nice text, but it needs font files and stuff. I usualy go for a basic bitmap font:
http://daid.mine.nu/pub/TinyFont.bmp
And a small snippet of code:
Code:
int DrawText(SDL_Surface* Surface, int X, int Y, char* Text)
{
	SDL_Rect Src;
	SDL_Rect Dest;
	while(*Text)
	{
		Src.x = ((*Text) & 0xF) * 6;
		Src.y = (((*Text) >> 4) - 2) * 8;
		Src.w = 6;
		Src.h = 8;
		Dest.x = X;
		Dest.y = Y;
		SDL_BlitSurface(Font, &Src, Surface, &Dest);
		Text++;
		X += 6;
	}
	return X;
}
(Note that Font is a global SDL_Surface and should be loaded from a the bmp, and freed at the program exit)
 
For reference, i'm using the windows GP2X SDK.

1: How do I create an app specifically for the GP2X? Not an exe, but a .gpe that will work - is there much to do in making an SDL app GP2X compatible? Other than the obvious things like screen resolution.
Not too sure about how the Windows setup is, but all a .gpe (and .gpu) is, is an executable file (or bash script,) Linux itself doesn't care about extensions, they're just naming conventions. Simply rename the output file, or set it with "-o myprog.gpe" in the linking phase (assuming the Windows SDK uses gcc.)
Other than that, as long as you work around things like no mouse or keyboard (although I've got working mouse support in my HW SDL, joystick and keyboard are being worked on - you just need a USB host cable or BoB to attach one.)
The GP2X's menu system will only list .gpe files from the games option, and only .gpu from the utilities menu. It also runs them differently in that when you select a .gpe the menu program quits and has to be explicitly started by the .gpe when it finishes. Whereas a .gpu will return to the menu automatically when it finishes.
2: My only source for tutorials is http://lazyfooproductions.com/SDL_tutorials/index.php, could someone recommend others? Preferably for a newbie like myself. Books arn't out of the question, if they're useful.
There are quite a few tutorials out there, I just don't know where - I started using it 12+ years ago.
I keep meaning to do a guide to show how to get the basics up and running along with how to do the equivalent by hitting the hardware directly. There are a few things that people commonly do wrong (or not in the best way for the GP2X) that isn't noticable on PC versions (i.e. HW surfaces), where the limited resources of the GP2X can make things worse. Maybe I should at least get that written as a start...
3: Displaying text. I understand the SDL function that does this, but what if I wanted to display pages of text? How would I even begin to do that in SDL? Would I need to redirect Cout, or create an entirely new function to do so? Or is there a way of using this function to do this task? I've taken a look at SDL_ttf documentation, but I found it pretty baffling.
With SDL, as any other graphics library, text is essentially bitmaps drawn side-by-side. There isn't really any concept of a page or starting a new line when you go off the right, you have to handle all that yourself. SDL_ttf handles converting character strings and freetype fonts into bitmaps of text, but you then have to deal with things like variable-width fonts and font styles etc. The easist is as Daid said above, have one big bitmap with all the ascii characters on it in a grid, and blit the small rectangles as needed. You'll still have to deal with placing characters at the right place and scrolling up/down if you need to, but it's not complicated and there's tons of example code for formatting and such like floating around.
 
Last edited by a moderator:
I'm in the same position as you Vynx, having gone through the Lazy Foo tutorials, I'm not having a look at this nice tutorial:
http://jnrdev.72dpiarmy.com/
which takes you through a nice little platform game.

Thankyou everyone for the replies, it's helped :)

I'll start getting into the nitty gritty of coding my own text display function this weekend, it'll be a good place to start :)
 
Last edited by a moderator:
Back
Top