最終更新: mikk_ni3_92 2009年11月16日(月) 19:04:22履歴
現在地 >> メニュー >> GLUI >> GLUI::09 >> GLUI::09::まとめ
#include <gl/glut.h> #include <gl/glui.h> //----------- 各種外部変数 ---------------// int glutWinId;//ウィンドウID float scrColor[3]={0,0,0};//スクロールバー用変数 GLUI_EditText *editText; GLUI_String text; //---------------- 各種コールバック ----------------------// //ディスプレイのコールバック void display(void) { 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); glColor3fv(scrColor); glutWireTeapot(1); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); } //------------- OpenGLの初期設定 ------------------// void GLUT_INIT() { glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(640,480); glutWinId = glutCreateWindow("GLUT And GLUI"); } void GLUT_CALL_FUNC() { glutDisplayFunc(display); glutReshapeFunc(reshape); } void MY_INIT() { glClearColor(1.0, 1.0, 1.0, 1.0); glEnable(GL_DEPTH_TEST);//ZバッファON } //--------- GLUTの初期設定 -----------// void GLUT_INITs(int *argcp, char **argv) { glutInit(argcp,argv); GLUT_INIT(); GLUT_CALL_FUNC(); MY_INIT(); } void scrollCB(int val) { glutSetWindow(glutWinId); glutPostRedisplay(); } void editTextCB(int val) { printf("%s\n",editText->get_text()); } //----------- メイン関数 -----------------// int main(int argc, char *argv[]) { GLUT_INITs(&argc, argv); //GLUIの初期設定 GLUI *glui = GLUI_Master.create_glui("GLUI Window"); editText = new GLUI_EditText( glui, "Text:", text, -1, editTextCB ); glui->add_statictext("Red"); glui->add_statictext("Green"); glui->add_statictext("Blue"); glui->add_column(); GLUI_Scrollbar *sb1= new GLUI_Scrollbar( glui, "Red",GLUI_SCROLL_HORIZONTAL,&scrColor[0],-1,scrollCB); sb1->set_float_limits(0,1); GLUI_Scrollbar *sb2= new GLUI_Scrollbar( glui, "Green",GLUI_SCROLL_HORIZONTAL,&scrColor[1],-1,scrollCB); sb2->set_float_limits(0,1); GLUI_Scrollbar *sb3= new GLUI_Scrollbar( glui, "Blue",GLUI_SCROLL_HORIZONTAL,&scrColor[2],-1,scrollCB); sb3->set_float_limits(0,1); glui->set_main_gfx_window(glutWinId); GLUI_Master.set_glutIdleFunc( NULL ); glutMainLoop(); return 0; }