Original Post
Is there any way i can use the printf with glut? I need to check some variables at runtime. I used to program with Allegro. Things are alot different with a glut window.
Quote:
Original post by Slinky360
Thanks for the reply.
I could compile as a console app i suppose. With allegro, it was easy to display text on screen. With opengl, it seems i would have to import some fonts first.
/* Project : Athamae Engine * File : ./Font.cpp * Version : 0.1 * Created : 24/05/2006 * Updated : 28/05/2006 * * Description: Load a font and draw text * */#include "Font.h"namespace Engine{ Font::Font(char* fontname, int size) { this->init(fontname, size, 0); } Font::Font(char* fontname, int size, int styleFlags) { this->init(fontname, size, styleFlags); } Font::~Font() { glDeleteLists(this->listBase,96); } void Font::init(char* fontname, int size, int styleFlags) { HFONT font, oldfont; HDC hDC = Core::Screen::GetInstance()->HDC(); this->listBase = glGenLists(96); font = CreateFont(size, 0, 0, 0, (styleFlags & FONTSTYLE_BOLD ? 800 : 0), (styleFlags & FONTSTYLE_ITALIC ? 1 : 0), (styleFlags & FONTSTYLE_UNDERLINE ? 1 : 0), (styleFlags & FONTSTYLE_STRIKEOUT ? 1 : 0), ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, fontname); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC,32,96, listBase); SelectObject(hDC, oldfont); DeleteObject(font); } void Font::DrawText(const char* format, ...) { char text[256]; va_list args; va_start(args,format); vsprintf(text,format,args); va_end(args); glPushAttrib(GL_LIST_BIT); glListBase(this->listBase-32); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib(); }}/* Project : Athamae Engine * File : ./HUD.cpp * Version : 0.1 * Created : 20/04/2006 * Updated : 28/05/2006 * * Description: * */#include "HUD.h"using namespace Core;namespace Engine{ HUD::HUD() { this->font = new Font("Distress",24); } HUD::~HUD() { delete this->font; } //protected void HUD::Start() { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0,Screen::GetInstance()->Width(),0,Screen::GetInstance()->Height()); glMatrixMode(GL_MODELVIEW);glPushMatrix(); glLoadIdentity(); } void HUD::End() { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } void HUD::Draw() { this->Start(); glDisable(GL_LIGHTING); glRasterPos3f(15,10,0.2); glColor3f(1,1,1); font->DrawText("Athamae Font Test"); //font->DrawText("FPS: %-3.f YAW: %-4.0f PITCH: %-4.0f ROLL: %-4.0f THROTTLE: %-4.0f POV: %-4.0f",fr,joy_rz*100, joy_y*100, joy_x*100, joy_throttle*100, joy_pov); glEnable(GL_LIGHTING); this->End(); } void HUD::Initialize() { }}This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more