現在地 >> メニュー >> GLUI >> GLUI::07 >> GLUI::07::まとめ2

問題

答え

#include <gl/glut.h>
#include <gl/glui.h>


//----------- 各種外部変数 ---------------//
int glutWinId;//ウィンドウID


//ロールアウト用
GLUI_Rollout *Rollout;

//ラジオボタン用
GLUI_RadioGroup  *radio;
int radioVal;




//-------------- ここから各種関数 ------------------//
void drawXYZ()
{
	glBegin(GL_LINES);
	glColor3f(0.f, 1.f, 0.f);
	glVertex2f(0.f,0.f);
	glVertex2f(0.f,100.f);

	glColor3f(1.f, 0.f, 0.f);
	glVertex2f(0.f,0.f);
	glVertex2f(100.f,0.f);

	glColor3f(0.f, 0.f, 1.f);
	glVertex3f(0.f,0.f,0.f);
	glVertex3f(0.f,0.f,100.f);

	glEnd();

	glColor3f(1,1,1);
}


//---------------- 各種コールバック ----------------------//
void idle()
{
	glutSetWindow(glutWinId);
	glutPostRedisplay();
}

//ディスプレイのコールバック
void display() 
{
	static int r = 0;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glColor3f(1,0,1);

	glPushMatrix();
	glRotatef(static_cast<float>(r),0,1,0);
	switch(radioVal)
	{
		case 0:
			glutWireTeapot(1);
		break;

		case 1:
			glutWireCube(1);
		break;

		case 2:
			glutWireTorus(0.3,0.5,20,20);
		break;
	}
	glPopMatrix();


	drawXYZ();

	glutSwapBuffers();

	if(++r>360) {r = 0; }

}

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 radioCB(int val)
{
	printf("current radio val is %d\n",radioVal);
}



//------ メイン関数 ----------//
int main(int argc, char *argv[]) 
{
	GLUT_INITs(&argc, argv);

	//GLUIの初期設定
	GLUI *glui = GLUI_Master.create_glui("GLUI Window");

	glui->add_statictext("GLUI rollout and radio button");

	//パネルを作成し、GLUIに関連付け
	Rollout = new GLUI_Rollout(glui,"rollout");
	//ラジオを作成し、パネルに関連付け
	radio = new GLUI_RadioGroup(Rollout,&radioVal,1,radioCB);
	glui->add_radiobutton_to_group(radio,"teapot");
	glui->add_radiobutton_to_group(radio,"cube");
	glui->add_radiobutton_to_group(radio,"torus");



	glui->set_main_gfx_window(glutWinId);
	GLUI_Master.set_glutIdleFunc( idle );

	glutMainLoop();

	return 0;
}

目次

― その他 ―

Wiki内検索

計測中...(07.10.8〜)

Save The World






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


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

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