Jump to content
  • Advertisement
Sign in to follow this  
MHOOO

[FreeType2&OpenGL] Problem Rendering

This topic is 4085 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

Hi all, I'd like to print out text using FreeType 2. Unfortunately I could not quite get it to work the way its supposed to. Here's the piece of code which does the rendering of text:
void CFont<RTTFont>::Render ( const char* string )  { 
	unsigned int error;
	float rPos[4];
	//FT_Set_Pixel_Sizes(_pFontRes->_FTFace, GetPixelWidth(), GetPixelHeight());
	FT_Set_Char_Size(_pFontRes->_FTFace, 24 * 64, 24 * 64, 72, 72);

	FT_Bitmap* bitmap;
	GLuint texId[255];
	glGenTextures(255,texId);
	unsigned int i = 0;

	bool texCreated[255];
	for(i=0;i<255;++i)
		texCreated = false;

	glPushMatrix();
	for(i=0;i<strlen(string);++i) {
		error = FT_Load_Char( _pFontRes->_FTFace, string, FT_LOAD_RENDER);
		FTException(error);
		_ASSERT( _pFontRes->_FTFace->glyph->format==FT_GLYPH_FORMAT_BITMAP );

		glGetFloatv(GL_CURRENT_RASTER_POSITION,rPos);

		glBindTexture(GL_TEXTURE_2D,texId[ string ]);
		if(!texCreated[ string ]) {

			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, _pFontRes->_FTFace->glyph->bitmap.width, _pFontRes->_FTFace->glyph->bitmap.rows, 0,
				GL_LUMINANCE, GL_UNSIGNED_BYTE, _pFontRes->_FTFace->glyph->bitmap.buffer );

			texCreated[ string ] = true;
		};

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering

		GLenum err = glGetError();

		glBindTexture(GL_TEXTURE_2D,texId[ string ]);
		glMatrixMode(GL_MODELVIEW);
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glBegin(GL_QUADS);
		glTexCoord2d(0,0);
		glVertex2d(0,_pFontRes->_FTFace->glyph->bitmap.rows);

		glTexCoord2d(0,1);
		glVertex2d(0,0);

		glTexCoord2d(1,1);
		glVertex2d(_pFontRes->_FTFace->glyph->bitmap.width,0);

		glTexCoord2d(1,0);
		glVertex2d(_pFontRes->_FTFace->glyph->bitmap.width,_pFontRes->_FTFace->glyph->bitmap.rows);
		glEnd();
		glTranslatef(_pFontRes->_FTFace->glyph->advance.x/64, 0.0, 0.0);
	};
	glPopMatrix();
	glDeleteTextures(255, texId);


};


As I am still merely trying out how to actually draw things, I did not make use of any opengl lists yet. Now the problem is visible in the following image: Image of faulty output Basically I have two buttons and an edit field there, the first button should have the text "Skip-FPS: xxx", the second button "FPS: xxx" and the edit field "test" followed by a cursor. Unfortunately some characters are screwed up (i.e. the "s" character) and I have no idea why that is. "_pFontRes->_FTFace" is basically the FreeType2 face struct which is returned after loading a font. Furthermore I have no idea why glTexCoord2d does not work if I use the bitmaps height and width as coordinates, but only if I use 1 (one) as a param. I already read nehe's tutorial on this matter and thats why my code is similar - only thing is, it does not work as expected. Thanks, MHOOO

Share this post


Link to post
Share on other sites
Advertisement
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!