Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL and displaying text !

Started by kajjait Mar 5, 2002 at 1:51 PM 18 replies 2.1k views
Original Post
kajjait
kajjait
I want to be able to display text on screen how would i go about doing this with sdl ?
Drizzt DoUrden
Drizzt DoUrden
Check out this thread. Don''t forget to download the SDL_ttf library and link it!

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)
------------------------------Put THAT in your smoke and pipe it
kajjait
kajjait
hmm recently i have been using devc++ .... and i dont know how to add the library to the project... this would probably explain all the linking errors im getting.. any idea how to do it?
Drizzt DoUrden
Drizzt DoUrden
I don''t use DevC++ but I''m sure you could find something in Cone3D.gamedev.net''s first tutorial or at www.libsdl.org.

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)
------------------------------Put THAT in your smoke and pipe it
kajjait
kajjait
yea i looked there first and i''m pretty sure this is how to add the sdl library "-lmingw32 -lSDLmain -lSDL" but im still trying to figure out what to put in for SDL_ttf
Drizzt DoUrden
Drizzt DoUrden
Probably something like "-lmingw32 -lSDL_ttf -lSDL" or "-lmingw32 -lSDL_ttf -lSDL_ttf". I really don''t know, sorry.

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)
------------------------------Put THAT in your smoke and pipe it
kajjait
kajjait
yea, i tried a million different things and nothing worked.. so im hoping someone else knows :\
Biased turkey
Biased turkey
http://www.linux-games.com/sfont/
Try the above URL. Download SFont1.5 Itis very simple to use and the downloaded file contain a short exemple.
The fonts are not fancy, but the main advantage of SFont is to be user friendly.
I hope this helps
kajjait
kajjait
a few problems with sfont...

Warning:
Return of negative value ''-1'' to "Uint32"
assignment to ''Sint16'' from ''float''


under linker:
Undefined reference to IMG_LOAD



any ideas?
smilydon
smilydon
Getting SDL_ttf to work with dev-c++ is rather involved. It took some time to figure it out but eventually it worked...

First: you download freetype and compile it, this results in a freetype.a file. You should rename it to libfreetype and place it in the lib directory of dev-c++ (then you can add -lfreetype as link option).

Second: you download the source of SDL_ttf. It comes with a showfont.c example. You can create a project with showfont.c, SDL_ttf.c and SDL_ttf.h and compile it (dont forget -lfreetype).
This results in a large executable because SDL_ttf was staticly linked with your program.

Third: The tricky bit... You want to link to a library that interfaces with SDL_ttf.dll. You create a project with SDL_ttf.c and SDL_ttf.h and call the project SDL_ttf. In the project options select "Create a dll" (and again dont forget -lfreetype).
If you compile you project you get a lot of linking errors. This is i believe a bug in dev-c++. To create a dll it will call dllwrap (in the bin directory of dev-c++) but it does not pass the link options (like -lSDL etc.). But if you go to the button with the yellow hand pointing at a paper (Create Makefile) you can create a make file. If you look at the makefile you will see that the link options are also passed to dllwrap. Run make and you get a libSDL_ttf.a file and a huge SDL_ttf.dll file. You can delete the dll file and replace it with SDL_ttf.dll that is downloadable as binary for SDL_ttf (which is much smaller).
Then you can create a project with only showfonts.c and SDL_ttf.h and add -lSDL_ttf as link option. That will add te interface to the dll file. The resulting exacutable in my case is only 11kB.

Well that''s it, but sfont or sofont are also cool. Personally i think that for a game sfont or sofont are better because the SDL_ttf fonts look too clean.....
kajjait
kajjait
so is this to get SDL_ttf working or sfont ? im confused.. i want to use sfont because it seems a bit easier but i am getting those compiler errors...

and what/where is freetype i looked on the sdl site and couldnt find it.. im guessing it isnt related to sdl...

Edited by - kajjait on March 5, 2002 6:52:59 PM
kajjait
kajjait
Gah forget it.. im just going to go to the store and buy msvc++ :\ i have enough for the introductory edition... be back in an hour or so.. hopefully i can get it to work with vc++
smilydon
smilydon
My description was for SDL_ttf. If you read the documentation you would know that it is a SDL wrapper for freetype, to render the true type fonts of windows in SDL. I just posted it because i can imagine that more people would get in trouble with the dllwrap problem in dev-c++.

Sfont is much easier and uses an image (png) with all characters of the font, but it requires SDL_image which is the same amount of work to get running as SDL_ttf. I think this causes your "Undefined reference IMG_LOAD", you didn''t use SDL_image......
kajjait
kajjait
hmmmm .. i got them both to compile in linux but there are problems... first the ttf one gives me this in the console : "Fatal signal: segmentation fault " and the sfont one runs, then shuts down right away. i get no errors/warnings compiling the TTF one...
the errors on the sfont one are :

"c:\coded\sdl\sfont\sfont-1.5\sfont.c(50) : warning C4013: 'exit' undefined; assuming extern returning int
c:\coded\sdl\sfont\sfont-1.5\sfont.c(95) : warning C4244: '=' : conversion from 'float ' to 'short ', possible loss of data
c:\coded\sdl\sfont\sfont-1.5\sfont.c(191) : warning C4018: '>' : signed/unsigned mismatch"

and also.. test1.c runs fine and delays for 4 seconds but doesnt display anything

*edit* nevermind the TTF library works fine i forgot to put the font in the same dir as the exe :\.... as for the sfont one.. im stumped

Edited by - kajjait on March 5, 2002 8:07:12 PM

Edited by - kajjait on March 5, 2002 8:24:35 PM
Biased turkey
Biased turkey
Installing and running SFont is not that difficult:
1) As Smilydon mentioned, you need SDL_Image installed ( both developer and runtime RPM packages )
2) Download, unzip and untar the file SFont-1.5.tar.gz
3) let''s say that you want to compile the test1.c example, you cimpile it with:
gcc SFont.c test1.c -o test1 sdl-config --libs --cflags -lSDL_image
and voila you have your executable.
Please note that every time you want to compile an application using SFonts the application source ( in our case test1.c ), SFont.c, SFont.h and at least 1 font graphic file ( in our case 24P_Copperplate_Blue.png must be in the same directory.

I hope this helps.
cone3d
cone3d
Click the SDL tutorials link to get a copy of my own SDL text printing routines
I modified the code a bit today (cleared it up, added comments), so it''s not the same as the one I posted earlier on the news (if anybody saw that news, anyway). If anybody should care, then the link at the news and the one on the tutorials page point to the same file, so it may seem like they are the same thing. That''s only because I overwrote the old file.


---
cone3d
http://cone3d.gamedev.net
My software never has any bugs - it just generates random features
---cone3dhttp://cone3d.gamedev.netMy software never has any bugs - it just generates random features
DaWanderer
DaWanderer
kajjait, I had some of the same problems you''ve had, except on VC++ 6. Make sure you get SDL_Image and link the .lib from that. Also, you need to have your code generation set to Multithreaded DLL. I didn''t and got the same errors you did about exit and stuff. Hope this helps.
kajjait
kajjait
its ok, im just going to use Marius'system... it seems a lot easier and doesnt depend on anything other than SDLmain and SDL, thanks a lot Marius!

Edited by - kajjait on March 6, 2002 9:30:39 PM
cone3d
cone3d
Hehe. No problem. I''m gonna write the tut for it some time soon (if not today or tomorrow, then next week).

I also put up one page with some additional fonts + info on how to create your own:
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/fonts/index


---
cone3d
http://cone3d.gamedev.net
My software never has any bugs - it just generates random features
---cone3dhttp://cone3d.gamedev.netMy software never has any bugs - it just generates random features

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.