Text output using SDL

Hi all!

Need help showing text on the screen. More specifically, trying to create a score board that changes each time an event occurs (eg. a bmp hits another bmp and records the number of hits).

Thanks!

Richard---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

SFont. DFont and many other libraries have image based font support.
SDL-ttf also exists.On Sunday, March 24, 2002, at 11:22 AM, Richard Perrine wrote:

Hi all!

Need help showing text on the screen. More specifically, trying to
create a score board that changes each time an event occurs (eg. a bmp
hits another bmp and records the number of hits).

Thanks!

Richard

Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

Need help showing text on the screen. More specifically, trying to
create a score board that changes each time an event occurs (eg. a bmp
hits another bmp and records the number of hits).

http://www.libsdl.org/projects/SDL_ttf/index.html

–ryan.

At 09:22 24.03.2002 -0800, you wrote:

Hi all!

Need help showing text on the screen. More specifically, trying to
create a score board that changes each time an event occurs (eg. a bmp
hits another bmp and records the number of hits).

Maybe you should just think about it for more than 10 seconds … if you
really are a programmer, then you’ll find help yourself within 5 minutes
(Just a hint: take a sheet of paper and a pencil and then continue
thinking).
No Regards,
St0fF.

P.S.: If you can’t find a solution to easy problems like this, what will
you do when you reach a real problem?

Thanks!

Richard

Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy AwardsA®

Thanks St0ff!
It’s a good thing that there are people out there who are more than happy to show us BEGINNERS to programming how to become more appreciative of the art of programming. I became aware of SDL only a week or so ago. Once again St0ff, I AM NEW TO PROGRAMMING and am happy to say that I have learned much from many others who have been gracious in giving someone like me a decent chance in learning SDL. We’re not all seasoned programmers and speaking for myself, would like to become one some day.
I’m asking for help. If you’re not interested in giving it, please (St0ff), refrain from such condescending comments. For the rest of you in the SDL world: THANK YOU VERY MUCH.
richard
St0fF 64 wrote: At 09:22 24.03.2002 -0800, you wrote:

Hi all!

Need help showing text on the screen. More specifically, trying to create a score board that changes each time an event occurs (eg. a bmp hits another bmp and records the number of hits).
Maybe you should just think about it for more than 10 seconds … if you really are a programmer, then you’ll find help yourself within 5 minutes (Just a hint: take a sheet of paper and a pencil and then continue thinking).
No Regards,
St0fF.

P.S.: If you can’t find a solution to easy problems like this, what will you do when you reach a real problem?

Thanks!

Richard

Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards? _______________________________________________ SDL mailing list SDL at libsdl.org http://www.libsdl.org/mailman/listinfo/sdl---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

Here’s some actual help:

SDL does’nt have any text functions natively so you’ll need to use a
library. The most flexible is SDL_ttf but it is a bit complicated
one, simpler libraries include dfont, sfont (all those on the
libsdl.org libraries page) or my own KBF_Lite
(http://kokido.sf.net/KBFLite.html)

Richard Perrine wrote:

Thanks St0ff!
It’s a good thing that there are people out there who are more than happy
to show us BEGINNERS to programming how to become more appreciative of the art
of programming. I became aware of SDL only a week or so ago. Once again St0ff,
I AM NEW TO PROGRAMMING and am happy to say that I have learned much from many
others who have been gracious in giving someone like me a decent chance in
learning SDL. We’re not all seasoned programmers and speaking for myself,
would like to become one some day.
I’m asking for help. If you’re not interested in giving it, please (St0ff),
refrain from such condescending comments. For the rest of you in the SDL
world: THANK YOU VERY MUCH.
richard
St0fF 64 wrote: At 09:22 24.03.2002 -0800, you wrote:

Hi all!

Need help showing text on the screen. More specifically, trying to create a
score board that changes each time an event occurs (eg. a bmp hits another bmp
and records the number of hits).
Maybe you should just think about it for more than 10 seconds … if you
really are a programmer, then you’ll find help yourself within 5 minutes (Just
a hint: take a sheet of paper and a pencil and then continue thinking).
No Regards,
St0fF.

P.S.: If you can’t find a solution to easy problems like this, what will
you do when you reach a real problem?

Thanks!

Richard

Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
_______________________________________________ SDL mailing list
SDL at libsdl.org http://www.libsdl.org/mailman/listinfo/sdl>


Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?

Maybe you should just think about it for more than 10 seconds … if you
really are a programmer, then you’ll find help yourself within 5 minutes
(Just a hint: take a sheet of paper and a pencil and then continue
thinking).
No Regards,
St0fF.

That was kind of a dick thing to say.

I get frustrated sometimes, but I try to not answer FAQs then. If I’m
curt, I at least try to put up a URL with more info.

–ryan.

Maybe you should just think about it for more than 10 seconds … if you

That was kind of a dick thing to say.

Yeah… and the HTML message really
impressed /me/, too :^P

-bill!On Sun, Mar 24, 2002 at 11:00:17PM -0500, Ryan C. Gordon wrote:

At 23:00 24.03.2002 -0500, you wrote:

Maybe you should just think about it for more than 10 seconds … if you
really are a programmer, then you’ll find help yourself within 5 minutes
(Just a hint: take a sheet of paper and a pencil and then continue
thinking).

These words in parentheses were the best help a beginner can get! Those
really old coder-buddies will tell you it’s true.

No Regards,
St0fF.

That was kind of a dick thing to say.

I surely know, but when I remembered how I got started in programming …
it was in '95, I got a C=64 as a present and what did I do, I didn’t have a
clue.
I started entering those programmes from the C=64-manual to get a plain
overview about what may be possible. Then I read a book on
6502-programming to get in touch with the ML-commands there. Anything that
came later I tought myself - taking a sheet of paper, “rendering” some
pseudo-code to have a written version of the algorithms and even making
some drawings.
I think if a beginner doesn’t start like this he won’t get too far, and,
especcially he won’t experience the real secrets of coding.
And, hey, what’s so difficult copying a font into an image, loading this
image via SDL_image, defining the top-left and bottom-right positions of
each symbol inside a textfile and reading this textfile into a structure of
symbols, then creating some functions that copy a letter from the loaded
surface into the display surface at the right position? Ok, now I helped.

<I AM NEW TO PROGRAMMING and am happy to say that I have learned much from
many
<others who have been gracious in giving someone like me a decent chance in
<learning SDL
Well, when I was a BEGINNER, I didn’T have this kind of overestimated
ideals. I was happy to have learned how to get stable rasterbars by
myself, after about a quarter of a year! Trial and Error! Divide and
Rule! If you haven’t heard of those statements, have some thoughts about it!
And by the way, the “decent chance” of “learning SDL” (I’d say “learning
how to use SDL”) is given to everyone by Matthias Edelgard via the docs.

I get frustrated sometimes, but I try to not answer FAQs then. If I’m
curt, I at least try to put up a URL with more info.

You are right, ryan! But I don’t think that it really helps to take some
code, partly understand it, and then partly copying it and modifying it to
fit one’s own needs.
St0fF.

Do you realy believe everyone should reinvent the wheel all the time? Did you
write your own OS, windowing system, hardware drivers or even SDL? I think it
is realy useful for novice programmers (like myself) to try and think up
their own systems for collision detection, drawing fonts, interfacing with
the user, timing the audio, etc. It is fun to do so, but i am sure that when
my first project is finished a lot of things are far less efficient than they
could have been by using already evolved and optimized code from others. I
think the only way in which software development can advance is reuse of code
(this is, i think, the opinion of every sane programmer). Thus, people just
entering the development community should be encouraged to invent their own
algorithms, but at the same time also to learn how to reuse code of other
people. Both skills are essential for productivity. The most important point
i would like to make is that if you still feel that it is important to tell
people to invent their own code (which probably is a good idea at times) you
could do so in a more friendly manner. That way new people might actually
stay on the list to learn something from you.

MattijsOn Monday 25 March 2002 04:45, you wrote:

You are right, ryan! ?But I don’t think that it really helps to take some
code, partly understand it, and then partly copying it and modifying it to
fit one’s own needs.
St0fF.

Maybe you should just think about it for more than 10 seconds … if you
really are a programmer, then you’ll find help yourself within 5 minutes
(Just a hint: take a sheet of paper and a pencil and then continue
thinking).
No Regards,
St0fF.

That was kind of a dick thing to say.

I get frustrated sometimes, but I try to not answer FAQs then. If I’m
curt, I at least try to put up a URL with more info.

I’d even add, REAL PROGRAMMERS know how to use Google.

http://www.libsdl.org/pipermail/sdl/2002-March/043492.html

This question exactly deserved the same answer, if not worse.

Alex.–
http://www.gnurou.org

At 12:42 25.03.2002 -0500, you wrote:

You are right, ryan! But I don’t think that it really helps to take some
code, partly understand it, and then partly copying it and modifying it to
fit one’s own needs.
St0fF.

Do you realy believe everyone should reinvent the wheel all the time?

No. But beginners should start to learn how to code - meaning how to
translate some algorithm (formulated in any way) into a language that the
computer understands. After you learned it, you shouldn’T always reinvent
the wheel (why should you?).

Did you
write your own OS, windowing system, hardware drivers or even SDL?

Well, Yes! I developed AcidTrackMusicDevelopmentSystem on the Commodore 64
(This is a combination of windowing-system and sound-hardware-driver). I
did this because all those C=64-Trackers had their own good points, but
none of them combined all the very good and important Features in one and
was actually optimized enough to meet some people’s needs (The best players
were too slow). So I wrote down a lot and spent 2.5 years evolving ATMDS
to Version 3.2 . Now ATMDS is the C=64-Tracker with most features compared
to the least rastertime-consume. And you know what? This actually made me
a programmer! (I know this sounds kinda arrogant)

I think it
is realy useful for novice programmers (like myself) to try and think up
their own systems for collision detection, drawing fonts, interfacing with
the user, timing the audio, etc. It is fun to do so, but i am sure that when
my first project is finished a lot of things are far less efficient than they
could have been by using already evolved and optimized code from others. I

You’re right! But at first creating an own solution to a problem actually
teaches you most.

think the only way in which software development can advance is reuse of code
(this is, i think, the opinion of every sane programmer). Thus, people just
entering the development community should be encouraged to invent their own
algorithms, but at the same time also to learn how to reuse code of other
people. Both skills are essential for productivity.

You tell me what I think (except that I say from myself that I’m insane in
some way)…

The most important point
i would like to make is that if you still feel that it is important to tell
people to invent their own code (which probably is a good idea at times) you
could do so in a more friendly manner. That way new people might actually
stay on the list to learn something from you.

… but if a question sounds like someone doesn’t read the manuals and
doesn’t make up his/her own mind at first, then I normally react that
way. It is a method to make somebody aware of what you just wrote 2
paragraphs above. And if the problem is as easy as I explained within
4(!!!) lines in my last post, then I guess the person wasn’t aware of that
thinking could solve a problem quicker than getting someone else’s
code. In this case the primary question was either misplaced or this guy
thought asking would be easier than reading (I know there’s a link to
SDL_ttf @ libsdl.org).
Best wishes,
St0fF.>On Monday 25 March 2002 04:45, you wrote:

(this is, i think, the opinion of every sane programmer). Thus, people
just
entering the development community should be encouraged to invent their
own
algorithms, but at the same time also to learn how to reuse code of other
people. Both skills are essential for productivity. The most important
point

I think it’s important for new developers to learn how to use existing work,
develope their own work, and learn how to use a web search engine to try and
find their own answers instead of running to people for help first. It
seems like this last one is the hardest for new developers to learn.

i would like to make is that if you still feel that it is important to
tell
people to invent their own code (which probably is a good idea at times)
you
could do so in a more friendly manner. That way new people might actually
stay on the list to learn something from you.

Is there a faq or manual or some thing for this mailing list? We could
point them to that then, and it would harp on the point that they should
learn to use search engines if they don’t know yet. That might help.

-Jason

----- Original Message -----
From: mattijsdegroot@xs4all.nl (Mattijs de Groot)
To:
Sent: Monday, March 25, 2002 12:42 PM
Subject: Re: [SDL] text output using SDL

I agree on all that. A FAQ could be useful, but i think in most cases just
using Google is more effective. If you type

“sdl some question”

in google you almost certainly will find some post at libsdl.org in the top
10. Better still:

“some question site:libsdl.org”

will only search on libsdl.org. The important thing is not to be too rude,
even when someone asks a stupid question.

Mattijs

P.S. My math teacher always said: “There are no stupid questions, there are
only stupid people”.On Monday 25 March 2002 10:36, you wrote:

----- Original Message -----
From: “Mattijs de Groot” <@Mattijs_de_Groot>
To:
Sent: Monday, March 25, 2002 12:42 PM
Subject: Re: [SDL] text output using SDL

(this is, i think, the opinion of every sane programmer). Thus, people

just

entering the development community should be encouraged to invent their

own

algorithms, but at the same time also to learn how to reuse code of other
people. Both skills are essential for productivity. The most important

point

I think it’s important for new developers to learn how to use existing
work, develope their own work, and learn how to use a web search engine to
try and find their own answers instead of running to people for help first.
It seems like this last one is the hardest for new developers to learn.

i would like to make is that if you still feel that it is important to

tell

people to invent their own code (which probably is a good idea at times)

you

could do so in a more friendly manner. That way new people might actually
stay on the list to learn something from you.

Is there a faq or manual or some thing for this mailing list? We could
point them to that then, and it would harp on the point that they should
learn to use search engines if they don’t know yet. That might help.

-Jason


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

| I think it’s important for new developers to learn how to use existing work,

Yes, there’s too much re-inventing going on. It’s fun to write your own
stuff, but look how many web-based contacts programs and CD players exist
for linux :slight_smile:

| develope their own work, and learn how to use a web search engine to try and
| find their own answers instead of running to people for help first. It
| seems like this last one is the hardest for new developers to learn.

The problem with trying to find stuff on google, is that it can be hard
phrasing your queries correctly. It seems there’s two kinds of people
here…

Ones who are just starting (graphics) programming, and don’t know
anything, and ones who have maybe used something like DirectX and want
to learn SDL.

For the first group, they might not even be aware they need to flip the
back buffer to get pictures on the screen, etc. You can’t search for
things you don’t know exist…

| Is there a faq or manual or some thing for this mailing list? We could
| point them to that then, and it would harp on the point that they should
| learn to use search engines if they don’t know yet. That might help.

An FAQ would be good. The online manual for SDL is quite good, but it
doesn’t explain some things that I found really confusing - like why I
can’t draw lines or write text using SDL. It wasn’t until I had a look
around the libraries part of the site that I realised there were extra
libs to do that sort of thing. To a newbie, putting text on the screen
would seem a really basic function, and the fact there’s no
"SDL_printf()" or similar is a little confusing.On Mon, Mar 25, 2002 at 10:36:31AM -0500, Jason Hoffoss wrote:


I am not a 32 year old woman
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc
E4C4 DEEA 7D08 D511 E149 | www.piku.org.uk wnzrf at cvxh.bet.hx (rot13’d)

Do you realy believe everyone should reinvent the wheel all the time?

No. But beginners should start to learn how to code - meaning how to
translate some algorithm (formulated in any way) into a language that the
computer understands. After you learned it, you shouldn’T always reinvent
the wheel (why should you?).

This isn’t necessarily true. It is good to try things yourself to learn
more about the subject, but you don’t always need to know stuff like that.
Do I need to write my own low level audio library using just SDL before I
use SDL_mixer? I just want to play sounds in my game, and that’s the bottom
line. I could care less how it works as long as it does work, and work
well. If it doesn’t, then I might have to figure out how to do it myself
instead. Otherwise, I won’t worry about it. Same thing with SDL. I’m not
about to try and write my own SDL library from scratch. I don’t think it’s
necessary I do so in order to use SDL in my projects. Or how about writing
my own 3d video card API before I use Direct3D or OpenGL? Ultimately, the
only important thing is reaching the goal, and the goal is to write good
programs. If you can reach that point without reinventing any wheels, then
why bother? Often doing many things yourself at least once will help you
reach that ultimate goal, but not always, as there’s an infinate amount of
things you could learn out there, but our lives are finite in length. You
have to “pick your battles” as they say.

I think it
is realy useful for novice programmers (like myself) to try and think up
their own systems for collision detection, drawing fonts, interfacing
with

the user, timing the audio, etc. It is fun to do so, but i am sure that
when

my first project is finished a lot of things are far less efficient than
they

could have been by using already evolved and optimized code from others.
I

You’re right! But at first creating an own solution to a problem actually
teaches you most.

Perhaps. I think as long as you are practicing programming, you’ll gain
experience and grow, whenther that means you write every single piece of a
program yourself from scratch, and only release that first program after 5
years of work, or whether you constantly use existing libraries and reuse
code from other, and write code to put it all together, and release 5
programs every year. You will develope specializations in different areas
depending which route you take, but in the end, you’ll be constantly
learning and improving and growing as a programmer. I’m not sure there’s
one right way to go about it. Certainly in commercial software developement
speed tends to be more important, which is why they push for code reuse.

think the only way in which software development can advance is reuse of
code

(this is, i think, the opinion of every sane programmer). Thus, people
just

entering the development community should be encouraged to invent their
own

algorithms, but at the same time also to learn how to reuse code of other
people. Both skills are essential for productivity.

The very act of programming is an exercise in inventing your own algorithms
really. The dictionary defines algorithm as: “A detailed sequence of
actions to perform to accomplish some task.” Blitting a bitmap to the
screen can be considered an algorithm in itself.

-Jason

----- Original Message -----
From: st0ff@gmx.net (Stefan Hubner)
To:
Sent: Monday, March 25, 2002 7:48 AM
Subject: Re: [SDL] text output using SDL

The problem with trying to find stuff on google, is that it can be hard
phrasing your queries correctly. It seems there’s two kinds of people
here…

Heh, that’s an art in itself really. But I think it’s a good skill to try
and master, considering how enormously useful it is. I don’t usually have
too much trouble anymore finding things. The key is using unique, key
words. The fewest, most relevent words tends to be best. For example, the
words in this subject would work pretty good I think. You could also try
"SDL text font" and get pretty good results probably.

For the first group, they might not even be aware they need to flip the
back buffer to get pictures on the screen, etc. You can’t search for
things you don’t know exist…

That’s what existing source code to programs using SDL are good for. It’s
an excellent way to learn new things. People tend to just want to jump in
and do, but learning doesn’t traditionally work that way. Take any class in
college and you’re going to have a professor up there talking, teaching you
about things, and a text book to read, etc before you get to do anything
yourself (labs, homework). So why do people think they can suddenly throw
the whole evolution of education out the window and do thing differently?
They aren’t thinking is the problem, which means they probably aren’t going
to get too far anyway.

| Is there a faq or manual or some thing for this mailing list? We could
| point them to that then, and it would harp on the point that they should
| learn to use search engines if they don’t know yet. That might help.

An FAQ would be good. The online manual for SDL is quite good, but it
doesn’t explain some things that I found really confusing - like why I
can’t draw lines or write text using SDL. It wasn’t until I had a look
around the libraries part of the site that I realised there were extra
libs to do that sort of thing. To a newbie, putting text on the screen
would seem a really basic function, and the fact there’s no
"SDL_printf()" or similar is a little confusing.

Another good point. Nevermind that it’s their own fault they are confused
for thinking they know more than they really do (i.e. the nature of what
text really is). It’s just a fact of life that that happens, though. We
can’t really change the preconceptions people are going to have, but we can
identify patterns in them and straighten people out more efficiently as a
result. That’s what a FAQ is all about many times.

-Jason

----- Original Message -----
From: james@piku.org.uk (James)
To:
Sent: Monday, March 25, 2002 1:41 PM
Subject: Re: [SDL] text output using SDL

This is nuts!

St0fF, forgive me for asking about something that I
guess you feel I should have some knowledge of. Let me
again say that I have been aware of SDL for only a
little over a week now. I didn’t know that there was a
manual for SDL? I looked over what I could concerning
the display of text, but was unable to find any "SDL"
function or statement that could help me. I would like
YOU to know that I have learned a great deal in the
short 1-2 weeks that I have experimented with SDL and
I for one am not ashamed to say that I also learn from
other’s code. For Pete’s sake, the code that i get
from the internet or from someone else is used as a
tutorial for me. I don’t just copy and paste…I learn
from the code and in turn learn to program! If I am
unable to find what i’m looking for, I ask. I always
ask for suggestions or functions etc., that can help
me. But when someone “offers” to provide some helpful
code, I use it to learn from. That’s all I’m going to
say about this.

richard

— St0fF 64 wrote:> At 12:42 25.03.2002 -0500, you wrote:

On Monday 25 March 2002 04:45, you wrote:

You are right, ryan! But I don’t think that it
really helps to take some

code, partly understand it, and then partly
copying it and modifying it to

fit one’s own needs.
St0fF.

Do you realy believe everyone should reinvent the
wheel all the time?

No. But beginners should start to learn how to code

  • meaning how to
    translate some algorithm (formulated in any way)
    into a language that the
    computer understands. After you learned it, you
    shouldn’T always reinvent
    the wheel (why should you?).

Did you
write your own OS, windowing system, hardware
drivers or even SDL?

Well, Yes! I developed
AcidTrackMusicDevelopmentSystem on the Commodore 64
(This is a combination of windowing-system and
sound-hardware-driver). I
did this because all those C=64-Trackers had their
own good points, but
none of them combined all the very good and
important Features in one and
was actually optimized enough to meet some people’s
needs (The best players
were too slow). So I wrote down a lot and spent 2.5
years evolving ATMDS
to Version 3.2 . Now ATMDS is the C=64-Tracker with
most features compared
to the least rastertime-consume. And you know what?
This actually made me
a programmer! (I know this sounds kinda arrogant)

I think it
is realy useful for novice programmers (like
myself) to try and think up
their own systems for collision detection, drawing
fonts, interfacing with
the user, timing the audio, etc. It is fun to do
so, but i am sure that when
my first project is finished a lot of things are
far less efficient than they
could have been by using already evolved and
optimized code from others. I

You’re right! But at first creating an own solution
to a problem actually
teaches you most.

think the only way in which software development
can advance is reuse of code
(this is, i think, the opinion of every sane
programmer). Thus, people just
entering the development community should be
encouraged to invent their own
algorithms, but at the same time also to learn how
to reuse code of other
people. Both skills are essential for productivity.

You tell me what I think (except that I say from
myself that I’m insane in
some way)…

The most important point
i would like to make is that if you still feel that
it is important to tell
people to invent their own code (which probably is
a good idea at times) you
could do so in a more friendly manner. That way new
people might actually
stay on the list to learn something from you.

… but if a question sounds like someone doesn’t
read the manuals and
doesn’t make up his/her own mind at first, then I
normally react that
way. It is a method to make somebody aware of what
you just wrote 2
paragraphs above. And if the problem is as easy as
I explained within
4(!!!) lines in my last post, then I guess the
person wasn’t aware of that
thinking could solve a problem quicker than getting
someone else’s
code. In this case the primary question was either
misplaced or this guy
thought asking would be easier than reading (I know
there’s a link to
SDL_ttf @ libsdl.org).
Best wishes,
St0fF.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards?
http://movies.yahoo.com/

OK,

If I didn’t know how to output text in SDL and I asked on a list and got
the response this poor guy got, I’d be pretty bummed out…

so, if he’s still there, here’s a simplified version of some code I wrote
for a text widget…

It should be fairly straight forward to see what is going on…

You need SDL_ttf and FreeType installed to get this working, though there
are instructions on the places you download these libraries from…
(try libsdl.org)

NOTE, you should only call TTF_RenderText when you absolutely need to (ie
when the text changes, as TTF_RenderText is quite expensive…
This example will only call it once, if you plan to change the text in
this calass then you will need to add some way of letting Draw know it has
to re-render the text surface…

Hope this helps some…---------------
//---------------EText.h--------------------------------------------------------------------------------------------------------

class EText
{
public:
void SetText(char *text);
void SetColour(int r,int g,int b);
void SetFont(char *font, int size);
virtual void Draw(SDL_Surface *screen);
EText();
virtual ~EText();

protected:
TTF_Font *mFont;
SDL_Surface *mRenderedText;
SDL_Color mColour;
int mX;
int mY;
int mWidth;
int mHeight;
};

//---------------EText.c--------------------------------------------------------------------------------------------------------

void EText::Draw(SDL_Surface *screen)
{
SDL_Rect frect;

if(!mFont)
	return;

if(!mRenderedText) {
	mRenderedText = TTF_RenderText_Solid(mFont, mText, mColour));	
}

if(mRenderedText) {
	frect.x = mX;
	frect.y = mY;
	frect.w = mRenderedText->w;
	frect.h = mRenderedText->h;
	SDL_BlitSurface(mRenderedText, NULL, screen, &frect);
	mWidth=mRenderedText->w;
	mHeight=mRenderedText->h;
}

}

void EText::SetFont(char *font, int size)
{
if(mFont)
TTF_CloseFont(mFont);
mFont = TTF_OpenFont(font, size);
}

void EText::SetColour(int r, int g, int b)
{
mColour.r=r;
mColour.g=g;
mColour.b=b;
}

void EText::SetText(char *text)
{
if(!mText || sizeof(mText)<(strlen(text)+1))
mText=(char *)realloc(mText,(strlen(text)+1));
memset(mText,0,sizeof(mText));

strcpy(mText,text);

}


Yours,
Andy Gordon


QueriX UK
36A London Road		http://www.querix.co.uk
Southampton		
Tel: +44 23 8023 2345	andy at querix.co.uk
Fax: +44 23 8039 9685