🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

FTGL text color not working

Started by
-1 comments, last by hannibar 18 years, 3 months ago
I'm using FTGL to draw text on the screen. Everything works, except for one thing : The text always draws white. Even when I call glColor..() before calling the print function. This is the relevant code :
void gui_set_font(int font){
	FTF_SetFont("C:\\Windows\\Fonts\\Arial.ttf", 0, 12);
}

void gui_print_text(Window *win, float x, float y, char *text, int alignx, int aligny){
	int w, h;

	wglMakeCurrent(win->winInfo->hdc, win->winInfo->hrc);

	w = win->clientRect->w;
	h = win->clientRect->h;

	glViewport(0, 0, w, h);
	glScissor(0, 0, w, h);

	glMatrixMode (GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, w, 0, h, -1, 1);

	glMatrixMode (GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	FTF_SetPosition(x, y);
	FTF_DrawString(text);

	glPopMatrix();
	glMatrixMode (GL_PROJECTION);
	glPopMatrix();
	glMatrixMode (GL_MODELVIEW);
}

int FTF_TTFont::SetFont(const unsigned char* str, int fontsize)
{
	int err = 0;
	bool success = 0;

	if (fonts) delete fonts;	fonts= 0;
	if (fontm) delete fontm;	fontm= 0;
	if (fontl) delete fontl;	fontl= 0;

	font = new FTGLTextureFont((char *)str);

	err = font->Error();

	if(err){
		printf("Failed to open font %s\n", str);
		return 0;
	}
	else{
			
		fontm = font;

		fonts = new FTGLTextureFont((char *)str);
		fontl = new FTGLTextureFont((char *)str);
			
		success = fonts->FaceSize(fontsize-2<8?8:fontsize-2);
		success = fontm->FaceSize(fontsize-1<8?8:fontsize-1);
		success = fontl->FaceSize(fontsize);
		if(!success) return 0;

		success = fonts->CharMap(ft_encoding_unicode);
		success = fontm->CharMap(ft_encoding_unicode);
		success = fontl->CharMap(ft_encoding_unicode);
		if(!success) return 0;

		return 1;
	}
	return 0;
}

float FTF_TTFont::DrawString(char* str)
{
	wchar_t wstr[FTF_MAX_STR_SIZE-1] = {'\0'};
	int len = 0;
  
	len = utf8towchar(wstr, str);
	
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);

	glPushMatrix();
	glTranslatef(pen_x, pen_y, 0.0);
	glRasterPos2f(0, 0);
	glScalef(fsize, fsize, 1.0);

	font->Render(wstr);
	glPopMatrix();
  
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);

	return font->Advance(wstr);
}

	//in some function
	glColor3f(1.0f, 0.0f, 0.0f);
	gui_print_text(win, x, y, "test", 0, 0)
Does anyone know why I can't color my text ? Thanks in advance

This topic is closed to new replies.

Advertisement