最終更新: mikk_ni3_92 2009年11月22日(日) 13:59:24履歴
現在地:メニュー >> NVIDIA_SDK >> NVIDIA_SDK_06 >> NVIDIA_SDK_06::Part2 >> NVIDIA_SDK_06::まとめ3
関連:NVIDIA_SDK_06::まとめ1、NVIDIA_SDK_06::まとめ2
関連:NVIDIA_SDK_06::まとめ1、NVIDIA_SDK_06::まとめ2
#include <iostream> #include <GL/glew.h> #include <GL/glut.h> #include <NV/nvGlutManipulators.h> #include <NV/nvGlutWidgets.h> //libファイルの依存指定 #pragma comment(lib,"nvWidgets.lib") //------- 各種外部変数 --------// nv::GlutExamine manipulator; //マウス操作用マニピュレータ nv::GlutUIContext g_ui;//nvWidget用 const char *comboStr[]={"red","green","blue"}; const char *liststr[]={"teapot","cube","sphere"}; int comboMethod; int listMethod; void display(); void reshape(int w, int h); void myMouseFunc(int button,int state,int x,int y); void myMouseMotion(int x,int y); void timer(int value); void DrawUI(); //------------- OpenGLの初期設定 -------------------------// void GLUT_CALL_FUNCs() { glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(myMouseFunc); glutMotionFunc(myMouseMotion); glutTimerFunc(0,timer,17); } void OtherMyInit() { glClearColor(0.0, 0.0, 0.0, 1.0); glEnable(GL_DEPTH_TEST); } void GLUT_INITs(int *argcp, char **argv) { glutInit(argcp,argv); glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(640,480); glutCreateWindow("NVIDIA SDK nvWidget comboBox"); GLUT_CALL_FUNCs(); OtherMyInit(); } //----------- メイン関数 -----------------// int main(int argc, char **argv) { GLUT_INITs(&argc,argv); manipulator.setTrackballScale(2.0);//トラックボール(回転処理の速度) manipulator.setDollyActivate( GLUT_LEFT_BUTTON, GLUT_ACTIVE_CTRL);//左ドラッグ+ctl → dolly移動処理 manipulator.setPanActivate( GLUT_LEFT_BUTTON, GLUT_ACTIVE_SHIFT);//左ドラッグ+Shfit → pan移動処理 //glewの初期化 GLenum err; err = glewInit(); if (err != GLEW_OK){ std::cerr << glewGetErrorString(err) << "\n"; //エラーを出力 return -1; } glutMainLoop(); return 0; } //------------- ここから各種コールバック -----------------// void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); manipulator.applyTransform();//移動を適用する(回転、平行、拡大縮小など) if(comboMethod == 0) { glColor3f(1,0,0); }else if(comboMethod == 1) { glColor3f(0,1,0); }else { glColor3f(0,0,1); } switch (listMethod) { case 0: glutWireTeapot(1.0); break; case 1: glutWireCube(1.0); break; case 2: glutWireSphere(0.5,60,60); break; } DrawUI(); glutSwapBuffers(); } void reshape(int w, int h) { g_ui.reshape(w, h); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, (double)w / (double)h, 0.1, 1000.0); glMatrixMode(GL_MODELVIEW); manipulator.reshape(w, h); } void myMouseFunc(int button,int state,int x,int y) { //UIの方にフォーカスがない時 if(!g_ui.isOnFocus()){ manipulator.mouse(button, state, x, y); } //UIに焦点が或る時 g_ui.mouse(button, state, glutGetModifiers(), x, y); } void myMouseMotion(int x,int y) { g_ui.mouseMotion(x, y); if(!g_ui.isOnFocus()) manipulator.motion(x, y); glutPostRedisplay(); } void timer(int t) { glutPostRedisplay(); glutTimerFunc(t,timer,17); //タイマー関数 } //--------- ユーザインターフェイス関係 ------------// void DrawUI() { g_ui.begin(); { //コンボボックス g_ui.beginGroup(nv::GroupFlags_GrowDownFromRight); { g_ui.doComboBox(nv::Rect(),3,comboStr,&comboMethod,1); } g_ui.endGroup(); //リストボックス g_ui.beginGroup(nv::GroupFlags_GrowDownFromLeft); { g_ui.doListBox(nv::Rect(),3,liststr,&listMethod,1); } g_ui.endGroup(); } g_ui.end(); }