glut /printf
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.
can't you just compile it as a console application... printf should end up in the console window. Otherwise you could always use a file to write to using fprintf, in stead of stdout.
Greetings.
Greetings.
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.
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.
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.
Yeah i know. I just implemented it :)
Maybe it helps:
/* 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(); }}
EDIT: you will need to set up a orthogonal projection matrix as well
this is what my HUD does for now:
/* 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() { }}
I will stick to the console window for now. Still a newbee with opengl. I could write a basic "mario" game on allegro. But i know very little about the whole 3d / opengl world. Still havent learnt matrices yet.
You could redirect stdout to a file easily
freopen("logfile.txt", "w", stdout);
Just put that at the start of your program and you can check it after execution.
But its no good if you need to see the output at the same time as your program is running.
freopen("logfile.txt", "w", stdout);
Just put that at the start of your program and you can check it after execution.
But its no good if you need to see the output at the same time as your program is running.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement