現在地 >> メニュー >> 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;
}

目次

― その他 ―

Wiki内検索

計測中...(07.10.8〜)

Save The World






▲よろしければ広告のクリックもお願いします


▲ランキングに参加しました

管理人/副管理人のみ編集できます