【问题标题】:Fl_Gl_Window flashes on creationFl_Gl_Window 在创建时闪烁
【发布时间】:2013-03-22 10:52:45
【问题描述】:

我有一些简单的 fltk 代码:

#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>

class MyWin : public Fl_Gl_Window {
  public:
  MyWin(int x,int y, int w,int h, const char*l = 0) :
    Fl_Gl_Window(x,y,w,h,l)
  {
  }
  void draw();
  void resize(int X,int Y,int W,int H) {
    Fl_Gl_Window::resize(X,Y,W,H);
    glLoadIdentity();
    glViewport(0,0,W,H);
    glOrtho(-W,W,-H,H,-1,1);
    redraw();
  }
};

void MyWin::draw() {
  ortho();
  glBegin(GL_QUADS);  
    glColor3d(1,0,0);
    glVertex3f(10,10,0);
    glColor3d(0,1,0);
    glVertex3f(w()-10,10,0);
    glColor3d(0,0,1);
    glVertex3f(w()-10,h()-10,0);
    glColor3d(1,1,0);
    glVertex3f(10,h()-10,0);
  glEnd();
}

int main(int argc,char* argv[]) {
  Fl_Window win(500,500, "OpenGL");
  MyWin window(10,10,win.w()-20,win.h()-20);
  win.end();
  win.resizable(window);
  win.show(argc,argv);
  return Fl::run();
}

这个示例在 Windows 7 上使用 mingw 为我完美地编译和链接,但是当我运行它时,它变得非常丑陋。首先屏幕变暗,并闪烁白色。然后屏幕被重绘,我的窗口出现了。当我关闭应用程序时也会发生同样的情况。

我试图删除绘图代码,同样的情况,然后我从外部窗口中删除了 gl 窗口,它仍然发生。所以它不受实际绘图的影响。所以我怀疑是opengl上下文创建导致了这个。删除 gl 窗口的创建支持这一假设,因为窗口现在“安静地”显示。

有谁知道如何让 Fl_Gl_Window 在 Windows 中正常播放?

【问题讨论】:

    标签: c++ opengl fltk


    【解决方案1】:

    在draw()函数中,我使用

        if (!valid())
        {
            valid(1);
            glLoadIdentity();
            glViewport(0,0,w(),h());
            ortho();
        }
    

    在其他任何事情之前。我认为这是一个OpenGL函数。如果你在这里放一个 printf 语句,你会看到它在第一次绘制和任何调整大小时都会被调用。

    也许和这个问题有关:Valid OpenGL context

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-14
      • 2020-06-11
      • 1970-01-01
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      相关资源
      最近更新 更多