On 05/11/17 03:37, Greg Ercolano wrote:
> Since I can't replicate your screenshot, I can't know if this is the issue,
> but does it help to redo your draw() code this way:
>
> [..ugly google groups posted code..]
>
> (Hmm, I'm replying here using google's interface to the group, something I
> rarely do -- copy/pasting code from my OS X terminal seems to include the
> terminal's font and bg color for some reason.. rather than rewrite that
> with a courier font, I'm leaving it be as I'm curious how it'll look in NNTP/email)
Oh wow, ok, that google groups code paste experiment went oddly..
looked nice in google's editor, but immediately it looked bad
once posted. I'll keep that in mind :/
Replying here the way I normally do via email; here's the rewritten
draw() code again, for readability sake:
--- snip
void TryWin::draw(){
// Viewport not valid? Init viewport, ortho, etc.
if (!valid()) {
glLoadIdentity();
glViewport(0,0,w(),h());
glOrtho(-w(),w(),-h(),h(),-1,1);
}
glClearColor(0.5, 0.5, 0.8, 1.0);
glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
}
--- snip
I'm guessing that added code might help, because without it
I don't think OpenGL is getting a proper viewport initialization.
> Besides adding the necessary "if (!valid())" check, I also left out the !visible check
> (I don't think fltk would call your draw() routine if the widget was invisible, but it's
> better to do something than nothing when draw() is called), and I don't think the
> glFlush() call is needed, as FLTK should be handling that kind of thing within draw().
PS. the 1.3.4 docs for Fl_GL_Window::valid() advise using this:
--- snip
void mywindow::draw() {
if (!valid()) {
glViewport(0,0,pixel_w(),pixel_h());
glFrustum(...);
...other initialization...
}
if (!context_valid()) {
...load textures, etc. ...
}
... draw your geometry here ...
}
--- snip
Just an aside: I've never had to use pixel_w(),pixel_h() myself..
Those new methods seem to have been added somewhere in 1.3.x,
something to do with supporting Apple retina displays when the
special Fl::use_high_res_GL(bool) mode is enabled.
So if by chance you need that hires mode, then replace
the w()/h() calls I'm using in draw() with pixel_w()/pixel_h().
[Outside of that, I think w()/h() are equivalent to pixel_w()/pixel_h()]
Attaching a single .cxx version of your TryWin example below
that I used for my tests, just so I could easily build it with
fltk-config --compile foo.cxx --use-gl.
My comments in the extreme right column.
It's odd I can't replicate your smaller blue window, but that may just
be a difference between our OSX hardware.
BTW, small nit: I also changed the variable names x1/y1/x2/y2
in the TryWin constructor to x/y/w/h -- those last two values
are *not* x/y coords, they are width/heights.
___________________________________________________________________________
#include <openGL/GLU.h> /* OSX SPECIFIC? */
#include <FL/GLUT.h>
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
class TryWin : public Fl_Gl_Window {
public:
TryWin(int x1, int y1, int x2, int y2, int index0);
void draw();
//void initGL(); // UNUSED?
};
TryWin::TryWin(int X, int Y, int W, int H, int index0) // REWRITTEN: x1/y1/x2/y2 -> x/y/w/h
: Fl_Gl_Window(X, Y, W, H, "TryWin")
{
}
//void TryWin::initGL() { // UNUSED?
// glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT); // UNUSED?
//} // UNUSED?
void TryWin::draw(){
// Viewport not valid? Init viewport, ortho, etc.
if (!valid()) { // ADDED
glLoadIdentity(); // ADDED
glViewport(0,0,w(),h()); // ADDED
glOrtho(-w(),w(),-h(),h(),-1,1); // ADDED
} // ADDED
// if (!visible_r()) return; // don't draw invisible widget // REMOVED -- fltk shouldn't be calling draw() if invisible -- is this a bug workaround?
glClearColor(0.5, 0.5, 0.8, 1.0);
glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
// glFlush(); // REMOVED
}
int main(int argc, char **argv) {
Fl_Window *mainwin = new Fl_Window(800,180);
{
// Positions of these two subwindows are relative to the mainwin's upper/left
Fl_Window *leftwin = new TryWin(20,20,370,140, 1);
leftwin->align(FL_ALIGN_CENTER);
leftwin->color(FL_RED);
leftwin->end();
mainwin->begin();
// REMOVED FOLLOWING:
// Fl_Gl_Window SHOULDN'T PARENT REGULAR FLTK WIDGETS
//
// { // REMOVED
// // Child box coords within subwindow // REMOVED
// Fl_Box *box = new Fl_Box(20,20,80,80,"L Box"); // REMOVED
// box->color(0xdd000000); // REMOVED
// box->box(FL_FLAT_BOX); // REMOVED
// } // REMOVED
Fl_Window *rightwin = new Fl_Window(410,20,370,140);
leftwin->align(FL_ALIGN_CENTER);
rightwin->color(FL_GREEN);
{
// Child box coords within subwindow
Fl_Box *box = new Fl_Box(20,20,80,80,"R Box");
box->color(0x00dd0000);
box->box(FL_FLAT_BOX);
}
rightwin->end();
}
mainwin->end();
mainwin->resizable(mainwin);
mainwin->show(argc, argv);
return Fl::run();
}
___________________________________________________________________________