FLTK logo

texture-based text drawing and window deletion

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.opengl  ]
 
Previous Message ]New Message | Reply ]Next Message ]

texture-based text drawing and window deletion Manolo Gouy Mar 26, 2011  
 
About the present texture-based Mac OS implementation
of text drawing in OpenGL windows.

There was a bug in the Mac OS 1.3 version where gl_draw() would fail
after an Fl_Gl_Window was deleted and recreated. The pre-computed
texture was re-used to draw in the new window, and this would fail.

I have implemented in r. 8536 a fix that invalidates the pile
of pre-computed textures when any Fl_Gl_Window is deleted.
This fixes the bug.

But, isn't there a better and less drastic solution ?

This short program displays the bug (before r.8536):

// run, then press 'd'
// - expected behaviour: the string is unchanged after pressing d
// - observed behaviour: the string is replaced by a rectangle

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Tile.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

class openglWindow : public Fl_Gl_Window{
public:
  openglWindow(int x, int y, int w, int h) : Fl_Gl_Window(x, y, w, h){}
  void draw()
  {
    glClearColor(0.5, 0.3, 0.8, 0.);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glRasterPos2d(0, 0);
    gl_font(0,20);
    gl_draw("A string");
  }
};

Fl_Tile *tile;

int shortcuts(int event)
{
  if(Fl::test_shortcut('d')){
    tile->clear();

    openglWindow *gl = new openglWindow(0, 0, 400, 400);
    gl->end();
    gl->mode(FL_RGB | FL_DEPTH | FL_DOUBLE);
    tile->add(gl);
    gl->show();
  }
  return 1;
}

int main(int argc, char **argv)
{
  Fl_Window *win = new Fl_Window(0, 0, 400, 400);
  tile = new Fl_Tile(0, 0, 400, 400);
  openglWindow *gl = new openglWindow(0, 0, 400, 400);
  gl->end();
  gl->mode(FL_RGB | FL_DEPTH | FL_DOUBLE);
  tile->end();
  win->end();
  win->show(argc, argv);
  Fl::add_handler(shortcuts);
  Fl::run();
}
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.