Sign in to follow this  
Slinky360

glut /printf

Recommended Posts

Slinky360    110
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.

Share this post


Link to post
Share on other sites
Limitz    342
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.

Share this post


Link to post
Share on other sites
Slinky360    110
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.

Share this post


Link to post
Share on other sites
Limitz    342
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()
{
}
}


Share this post


Link to post
Share on other sites
Slinky360    110
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this