FLTK logo

GL windows in Fl_Tile

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 ]

GL windows in Fl_Tile Robert Strickland Dec 15, 2011  
 
I am new to FLTK. I want to put several OpenGL windows in an Fl_Tile. I started with Erco's cheat at

http://seriss.com/people/erco/fltk/#GL4PortResizable

which worked OK. However, I want the FL_DOWN_BOX borders to be visible between the tiles. So I enclosed each Fl_Gl_Window in a larger Fl_Window and put these in the Fl_Tile.

My layout for testing is like this:
+----------+----------+
|       gltileb       |
+----------+----------+
| +------+ | +------+ |
| |\    /| | |\    /| |
| | \  / | | | \  / | |
| |  \/  | | |  \/  | |
| |  /\  | | |  /\  | |
| | /  \ | | | /  \ | |
| |/    \| | |/    \| |
| +------+ | +------+ |
+----------+----------+
| +------+ | +------+ |
| |\    /| | |\    /| |
| | \  / | | | \  / | |
| |  \/  | | |  \/  | |
| |  /\  | | |  /\  | |
| | /  \ | | | /  \ | |
| |/    \| | |/    \| |
| +------+ | +------+ |
+----------+----------+

I was hoping for Four Xs in four squares, each with a colored border inside a tile. The X and squares are drawn by GL with colored borders drawn by FLTK, surrounded by regular FL_DOWN_FRAMEs.

The problem is that only the left two of the four GL windows get drawn. This is with fltk1.3.0 tested under linux and Windows. What am I doing wrong? I am not really clear on how/when/if my FLGL::draw() gets called in this hierarchy.

Robert Strickland

Here is my test code:

/**
  Test by Robert Strickland to tile four OpenGL windows.
  Based on Erco's cheat:
  http://seriss.com/people/erco/fltk/#GL4PortResizable
  but without the code to do the proportional resizing
*/
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Tile.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>

/**
  A Fl_Gl_Window that draws an X in a box
*/
class FLGL : public Fl_Gl_Window {
public:
  FLGL(int x, int y, int w, int h, const char* l=0) :
      Fl_Gl_Window(x, y, w, h, l) {
    end();
  }
protected:
  void draw() {
    if ( !valid() ) {
      // First time? init viewport, etc.
      valid(1);
      glLoadIdentity();
      glViewport(0, 0, w(), h());
      glOrtho(-w(), w(), -h(), h(), -1, 1);
    }
    // Clear screen
    glClear(GL_COLOR_BUFFER_BIT);
    // Draw white 'X'
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_LINES);
    glVertex2f(w(),  h());
    glVertex2f(-w(), -h());
    glVertex2f(w(), -h());
    glVertex2f(-w(),  h());
    glEnd();
    // Draw yellow border last, around the outer edge
    glColor3f(1.0, 1.0, 0.0);
    glBegin(GL_LINE_LOOP);
    glVertex2f(-w()+1, -h());
    glVertex2f(w(), -h());
    glVertex2f(w(), h()-1);
    glVertex2f(-w()+1, h()-1);
    glEnd();
  }
};

/**
  A container for a FLGL window that leaves room for a border
*/
class Viewport : public Fl_Window {
protected:
  FLGL *gl;
public:
  Viewport(int x, int y, int w, int h, const char* l=0) :
        Fl_Window(x, y, w, h, l) {
    box(FL_DOWN_FRAME);
    gl = new FLGL( x+10, x+10, w-20, w-20 ); // wide border for testing
    resizable(gl);
    end();
  }
};

/**
  A 2x2 tile of OpenGL windows in Viewport containers with borders
*/
class Layout:public Fl_Tile {
private:
  Viewport *view[4];
public:
  Layout(int x, int y, int w, int h) : Fl_Tile(x, y, w, h) {
    box(FL_DOWN_BOX);
    color(FL_RED);          // (shouldn't be seen)
    // Create the 4 Viewports
    int k = 0;
    for (int j = 0; j < 2; j++) {
      for (int i = 0; i < 2; i++) {
        view[k] = new Viewport(i*200, j*200, 200, 200);
        view[k]->box(FL_DOWN_BOX);
        view[k]->color(9+k);
        view[k]->align(FL_ALIGN_CLIP);
        k++;
      }
    }
    end();
  }
};

int main() {
  Fl_Double_Window *win = new Fl_Double_Window(400, 400, "gltileb");
  Layout *layout = new Layout(0, 0, win->w(), win->h());
  win->resizable(layout);
  win->end();
  win->show();
  return(Fl::run());
}

// End of test code
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'.