When trying to cut down my program to the font problem, I discovered that it is
possible to use two different fonts in the same window - if I'm not using
display lists! In this small version of my program, if I'm using DL nothing is
displayed at all. What is wrong in my way using DL?
It would be great if I could handle the data seperately, since I have a lot of
data that has to be blended in and out, and I would like to do it without
generating everything new again - that's why I've tried the DL way.
Here is the the source code with everything correctly displayed. I've marked
the parts to be put in or taken out, respectively, if using the (not running
correctly) DL version.
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/gl.h>
#include <GL/glu.h>
#include <string>
class MyGlWindow : public Fl_Gl_Window {
public:
GLint DisplayList[2]; ///< OpenGL display lists
void draw(){
if (!valid()) {
valid(1);
glClearColor(1.0, 1.0, 1.0, 1.0);
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,w(),h());
//reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Establish clipping volume
gluOrtho2D (10,w()-10, 10, h()-10);
//Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 0.0);
glLineWidth(1.0);
//the actual drawing
// using displaylist
//draw_model();
//using displaylist end
//without display lists
draw_x_axis(20,w()-40,"length","english");
draw_y_axis(20,h()-40,"r/R","greek");
//without display lists end
glPopMatrix();
}
void draw_model(){
//draw x_axis
glPushMatrix();
glCallList (DisplayList[0]);
glPopMatrix();
//draw y_axis
glPushMatrix();
glCallList (DisplayList[1]);
glPopMatrix();
}
void generate_model(){
glDeleteLists(DisplayList[0],1); // clear
DisplayList[0] = glGenLists(1);
glNewList(DisplayList[0], GL_COMPILE);
//x-axis
draw_x_axis(20,w()-40,"length","english");
glEndList();
glDeleteLists(DisplayList[1],1); // clear
DisplayList[1] = glGenLists(1);
glNewList(DisplayList[1], GL_COMPILE);
//y-axis
glNewList(DisplayList[1]+1, GL_COMPILE);
draw_y_axis(20,h()-40,"r/R","greek");
glEndList();
}
void draw_x_axis(double x_min, double x_max, std::string x_name,
std::string x_type){
if(x_type=="greek")
gl_font(FL_SYMBOL, 14 );
else
gl_font(FL_HELVETICA, 14);
//draw line
glBegin(GL_LINE_STRIP);
glVertex2d(x_min, 40); glVertex2d(x_max, 40);
glEnd();
//draw label
gl_draw(x_name.c_str(), w()-70, 20);
}
void draw_y_axis(double y_min, double y_max, std::string y_name,
std::string y_type){
//glColor3f(0.0, 0.0, 0.0);
glLineWidth(1.0);
if(y_type=="greek")
gl_font(FL_SYMBOL, 14 );
else
gl_font(FL_HELVETICA, 14);
//draw line
glBegin(GL_LINE_STRIP);
glVertex2d(40,y_min); glVertex2d(40,y_max);
glEnd();
//draw label
gl_draw(y_name.c_str(), 20, h()-50);
}
MyGlWindow(int x,int y,int w,int h,const char *l):
Fl_Gl_Window(x,y,w,h,l)
{
}
};
int main(int argc, char **argv, char **env)
{
Fl::visual(FL_DOUBLE|FL_INDEX); // initialise FLTK's OpenGL window as
'double buffered' and 'true color'
MyGlWindow* mywin;
Fl_Double_Window* win = new Fl_Double_Window(500, 300, "Labels");
{
MyGlWindow* o = mywin = new MyGlWindow(10, 10, win->w()-20,
win->h()-20, 0);
}
win->end();
win->resizable(mywin);
win->show();
mywin->show();
mywin->make_current();
/* //using displaylist
mywin->generate_model();*/
mywin->redraw();
return(Fl::run());
}
_______________________________________________
fltk-opengl mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-opengl