Jump to content
  • Advertisement
Sign in to follow this  
3dcgmodeling

construct not called

This topic is 4171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#ifndef __freetype__
#define __freetype__

typedef unsigned short wchar_t;

 /* origin is the upper left corner */

/*********************************************************************/
//class FT_Bitmap;
class freetype
{
public:	
	freetype();
	freetype::~freetype();
	int init( char *filename);
	//void * getbitmap(  wchar_t *text );
	void * getbitmap(  wchar_t text );
 

	void clear_allocate_memory();
	void set_dimension_and_allocate_memory(int width1, int height1, int canvase_size);
	void kill();
private:
 
	class freetype_impl;
	freetype_impl *impl;

};

#endif




///////////////////////////


#include "freetype.h"
#include "ft2build.h"
#include FT_FREETYPE_H
#include FT_GLYPH_H 
#include <windows.h>

struct quad
{

	char r;
	char g;
	char b;
	char a;
	
};

/********************************************************************
	impl  type 
/*********************************************************************/
class freetype::freetype_impl
{
public:
	
	int init( char *filename ,FT_Encoding type = FT_ENCODING_UNICODE );
	void * getbitmap(  wchar_t *text );
	void * getbitmap(  wchar_t text );
 
	
	freetype_impl(){}
	~freetype_impl(){}
void copy_buffer_to_squad( 
			 FT_Bitmap*  bitmap,
             int canvas_size,
			 FT_Int      x,
             FT_Int      y);

	void clear_allocate_memory();
	void set_dimension_and_allocate_memory(int width1, int height1, int canvase_size);
	void kill();
private:

  FT_Library    library;
  FT_Face       face;

  FT_GlyphSlot  slot;
  FT_Matrix     matrix;                 /* transformation matrix */
  FT_Vector     pen;                    /* untransformed origin  */
  FT_Error      error;

  int width, height, canvase;
  quad  * image;

};


void  
freetype::freetype_impl::clear_allocate_memory()
{

	delete[] image;
	image = 0;
}
void 
freetype::freetype_impl::kill()
{
	
  FT_Done_Face    ( face );
  FT_Done_FreeType( library );
}

/*********************************************************************/   
int
freetype::freetype_impl::init( char *filename, FT_Encoding type )
{
  

  error = FT_Init_FreeType( &library );              /* initialize library */
  /* error handling omitted */
  if(error)
  {
	  int c = 0;
  }

  error = FT_New_Face( library, filename, 0, &face ); /* create face object */
  /* error handling omitted */

	if( error)
	{
		error = FT_New_Face(library,"font/gamespecialfont.TTF",0, &face);
		if(error)
		{

			int i = 1;
		}
	}
	error = FT_Select_Charmap( face, /* target face object */  type);
  return 0;
}

/*********************************************************************/
void
freetype::freetype_impl::copy_buffer_to_squad( 
			 FT_Bitmap*  bitmap,
             int canvas_size,
			 FT_Int      x,
             FT_Int      y)
{
 
  FT_Int  i, j, p, q;
  FT_Int  x_max = x + bitmap->width;
  FT_Int  y_max = y + bitmap->rows;

 //y_max = HEIGHT - top + rows
  for ( i = x, p = 0; i < x_max; i++, p++ )
  {
    for ( j = y, q = 0; j < y_max; j++, q++ )
    {
      if ( i < 0      || j < 0       ||
           i >= canvase || j >= canvase)
        continue;

      image[j* canvase + i].r |= bitmap->buffer[q * bitmap->width + p];
	  image[j* canvase + i].g |= bitmap->buffer[q * bitmap->width + p];
	  image[j* canvase + i].b |= bitmap->buffer[q * bitmap->width + p];

//	  image1[j].r = bitmap->buffer[q * bitmap->width + p];
//	  image1[j].g = bitmap->buffer[q * bitmap->width + p];
//	  image1[j].b = bitmap->buffer[q * bitmap->width + p];

    }
  }
}


/*********************************************************************/
void
freetype::freetype_impl::set_dimension_and_allocate_memory(int width1, int height1, int canvase_size)
{
	width = width1;
	height = height1;
	canvase = canvase_size;
	image = new quad[canvase * canvase];
	
	memset(image,0, canvase * canvase * sizeof(quad)) ;
}

/*********************************************************************/
void *
freetype::freetype_impl::getbitmap( wchar_t  text)
{
	    
  int           n, num_chars;
num_chars     = 1;

 memset(image,0, canvase * canvase *sizeof(quad));

	 /* use 50pt at 100dpi */
  //error = FT_Set_Char_Size( face, 1 * 64, 0,
    //                        100, 0 );                /* set character size */
  /* error handling omitted */

	error = FT_Set_Pixel_Sizes(face,width, height);
  slot = face->glyph;

 

  /* the pen position in 26.6 cartesian space coordinates; */
  /* start at (300,200) relative to the upper left corner  */
  pen.x = 0;
  pen.y = 0;
 
  for ( n = 0; n < num_chars; n++ )
  {
    /* set transformation */
  FT_Set_Transform( face, 0, &pen );
	
	
	
		FT_Glyph glyph;
	error = FT_Get_Glyph( face->glyph, &glyph );
 
 
//	FT_Glyph_Get_CBox(glyph,FT_GLYPH_BBOX_UNSCALED,&bbox);

    /* load glyph image into the slot (erase previous one) */
    error = FT_Load_Char( face, text, FT_LOAD_RENDER    );
	// FT_Render_Glyph(face->glyph,0);
    if ( error )
      continue;                 /* ignore errors */
	

	
	slot->bitmap.width;
	int spacex = slot->bitmap_left;
    /* now, draw to our target surface (convert position) */
    copy_buffer_to_squad( 
				 &slot->bitmap,
			     canvase,
                 spacex,
                 height - 2 - slot->bitmap_top );

    /* increment pen position */
    pen.x += slot->advance.x;
    pen.y += slot->advance.y;

	
  }
  return image;

}
 
/********************************************************************
	freetype interface 
/*********************************************************************/

freetype::freetype()
{
	impl = new freetype_impl;
	MessageBox(0,"construct",0,0);
}

freetype::~freetype()
{
	delete impl;
	impl = 0;
}
int freetype::init( char *filename )
{
	impl = new freetype_impl;
	return impl->init(filename);
}


void * freetype::getbitmap(  wchar_t text )
{
	return impl->getbitmap(text);
}

void freetype::clear_allocate_memory()
{
	impl->clear_allocate_memory();
}
void freetype::set_dimension_and_allocate_memory(int width1, int height1, int canvase_size)
{
	impl->set_dimension_and_allocate_memory(width1, height1, canvase_size);
}
void freetype::kill()
{

	impl->kill();

}



I compile it to a lib and use it at another project A and B, in A, construct called. but In B ,it not called. B is a dll project that is used in a exe project C. in both project,I use global. //global freetype ft; why does construct not be called in B?

Share this post


Link to post
Share on other sites
Advertisement
Hi,

If this code compiles and works (with Project A)

Wouldn't that suggest this code is OK ?

Why not post your code for Project B.
Which you actually say is a DLL, so I doubt that's the problem.

I would think your problem is in Project C (The EXE Application)

Post your code for that, and describe your problem [wink]

Share this post


Link to post
Share on other sites
I FOUND the problem

class freetype
{
public:
//freetype(); --- line 1
//freetype::~freetype(); line 2
int init( char *filename);
//void * getbitmap( wchar_t *text );
void * getbitmap( wchar_t text );


void clear_allocate_memory();
void set_dimension_and_allocate_memory(int width1, int height1, int canvase_size);
void kill();
private:

class freetype_impl;
freetype_impl *impl;

};



I use the class as head file for project B,without no constructor delelared in head file, it will not be called in project that use it,right? but why?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!