• Advertisement
Sign in to follow this  

FTGL text color not working

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

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

Share this post


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

  • Advertisement