プロジェクション行列を作る際のハメ

プロジェクション行列は一定なので、起動時に一回作るだけで終わろうと思ったのですが、うまく行きませんでした。原因は、

std::auto_ptr< Fl_Gl_Window > window(
    new Fl_Gl_Window( 640, 480 ) );
window->show(argc,argv);

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glViewport(0,0,window->w(),window->h());
float frustumWidth = window->w() / static_cast< float >( window->h() );
glFrustum(-frustumWidth,frustumWidth,-1,1,1,10000);

と、newとshow直後に作っていたためでした。いったん、Fl::check()を呼んで、メッセージをいろいろ処理しなければならないようです。

std::auto_ptr< Fl_Gl_Window > window(
    new Fl_Gl_Window( 640, 480 ) );
window->show(argc,argv);

// ウインドウ更新
Fl::check();

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glViewport(0,0,window->w(),window->h());
float frustumWidth = window->w() / static_cast< float >( window->h() );
glFrustum(-frustumWidth,frustumWidth,-1,1,1,10000);

new, show とプロジェクション行列作成の前に Fl::check() を呼ぶことで解決しました。