Partage
  • Partager sur Facebook
  • Partager sur Twitter

TRUETYPE 2.3.5

    15 avril 2008 à 14:49:53

    Salut les Zéros :D

    voilà, je découvre l'affichage de fonte sous OpengGL avec la SDL, et cette lib me paraît idéale pour commencer !

    Je teste donc les appels de fonctions d'après un tuto, mais je
    bloque sur les variables de la fonction FT_New_Memory_Face... le tuto ne propose pas de valeurs par défault, je ne vois donc pas comment les remplir concrètement.

    mon code :

    {...
    //--1)INIT
               int errFREEFONT;
    	       errFREEFONT = FT_Init_FreeType( &library );
    	  if ( errFREEFONT )
    	  {
    	   //...erreur
    	  }
    	  else
    	  {
    
    
    //--2) LOAD FONT	
    	      errFREEFONT = FT_New_Face( library, monURL,0, &face );
             if ( errFREEFONT )
    	  {
    	   //...
    	  }
    	  else
    	  {
    //---3) MEMORY
                 errFREEFONT = FT_New_Memory_Face(   library,
    				         buffer, // first byte in memory 
    				         size,// size in bytes 
                                                       0, // face_index           
    					   &face );
              }
    ...}
    


    Comment déterminer buffer et size ?

    Faut-il extraire les données d'après la fonte chargée ?

    J'ai aussi trouvé le tuto de Nehe mail il date à cause de l'ancienne version de FREETYPE qu'il utilise...

    ps: d'après le site de freetype, les sources à tester pour Windows sont sus la forme
    ftdmo.x.x.x ( les .x symbolisant la version en cours)
    mais tout ce que j'ai pu récupéré c'est ft2demos-2.3.5 !

    ...auriez-vous d'autres exemples ou des sources plus détaillées !?

    merci
    • Partager sur Facebook
    • Partager sur Twitter
      15 avril 2008 à 16:02:26

      Oui oui! C'est une réponse "Je sais chercher sur Google"

      http://www.google.com/search?client=op [...] f-8&oe=utf-8

      Si tu prend 3 secondes pour descendre dans la page tu vas voir un joyaux de Google Code!
      • Partager sur Facebook
      • Partager sur Twitter
        16 avril 2008 à 7:28:55

        Citation : Mattex

        Si tu prend 3 secondes pour descendre dans la page tu vas voir un joyaux de Google Code!



        C'est sûr, je suis pas une lumière :) mais si le joyaux dont tu parles est bien
        SplashFTFontFile.cc, je suis un peu plus perdu avec ses SplashFTFontEngine , SplashFTFontID... :-°
        • Partager sur Facebook
        • Partager sur Twitter
          16 avril 2008 à 14:31:51

          Je parle de ça : http://www.google.com/codesearch?clien [...] um=4&ct=title

          Des dizaines d'exemples pour FT_New_Memory_Face
          • Partager sur Facebook
          • Partager sur Twitter
            17 avril 2008 à 12:37:34

            Oui, je les ai vu aussi, très intéressant !
            Mais ... comprends pas :-°

            j'ai essayé de compiler des exemples - sans trop savoir lesquels - de gnubg, de foss...que des retour d'erreurs ! Et pi selon la source les headers varient ...Il faut savoir appeler les nombreuses fonctions ... pas d'exemples ultra basiques avec des chemin explicites ... C++ encore tout frais pour moi (syntaxe, organisation...), donc tu comprendras que je me noie très vite avec autant de procédures :o

            Mais bon, va bien falloir y arriver :p
            En fait j'aurais besoin d'un petit exemple tout [...] avec le moins fichiers possibles...avant de lancer dans les headers, classes &Cie...


            Cela dit, je m'accroche à mes débuts et si quelqu'un veut bien m'aider à le compléter :


            // FreeType Headers
            #include <ft2build.h>
            #include FT_FREETYPE_H
            //#include "resource.h"
            #include <iostream>
            // Some STL Headers
            #include <vector>
            #include <string>
            //
            #include <stdlib.h>
            #include <SDL/SDL.h>
            #include <GL/GL.h>
            #include <GL/glu.h>
            //   Exceptions 
            #include <stdexcept>
            
            
            FT_Library  library;  
            FT_Face     face; 
            
            
            
            void initFREEFONT( const char* url )
            {
            	//--1-- INIT
            	int errFREEFONT;
            	   errFREEFONT = FT_Init_FreeType( &library );
            	  if ( errFREEFONT )
            	  {
            	    std::cerr << "1-{initFREEFONT} FT_Init_FreeType error:" << errFREEFONT << std::endl;
            	  }
            	  else
            	  {
            	    std::cerr << "1-{initFREEFONT} FT_Init_FreeType OK!"  << std::endl;
            	
            
            	
            	//---	2.A--  LOAD FONT from FILE
            		 errFREEFONT = FT_New_Face( library,
            					                       url,
            					                       0,
            					                       &face );	
            
            	//--- 2.B --  LOAD FONT from memory	
            	
            	/*errFREEFONT = FT_New_Memory_Face(   library,
            							pf->data,  // BUFFER : first byte in memory 
            							pf->size,  // size in bytes      
            							0,  // face_index      
            							&face );*/
            	//-------------------------------------------------------------------------------
            		// A) doesn't work
            		  //if ( errFREEFONT == FT_Err_Unknown_File_Format ) {   std::cerr << "2-{initFREEFONT} FT_New_Face OK !" << errFREEFONT << std::endl; }
            		//  else if ( errFREEFONT ) { std::cerr << "2-{initFREEFONT} FT_New_Face error:" << errFREEFONT << std::endl;}		  
            		  
            		// B)
            		//-- 3 -- MEMORY FONT
            		   if ( errFREEFONT )
            		  {
            		    std::cerr << "2-{initFREEFONT} FT_New_Face ERROR" << errFREEFONT << std::endl;
            		  }
            		  else
            		  {
            		    std::cerr << "2-{initFREEFONT} FT_New_Face OK !" << std::endl;
            			
            	
            					/*int  num_chars;
            					num_chars = (int)face->num_glyphs;
            					std::cerr << "3-              num_chars : " <<num_chars << std::endl;
            		
            					int  face_size;
            					face_size = (int)face->size ;
            					std::cerr << "3-              face_size  : " <<face_size << std::endl;*/
            			
            		//-- 4 --  RESIZE FONT	
            
            					errFREEFONT = FT_Set_Char_Size( face ,  // handle to face object       
            													0 , // char_width in 1/64th of points  
            													16*64,   // char_height in 1/64th of points     or 768
            													300 , 
            													300 ) ;
            	//std::cerr << "4/exit: face , 0 , 768 , 300 , 300)" << std::endl;
            				if ( errFREEFONT != 0 )
            				 {
            				    std::cerr << "3-{initFREEFONT} FT_Set_Char_Size ERROR" << errFREEFONT << std::endl;
            				 }
            				 else
            				 {
            				    std::cerr << "3-{initFREEFONT} FT_Set_Char_Size OK !" << std::endl;
            					
            		//-- 5 --  LOAD GLYPH			
            					//glyph_index = FT_Get_Char_Index( face, charcode );
            					
            					int glyph_index = 0;
            					int load_flags = 0;//  set of bit flags used to indicate some special operations. The default value FT_LOAD_DEFAULT is 0.
            					
            					
            						errFREEFONT = FT_Load_Glyph(  face,          /* handle to face object */
            										          glyph_index,   /* glyph index           */
            										          load_flags );  /* load flags, see below */
            					if ( errFREEFONT != 0 )
            					{
            					    std::cerr << "4-{initFREEFONT} FT_Load_Glyph ERROR" << errFREEFONT << std::endl;
            					}
            					else
            					{
            					    std::cerr << "4-{initFREEFONT} FT_Load_Glyph OK !" << std::endl;
            						
            						
            						int  glyph_format;
            						glyph_format = (int)face->glyph->format ;
            						std::cerr << "4-              glyph_format  : " <<glyph_format << std::endl;
            						
            						
            						/*The field face->glyph->format describes the format used to store the glyph image in the slot. If it is not FT_GLYPH_FORMAT_BITMAP, 
            						one can immediately convert it to a bitmap through
            						FT_Render_Glyph as i*/
            						//http://freetype.sourceforge.net/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Mode
            						//const char render_mode = "FT_RENDER_MODE_NORMAL"; // high-quality anti-aliased (256 gray levels) ;
            										//FT_RENDER_MODE_MONO // 1-bit monochrome bitmap
            										//FT_RENDER_MODE_LCD
            							
            						
            			//-- 6 --  RENDER  GLYPH			
            							errFREEFONT = FT_Render_Glyph( face->glyph,   // glyph slot  
            															FT_RENDER_MODE_NORMAL ); // render mode 
            						if ( errFREEFONT != 0 )
            						{
            						    std::cerr << "5-{initFREEFONT} FT_Render_Glyph ERROR" << errFREEFONT << std::endl;
            						}
            						else
            						{
            						    std::cerr << "5-{initFREEFONT} FT_Render_Glyph OK !" << std::endl;
            							
            							/*CHARMAPS 
            							when a new face object is created, it will look for a Unicode charmap and select it. 
            							The currently selected charmap is accessed via 
            							face->charmap. */
            							
            							/*int  glyph_charmap.;
            						glyph_charmap = (int)face->charmap. ;*/
            						std::cerr << "5-              glyph_charmap  : " << (face->charmap) << std::endl;
            						
            							//This field is NULL when no charmap is selected, which typically happens when you create a new FT_Face object from a font file that doesn't contain a Unicode charmap  
            							
            			//-- 6--  SELECT CHARMAP	
            							
            								/*errFREEFONT = FT_Select_CharMap( face,               // target face object 
            																 FT_ENCODING_BIG5 ); // encoding           
            							if ( errFREEFONT != 0 )
            							{
            							    std::cerr << "6-{initFREEFONT} FT_Select_CharMap ERROR" << errFREEFONT << std::endl;
            							}
            							else
            							{
            							    std::cerr << "6-{initFREEFONT} FT_Select_CharMap OK !" << std::endl;
            							}*/
            							/*
            							FT_CharMap  found = 0;
            						    FT_CharMap  charmap;
            						   int n;
            						  for ( n = 0; n < face->num_charmaps; n++ )
            						  {
            						    charmap = face->charmaps[n];
            						    if ( charmap->platform_id == my_platform_id &&
            						         charmap->encoding_id == my_encoding_id )
            						    {
            						      found = charmap;
            						      break;
            						    }
            						  }
            
            							if ( !found ) 
            							{  
            							}*/
            						//----------------------
            						
            						
            							
            			
            						}
            						   
            					}					
            						
            						
            						
            				 }
            	   
            
            			//std::cerr << "3-{initFREEFONT} num_glyphs :" << (errFREEFONT->num_glyphs) << std::endl;
            			
            			
            			
            			
            			// std::cerr << "2-{initFREEFONT} list_base :" << string(list_base) << std::endl;
            			/*glGenTextures( 128, textures );
            
            			// This Is Where We Actually Create Each Of The Fonts Display Lists.
            			for(unsigned char i=0;i<128;i++)
            				make_dlist(face,i,list_base,textures);
            
            			// We Don't Need The Face Information Now That The Display
            			// Lists Have Been Created, So We Free The Assosiated Resources.
            			FT_Done_Face(face);
            
            			// Ditto For The Font Library.
            			FT_Done_FreeType(library);*/
            
            			 // Get the file size
               /* fseek( file, 0, SEEK_END );
                int size = ftell( file );*/
            					
            				
            							  
            		  }
            	  }
            	 
            	// return error;
            }
            
            
            
            //----------------------------------- SDL ------------------------------------------------
            
            int initSDL()
            {
                if( SDL_Init(SDL_INIT_VIDEO) < 0)
                {
                    std::cerr << "Echec SDL_Init : " << SDL_GetError() << std::endl;
                    return (EXIT_FAILURE);
                }
            
               atexit( SDL_Quit );
               
                SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
            
                SDL_Surface* pScreen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL );//| SDL_FULLSCREEN );//
                if( !pScreen )
                {
                    std::cerr << "Echec de creation de la fenetre en 640x480 : " << SDL_GetError() << std::endl;
                    return (EXIT_FAILURE);
                }
            
                int nValue;
                if( SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &nValue) < 0)
                {
                    std::cerr << "Echec de recuperation du parametre SDL_GL_DOUBLEBUFFER : " << SDL_GetError() << std::endl;
                    return (EXIT_FAILURE);
                }
            
                if(nValue != 1)
                {
                    std::cerr << "Erreur : SDL_GL_DOUBLEBUFFER inactif" << std::endl;
                    return (EXIT_FAILURE);
                }
            
                bool bRunning = true;
                // boucle principale du programme
                while(bRunning)
                {
                    SDL_Event event; 
                    while(SDL_PollEvent(&event))
                    {
                       switch(event.type)
                        {
                            case SDL_QUIT:
                                bRunning = false;
                                break;
            
                            case SDL_KEYDOWN:
                                if (event.key.keysym.sym == SDLK_ESCAPE)
                                    bRunning = false;
                                break;
                        } 
                    } 
            
            		
                    glClear(GL_COLOR_BUFFER_BIT);
            
            	//--- SHAPE
            		/*glBegin(GL_TRIANGLES);
            	            glColor3ub(0,255,0);    glVertex2d(0,0.75);
            	            glColor3ub(0,0,255);    glVertex2d(0.75,-0.75);
            	            glColor3ub(255,0,0);    glVertex2d(-0.75,-0.75);
            		 glEnd();
            		glFlush();*/
            		
                  // --- echange des buffers back et front
                    SDL_GL_SwapBuffers();
            		
            		
                } 
            }
            
            
            
            //--------------------------------------------------------------------------------
            
            
            int main( int argc, char** argv )
            {
                //--- INIT SDL
            	initSDL();
            
            	//--- INIT FreeFont
            	initFREEFONT("assets/fonts/visitor1.ttf");
            	
                std::cerr << "Fin normale du programme" << std::endl;
            
                (argc);
                (argv);
            //---Pause
            /*int a;
            std::cin >> a;
            return EXIT_SUCCESS;*/
            }
            
            • Partager sur Facebook
            • Partager sur Twitter

            TRUETYPE 2.3.5

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown