"glwindow"はGLUTのウインドウをクラスでラップした"GLWindow"クラスとウインドウの設定をまとめた"GLWindowProperty"構造体を定義している。
- #ifndef __GLWINDOW_HPP__
- #define __GLWINDOW_HPP__
- #include <string>
- #include "gl.hpp"
- using namespace std;
- namespace DECS{
- namespace GL{
- struct GLWindowProperty{
- string title_;
- unsigned int mode_; //描画モード
- GLColor bgColor_; //背景色
- int wWidth_; //ウィンドウの幅
- int wHeight_; //ウインドウの高さ
- int wPositionX_; //ウインドウのx座標
- int wPositionY_; //ウインドウのy座標
- };
- static GLWindowProperty DEFAULT_WPROP = {
- "GLWindow", GL_RGBA, DGL_WHITE,
- 300, 300, 100, 100}; //デフォルトのウインドウ設定
- class GLWindow{
- private:
- GLWindowProperty* wProp_;
- void (*displayFunc_)(); //描画関数の関数ポインタ
- void init();
- public:
- GLWindow(int argc, char* argv[]): wProp_(&DEFAULT_WPROP)
- {
- this->wProp_->wPositionX_ =
- (glutGet(GLUT_SCREEN_WIDTH) - this->wProp_->wWidth_) / 2;
- this->wProp_->wPositionY_ =
- (glutGet(GLUT_SCREEN_HEIGHT) - this->wProp_->wHeight_) / 2;
- glutInitWindowPosition(this->wProp_->wPositionX_,
- this->wProp_->wPositionY_);
- glutInitWindowSize(this->wProp_->wWidth_, this->wProp_->wHeight_);
- glutInit(&argc, argv); glutInitDisplayMode(this->wProp_->mode_);
- }
- GLWindow(int argc, char* argv[], GLWindowProperty* wProp): wProp_(wProp)
- {
- glutInitWindowPosition(this->wProp_->wPositionX_,
- this->wProp_->wPositionY_);
- glutInitWindowSize(this->wProp_->wWidth_, this->wProp_->wHeight_);
- glutInit(&argc, argv); glutInitDisplayMode(this->wProp_->mode_);
- }
- ~GLWindow(){};
- void setBGColor(GLColor bgColor); //背景色設定関数
- void setDisplayFunc(void (*displayFunc)()); //描画関数を設定する関数
- void create(); //ウインドウ作成関数
- };
- }
- }
- #endif // __GLWINDOW_HPP__
使い方はメイン関数内で次のように記述する。
- int main(int argc, char* argv[]){
- GLWindowProperty wProp = {
- "DECS GL TEST", GL_RGBA, DGL_WHITE,
- 500, 500, 100, 100};
- GLWindow w(argc, argv, &wProp);
- w.setDisplayFunc(display);
- w.create();
- return EXIT_SUCCESS;
- }
WindowProperty構造体を用意して、コマンドライン引数とともにインスタンスを生成する。次に描画関数を設定して、"create()"を実行する。ここで描画関数は"void display()"と定義されている。
構成要素の詳細 :
- 自作OpenGLクラス(DGLLib)詳細 その1 gl.hpp
- 自作OpenGLクラス(DGLLib)詳細 その2 glutil.hpp, glutil.cpp
- 自作OpenGLクラス(DGLLib)詳細 その3 glbasicshape.hpp, glbasicshape.cpp
- 自作OpenGLクラス(DGLLib)詳細 その4 glwindow.hpp, glwindow.cpp
コメント