Jump to content
  • Advertisement
Sign in to follow this  
Tensore

OpenGL Font in openGL

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

Hi people! I've tryed to follow the NeHe tutorial; it works with his code, but when I try to put it in a FLTK project characters are not shown! I copyed al gl relative lines of code without changing them, I past you my simple code: #include <windows.h> #include <stdio.h> #include <stdarg.h> #include <GL/gl.h> #include <Gl/glu.h> #include <FL/Fl.h> #include <FL/Fl_Window.h> #include <FL/Fl_Gl_Window.h> #include <Fl/Fl_Box.h> GLvoid glPrint(const char *fmt); GLvoid BuildFont(GLvoid); class Gl_Window : public Fl_Gl_Window { public: Gl_Window(int x,int y,int w,int h,const char *l=0) : Fl_Gl_Window(x,y,w,h,l) {;} private: void draw(); }; Fl_Window *form; Gl_Window *glw; Fl_Box *box; HDC hDC=NULL; HGLRC hRC=NULL; GLuint base; bool keys[256]; bool active=TRUE; GLYPHMETRICSFLOAT gmf[256]; void Gl_Window::draw() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glClearColor(0,0,0,0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,0.0f); glRasterPos2f(-0.8f, 0.00f); glPrint("Active OpenGL Text With NeHe"); } GLvoid BuildFont(GLvoid) { HFONT font; HFONT oldfont; base = glGenLists(96); font = CreateFont(-24,0,0,0,FW_BOLD, FALSE,FALSE,FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier New"); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, base); SelectObject(hDC, oldfont); DeleteObject(font); } GLvoid glPrint(const char *fmt) { char text[256]; sprintf(text, fmt); glPushAttrib(GL_LIST_BIT); glListBase(base - 32); glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); glPopAttrib(); } int main(int argc, char *argv[]) { form = new Fl_Window(800,600,"FONTS"); box = new Fl_Box(FL_DOWN_FRAME,10,10,780,580,""); glw = new Gl_Window(13,13,774,574,0); BuildFont(); form->end(); form->show(); SwapBuffers(hDC); return Fl::run(); } What's wrong with it? Thank you Mic

Share this post


Link to post
Share on other sites
Advertisement
It's difficult to read without proper formatting, use the [ source lang="cpp" ] tags.
Glancing over the code I see you try to print the text at position 0 on the Z-Axis. Your camera position is at 0, so the text would be invisible being on same plane with your view.
You need to translate to negative Z first.

Share this post


Link to post
Share on other sites
Hi! Thank you for your reply, but it did not work!
I tried to translate in negative Z but no font on the screen again! :(
I paste another time the code with source tag, so it'll be simpler to understand!


[source lang=cpp]

#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <GL/gl.h>
#include <Gl/glu.h>
#include <FL/Fl.h>
#include <FL/Fl_Window.h>
#include <FL/Fl_Gl_Window.h>
#include <Fl/Fl_Box.h>

GLvoid glPrint(const char *fmt);
GLvoid BuildFont(GLvoid);

class Gl_Window : public Fl_Gl_Window {
public:
Gl_Window(int x,int y,int w,int h,const char *l=0) : Fl_Gl_Window(x,y,w,h,l) {;}
private:
void draw();
};

Fl_Window *form;
Gl_Window *glw;
Fl_Box *box;
HDC hDC=NULL;
HGLRC hRC=NULL;
GLuint base;
bool keys[256];
bool active=TRUE;
GLYPHMETRICSFLOAT gmf[256];

void Gl_Window::draw() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0,0,0,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-4.0f);
glRasterPos2f(-0.8f, 0.00f);
glPrint("Active OpenGL Text With NeHe");
}

GLvoid BuildFont(GLvoid) {
HFONT font;
HFONT oldfont;
base = glGenLists(96);
font = CreateFont(-24,0,0,0,FW_BOLD,
FALSE,FALSE,FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
"Courier New");
oldfont = (HFONT)SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 32, 96, base);
SelectObject(hDC, oldfont);
DeleteObject(font);
}

GLvoid glPrint(const char *fmt) {
char text[256];
sprintf(text, fmt);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}

int main(int argc, char *argv[]) {
form = new Fl_Window(800,600,"FONTS");
box = new Fl_Box(FL_DOWN_FRAME,10,10,780,580,"");
glw = new Gl_Window(13,13,774,574,0);
BuildFont();
form->end();
form->show();
SwapBuffers(hDC);
return Fl::run();
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!