Home » Community » Forums » » SDL & Fonts
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 SDL & Fonts
Post Reply 
Uint32 is the color type if you're using MapRGB, and also for SDL_Rect::w and SDL_Rect::h

SDL_Color's members are all Uint8's and SDL_Rect::x and SDL_Rect::y are Sint32.

 User Rating: 1322   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

A good article, especially since I need a better font system that the one I'm using now! But I have some thoughts..

A little comment here. SDL_TTF is a wrapper for FreeType, am I correct? And FreeType is NOT LGPL, meaning it's GPL, and derivative works must release their source code. (I'm no lawyer, correct me if wrong, please.)

That's not to mention the Apple patents if you don't use 2.0 or have it compiled incorrectly.

I'm an indie who plans on selling his software, and I don't want to release my source code.. so FreeType is not usable to me.

 User Rating: 1024   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

According to the Sourceforge page: http://sourceforge.net/projects/freetype/
Freetype is BSD licensed. There is stuff on the freetype site about using the Mac libraries, which is a completely different issue you'd need to take up with Apple if you chose to use them.





 User Rating: 1322   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Great job cozman !

Please correct me if im wrong.
SDL_TTF is a separate DLL from your program and there is a source code for that dll, because of that you dont have to release your source code to the public.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'm fairly sure under GPL that you'd only have to release your source code if you created a derivative of the freetype DLL not if you use the DLL in your program.

 User Rating: 1070   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Nice article. Why does everyone put their DLLs in their executable folder though? That's such a pain in the ass. If you're on Windows then just stick em all in the Windows/system folder and be done with it.

 User Rating: 2077   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Pahan, if you were saying great job on the article, sorry to say it wasn't me who wrote this. If you were just saying great job about something else, then thanks

If you produce a work that links to a GPL'd library the reason the GPL is sometimes called viral applies, your app becomes 'infected' with the GPL, and must fall under the GPL.
The Library or Lesser GPL (LGPL) allows for dynamic linking as long as you provide the source of the DLL you link to.

If you make a game 'agame.exe' you must distribute:
agame.exe
SDL.dll
SDL_mixer.dll
copy of the LGPL
a notice saying you used SDL & SDL_mixer which are LGPL
source or an offer for source for SDL.dll and SDL_mixer.dll, the source technically should be available from the same place as agame.exe, so if it's on http://somesite.com it should be found on your site, however many people do not follow this rule, and I doubt anybody in the SDL crew would ever go after you on this, unless you had given them a reason to.

If you statically link SDL.dll and SDL_mixer.dll you are obligated to provide source for agame.exe as well, because the purpose is so that users may recompile your app with changes they made to LGPL'd libraries, so if they changed SDL but you statically linked they'd need your source as well.

(If you happen to be writing on a system for which there is no dynamic linking some of these rules may vary, I happen to know that Sam Lantinga (author of SDL) will exempt such platforms from the license.)

[edited by - cozman on June 11, 2003 3:41:32 AM]

 User Rating: 1322   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Hi guys.

I really want to thank you guys for the positive support. I wasn't sure how many SDL'ers there were here.

I finished my sister-article to this one. It basically runs through the creation of an uber-function PrintStrings() that does multiple lines and stuff. This new article is a lot shorter and I hope it goes up soon.

SDL & Fonts Part 2: PrintStrings()

(Thanks again !!

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Nice article, but the bit at the end probably isn't necessary; SDL structs are, well, structs, and you can initialise them all on one line without needing to write a function for them.

SDL_Rect rect = newSDL_Rect(1,2,3,4); // your way
SDL_Rect rect = { 1, 2, 3, 4 }; // the normal way

Gaiiden; filling the Windows directory with DLLs can lead to versioning problems (ie. your software breaks when someone else installs a 'newer' DLL that doesn't work entirely the same way) and also incidentally leads to marginal performance hits due to the number of entries in the directory.


[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]


 User Rating: 1905   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

quote:
Original post by Kylotan
Gaiiden; filling the Windows directory with DLLs can lead to versioning problems (ie. your software breaks when someone else installs a 'newer' DLL that doesn't work entirely the same way) and also incidentally leads to marginal performance hits due to the number of entries in the directory.


I understand. I just personally got tired of moving the DLLs or copying them around when building new programs or moving the program files for whatever reason. I'll keep this in mind for release versions however.

 User Rating: 2077   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Excellent article, just what we snippet readers need; I got a whole ton of information on this, particularly setting up helper functions.

however, I've also had questions regarding where to put DLLs for development and distribution. how do people arrange their SDL/freetype/dev libraries otherwise?

[edited by - d0hboy on June 16, 2003 12:04:38 AM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

What all files go i need to use sdl_ttf and run the program used in the article?

I have the sdl_ttf.lib and all the standard sdl stuff linked, and I have the sdl.dll and sdl_tff.dll in the folder with the my program. I also have freetype-6.dll in there. Am I missing anything that needs to be linked? Using the code from the article, my program closes after "TTF_Font *fntCourier = TTF_OpenFont( "Fonts\\cour.ttf", 12 );" I have cour.tff in a Fonts directory.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

i guess I’m the only person that is having trouble with this.
i compile the code and get no text display no warring or errors.
i tried lots of combination of the code below. i think my problem lies some where in freetype. it does not seem to matter if thefreetype214ST_D.lib is there or not it will still compile.
i'm using VS6 on windows 2000 with SDL-1.2.5

this is what i did.
1) i when to ( http://www.libsdl.org/projects/SDL_ttf/ ) and downloaded ( SDL_ttf-devel-2.0.6-VC6.zip) extracted it copyed the header file ( SDL_ttf.h ) to my (SDL\include\ ) directory the libary (SDL_ttf.lib) to (SDL\lib\ ) and the dll (SDL_ttf.dll) with my font.exe
2) i when to ( http://www.freetype.org ) and downloaded (ft214.zip) extracted it and build the project (from ..\freetype-2.1.4\builds\win32\) this out putted a file in to the directory ( ...\freetype-2.1.4\objs\freetype214ST_D.lib ) i moved that file from there in to my ( SDL\lib\ ) then copied the base include directory of ( ..\freetype-2.1.4\include\freetype\*.* ) in to my ( SDL\include\ )
3) made a new project and got SDL to work
4) included the SDL\include\ and SDL\lib\ (Tools-->Options-->Directories)
5) Copied a font to the projects font folder ( Fonts\cour.ttf )
6) added font source code to my SDL project this is my source
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <time.h>

#include <SDL.h>   // All SDL App's need this

#include <SDL_TTF.h> // It's our new buddy!!


int main( int argc, char* argv[] ) {
   /* Initialize defaults, Video and Audio */
   if( SDL_Init(SDL_INIT_VIDEO)==(-1) ) { 
      printf("Could not initialize SDL: %s.\n", SDL_GetError());
      exit(-1);
   }

   /* Set up the video */
   SDL_Surface *screen;
   int WINWIDTH = 640, WINHEIGHT = 480, BPP = 32;
   screen = SDL_SetVideoMode( WINWIDTH,WINHEIGHT, BPP, SDL_SWSURFACE );
   if( screen == NULL ) {
        fprintf(stderr, "Couldn't set %ix%ix%i video mode: %s\n", WINWIDTH,WINHEIGHT,BPP, SDL_GetError());
        exit(1);
   }
   atexit(SDL_Quit);
   SDL_ShowCursor( SDL_DISABLE ); // The cursor is ugly :)


   /* Set up the SDL_TTF */
   TTF_Init();
      atexit(TTF_Quit);
   /* TTF_Init() is like SDL_Init(), but with no parameters.  Basically, it initializes
      SDL_TTF.  There's really not much to it.  Remember, when the program ends, we have
      to call TTF_Quit().  atexit(TTF_Quit) ensures that when we call exit(), the
      program calls TTF_Quit() for us. */
   

TTF_Font *fntCourier = TTF_OpenFont( "Fonts\\cour.ttf", 12 );

SDL_Color clrFg = {0,0,255,0};  // Blue ("Fg" is foreground)

SDL_Surface *sText = TTF_RenderText_Solid( fntCourier, "Courier 12", clrFg );

   SDL_Rect rcDest = {0,0,0,0};
   SDL_BlitSurface( sText,NULL, screen,&rcDest );

SDL_FreeSurface( sText );


TTF_CloseFont( fntCourier );
exit(0);
}



Compiled it with no errors but the text did not show up any help would be greatly appreciated
For your next article I suggest that you include a example project.



 User Rating: 1060   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Okay, guys. Looking back on this, I seem to have forgotten to add one teeny weeny bit of code to my example.

What the code that [funvill] posted does is blit some text to the screen almost infinitely fast and then closes the window. What you need is one of these right before the 'exit(0)':

bool quit = false;
while( !quit ) {
   SDL_Event event;
   if( SDL_PollEvent( &event ) ) {
       switch( event.type ) {
          case SDL_KEYDOWN: {
             int key = event.key.keysym.sym;
             if( key == SDLK_ESCAPE ) {
                quit = true;
             }
             break;
          }
       }
   }
}


That's basically a 'press esc. to continue' type of thing. It completely slipped my mind.

If that wasn't the issue, I'll do my best to help some more.

Update:
Also, you may have to update the 'screen'. Put 'SDL_UpdateRect( screen,NULL )' right before the above 'while' loop. I am so absent-minded.

[edited by - tekkamanendless on June 20, 2003 11:40:32 PM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

What version of TrueType would I want, using VisualC++ 6 on Windows XP? With the revised code my program exits when it tries to load a font on the line

TTF_Font *fntCourier = TTF_OpenFont( "Fonts\\cour.ttf", 12 );

I've tried using different fonts and different sizes, but it still exits. I used the 'press esc. to continue' at various places throughout the entire project and it always exits when it gets to the TTF_OpenFont line.

[edited by - sharkius on June 23, 2003 3:06:09 PM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'll ask the obvious first:
Do you have a folder called 'Fonts' in your program directory with the font file that you want to use in it?

(That sounds like the problem.)

After the TTF_OpenFont, you could possibly call TTF_GetError or TTF_Error (it's something like that). It should return a 'char*' to print with printf.

In the future, I'll definitely include a project with all this stuff zipped away.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I had a Fonts folder, but i put it in the Debug folder. Moved it out of that and now everything works fine. Thanks!

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Great tut. You mentioned a sister tut but I am either blind or stupid, I can't find the link. (more than likely, stupid)

Grellin CGP

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: