// Callback function called by GLUT to render sub-window content
void DisplaySubWindow(void)
{
    float v[4]; // will be used to set light parameters
    float mat[4*4]; // rotation matrix
    SubWindowData *win;

    win = GetCurrentSubWindowData();
    if (win == NULL) return;

    // Tell AntTweakBar which is the current window
    TwSetCurrentWindow(win->WinID);

    // Clear frame buffer
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_NORMALIZE);

    // Set light
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    v[0] = v[1] = v[2] = win->LightMultiplier*0.4f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_AMBIENT, v);
    v[0] = v[1] = v[2] = win->LightMultiplier*0.8f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
    v[0] = -win->LightDirection[0]; v[1] = -win->LightDirection[1]; v[2] = -win->LightDirection[2]; v[3] = 0.0f;
    glLightfv(GL_LIGHT0, GL_POSITION, v);

    // Set material
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, win->MatAmbient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, win->MatDiffuse);

    // Rotate and draw shape
    glPushMatrix();
    glTranslatef(0.5f, -0.3f, 0.0f);
    if( win->AutoRotate ) 
    {
        float axis[3] = { 0, 1, 0 };
        float angle = (float)(GetTimeMs()-win->RotateTime)/1000.0f;
        float quat[4];
        SetQuaternionFromAxisAngle(axis, angle, quat);
        MultiplyQuaternions(win->RotateStart, quat, win->Rotation);
    }
    ConvertQuaternionToMatrix(win->Rotation, mat);
    glMultMatrixf(mat);
    glScalef(win->Zoom, win->Zoom, win->Zoom);
    glCallList(win->ObjectShape);
    glPopMatrix();

    // Draw tweak bars
    TwDraw();

    // Present frame buffer
    glutSwapBuffers();

    // Recall Display at next frame
    glutPostRedisplay();
}
示例#2
0
// Callback function called by GLUT to render screen
void Display(void)
{
    float v[4]; // will be used to set light paramters
    float mat[4*4]; // rotation matrix

    // Clear frame buffer
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glEnable(GL_NORMALIZE);

    // Set light
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_AMBIENT, v);
    v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f;
    glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
    v[0] = -g_LightDirection[0]; v[1] = -g_LightDirection[1]; v[2] = -g_LightDirection[2]; v[3] = 0.0f;
    glLightfv(GL_LIGHT0, GL_POSITION, v);

    // Set material
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse);

    // Rotate and draw shape
    glPushMatrix();
    glTranslatef(0.5f, -0.3f, 0.0f);
    if( g_AutoRotate ) 
    {
        float axis[3] = { 0, 1, 0 };
        float angle = (float)(glutGet(GLUT_ELAPSED_TIME)-g_RotateTime)/1000.0f;
        float quat[4];
        SetQuaternionFromAxisAngle(axis, angle, quat);
        MultiplyQuaternions(g_RotateStart, quat, g_Rotation);
    }
    ConvertQuaternionToMatrix(g_Rotation, mat);
    glMultMatrixf(mat);
    glScalef(g_Zoom, g_Zoom, g_Zoom);
    glCallList(g_CurrentShape);
    glPopMatrix();

    // Draw tweak bars
    TwDraw();

    // Present frame buffer
    glutSwapBuffers();

    // Recall Display at next frame
    glutPostRedisplay();
}
示例#3
0
//--------------------------------------------------------------
void testApp::setup(){
	
	g_Rotation = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
	g_RotateStart = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
	g_LightDirection.set(-0.57735f, -0.57735f, -0.57735f);
	
	// Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();
	
	
	float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
	
	//TWEAK BAR
	bar.init("TweakBar", 200, 400, 200, 200, 200, 100);
	bar.enable();
	
	bar.addParam("Zoom", &g_Zoom, " min=0.01 max=500.0 step=1.0 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ", false);
	bar.addParam("ObjRotation", &g_Rotation, " label='Object rotation' open help='Change the object orientation.' ", false);	
	bar.addParam("Multiplier", &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ", false);
	bar.addParam("LightDir", &g_LightDirection, " label='Light direction' open help='Change the light direction.' ", false);
	bar.addSeparator("separator");
	bar.addParam("Ambient", g_MatAmbient, " group='Material' ", false, TW_TYPE_COLOR3F);
	bar.addParam("Diffuse", g_MatDiffuse, " group='Material' ", false, TW_TYPE_COLOR3F);
}
示例#4
0
// Main
int main(int argc, char *argv[])
{
    TwBar *bar; // Pointer to the tweak bar
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Initialize AntTweakBar
    // (note that AntTweakBar could also be intialized after GLUT, no matter)
    if( !TwInit(TW_OPENGL, NULL) )
    {
        // A fatal error occured    
        fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
        return 1;
    }

    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar simple example using GLUT");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    atexit(Terminate);  // Called after glutMainLoop ends

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, 
               " label='Object rotation' open help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, 
               " label='Light direction' open help='Change the light direction.' ");

    // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");

    // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");

    // Add the enum variable 'g_CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }

    // Store time
    g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

    // Call the GLUT main loop
    glutMainLoop();

    return 0;
}
示例#5
0
文件: main.cpp 项目: Sylvanuszhy/IBL
// Main
int main(int argc, char *argv[])
{
	TwBar *bar; // Pointer to the tweak bar
	float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
	float angle = 0.8f;

	// Initialize GLUT
	//OutputDebugStringA("Test\n");
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("SRTP Middle Check");
	glutCreateMenu(NULL);
	glewInit();
	initTextureList();
	for (int i = 0; i < textpoint; i++){
		glActiveTexture(GL_TEXTURE0 + i);
		glBindTexture(GL_TEXTURE_2D, textureObjects[i]);
	}
	glActiveTexture(GL_TEXTURE0);

	sprintf(path, "%sCook-Torrorence", root);
	programs[2] = setupShaders(path);

	// Set GLUT callbacks
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);

	// Initialize AntTweakBar
	TwInit(TW_OPENGL, NULL);

	// Set GLUT event callbacks
	// - Directly redirect GLUT mouse button events to AntTweakBar
	glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
	// - Directly redirect GLUT mouse motion events to AntTweakBar
	glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT key events to AntTweakBar
	glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
	// - Directly redirect GLUT special key events to AntTweakBar
	glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
	// - Send 'glutGetModifers' function pointer to AntTweakBar;
	//   required because the GLUT key event functions do not report key modifiers states.
	TwGLUTModifiersFunc(glutGetModifiers);

	// Create some 3D objects (stored in display lists)
	glNewList(SHAPE_TEAPOT, GL_COMPILE);
	glutSolidTeapot(1.0);
	glEndList();
	glNewList(SHAPE_TORUS, GL_COMPILE);
	//glutSolidTorus(0.3, 1.0, 16, 32);
	glutSolidSphere(0.75f, 20, 20);
	glEndList();
	glNewList(SHAPE_DRAGON, GL_COMPILE);
	drawBunny("dragon");
	glEndList();
	glNewList(SHAPE_SKULL, GL_COMPILE);
	drawBunny("skull");
	glEndList();
	glNewList(SHAPE_GARGO, GL_COMPILE);
	drawBunny("Gargoyle_ABF");
	glEndList();
	glNewList(DRAW_EN, GL_COMPILE);
	drawEnv(30);
	glEndList();

	// Create a tweak bar
	bar = TwNewBar("TweakBar");
	TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
	TwDefine(" TweakBar size='250 540' color='96 216 224' "); // change default tweak bar size and color

	TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=7.5 step=0.01 ");
	TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true ");
	TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space ");
	TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &lightDirection, " label='Light direction' opened=true ");
	TwAddVarRW(bar, "LightDist", TW_TYPE_FLOAT, &lightDistance, " label='Light distance' ");
	TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &lightAmbient, "");
	TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &lightDiffuse, "");
	TwAddVarRW(bar, "Rf", TW_TYPE_COLOR3F, &rf, "");
	TwAddVarRW(bar, "Roughness", TW_TYPE_FLOAT, &roughness, " label='Roughness' min=0.01 max=1.99 step=0.01 keyIncr='+' keyDecr='-' ");

	{
		TwEnumVal shaders[NUM_SHADERS] = { { SHADER_PHONG, "Phong" }, { SHADER_COOKTORRORENCE, "CookTorrorence" } };
		TwType shaderType = TwDefineEnum("ShaderType", shaders, NUM_SHADERS);
		TwAddVarRW(bar, "Shader", shaderType, &currentShader, "");
	}

	// Add the enum variable 'g_CurrentShape' to 'bar'
	// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
	{
		// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
		TwEnumVal shapeEV[NUM_SHAPES] = { { SHAPE_TEAPOT, "Teapot" }, { SHAPE_TORUS, "Sphere" }, { SHAPE_DRAGON, "Dragon" }, { SHAPE_SKULL, "Skull" }, { SHAPE_GARGO, "Gargo" } };
		// Create a type for the enum shapeEV
		TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
		// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
		TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, "");
	}

	// Store time
	g_RotateTime = GetTimeMs();
	// Init rotation
	SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
	SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

	atexit(Terminate);  // Called after glutMainLoop ends
	// Call the GLUT main loop
	glutMainLoop();

	return 0;
}
示例#6
0
文件: main.cpp 项目: Sylvanuszhy/IBL
// Callback function called by GLUT to render screen
void Display(void)
{

	// Clear frame buffer
	glClearColor(0.7, 0.7, 0.7, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glEnable(GL_NORMALIZE);

	float lightPositon[4];
	float l = sqrtf(powf(lightDirection[0], 2) + powf(lightDirection[1], 2) + powf(lightDirection[2], 2));
	lightPositon[0] = -lightDistance*lightDirection[0] / l;
	lightPositon[1] = -lightDistance*lightDirection[1] / l;
	lightPositon[2] = -lightDistance*lightDirection[2] / l;
	lightPositon[3] = 1.0f;                                 // point light

	glUseProgram(0);
	glPushMatrix();
	glTranslatef(0.5f, -0.3f, 0.0f);
	if (g_AutoRotate)
	{
		float axis[3] = { 0, 1, 0 };
		float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f;
		float quat[4];
		SetQuaternionFromAxisAngle(axis, angle, quat);
		MultiplyQuaternions(g_RotateStart, quat, g_Rotation);
	}
	ConvertQuaternionToMatrix(g_Rotation, mat);
	glMultMatrixf(mat);
	glScalef(g_Zoom, g_Zoom, g_Zoom);
	glCallList(DRAW_EN);
	glPopMatrix();

	GLuint currentProgram = programs[currentShader];
	if (currentShader == 1) {
		glUseProgram(0);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
		glLightfv(GL_LIGHT0, GL_SPECULAR, lightDiffuse);
		glLightfv(GL_LIGHT0, GL_POSITION, lightPositon);

		float materialAmbient[] = { rf[0] * 0.2f, rf[1] * 0.2f, rf[2] * 0.2f };
		float materialDiffuse[] = { rf[0] * 0.6f, rf[1] * 0.6f, rf[2] * 0.6f };
		float materialSpecular[] = { 1 - rf[0] * roughness / 2, 1 - rf[1] * roughness / 2, 1 - rf[2] * roughness / 2 };
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materialAmbient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialDiffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 24);
	} else {
		glUseProgram(currentProgram);
		glUniform1i(glGetUniformLocation(currentProgram, "env_brdf"), IBL);
		//#####glUniform1i(glGetUniformLocation(currentProgram, "env_map"), MAP);
		glUniform1i(glGetUniformLocation(currentProgram, "cubemap"), MAP);
		glUniform1i(glGetUniformLocation(currentProgram, "tex"), TEX);
		//glUniform1i(glGetUniformLocation(currentShader, "lightNum"), 0);
		//glUniform1f(glGetUniformLocation(currentProgram, "density"), lightAmbient[1]);
		//glUniform3fv(glGetUniformLocation(currentProgram, "ambient"), 1, lightAmbient);
		glLightfv(GL_LIGHT0, GL_POSITION, lightPositon);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
		glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
		//glUniform3fv(glGetUniformLocation(currentProgram, "lightPos"), 1, lightPositon);
		//glUniform3fv(glGetUniformLocation(currentProgram, "diffuse"), 1, lightDiffuse);
		glUniform3fv(glGetUniformLocation(currentProgram, "rf"), 1, rf);
		glUniform1f(glGetUniformLocation(currentProgram, "roughness"), roughness);
		glUniform1i(glGetUniformLocation(currentProgram, "iftex"), -1);
		glUniformMatrix4fv(glGetUniformLocation(currentProgram, "g_rotation"), 1, GL_FALSE, mat);		
	}

	// Rotate and draw shape
	glPushMatrix();
	glTranslatef(0.5f, -0.3f, 0.0f);
	if (g_AutoRotate)
	{
		float axis[3] = { 0, 1, 0 };
		float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f;
		float quat[4];
		SetQuaternionFromAxisAngle(axis, angle, quat);
		MultiplyQuaternions(g_RotateStart, quat, g_Rotation);
	}
	ConvertQuaternionToMatrix(g_Rotation, mat);
	glMultMatrixf(mat);
	glScalef(g_Zoom, g_Zoom, g_Zoom);
	glCallList(g_CurrentShape);
	glPopMatrix();

	glUseProgram(0);
	// Draw tweak bars
	TwDraw();

	// Present frame buffer
	glutSwapBuffers();

	// Recall Display at next frame
	glutPostRedisplay();
}
示例#7
0
int main(int argc, char *argv[])
{
	TwBar *bar; 
	float axis[] = { 0.7f, 0.7f, 0.0f }; 
	float angle = 0.8f;
	winW = 640;
	winH = 480;
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(640, 480);
	glutCreateWindow("Assignment3- Skinning");
	glutCreateMenu(NULL);

	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	atexit(Terminate);  

	TwInit(TW_OPENGL, NULL);

	glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);

	glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
	glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
	TwGLUTModifiersFunc(glutGetModifiers);

	//Todo
	Matrices identity;
	skeletonWasp = new Skeleton("wasp_walk.skel");
	skinningWasp = new skin("wasp_walk.skin", skeletonWasp->worldMatrixes);
	animation = new Animation("wasp_walk.anim", skeletonWasp->joints);
	skeletonWasp->calculate(identity.IDENTITY);
	skinningWasp->update();
	
	bar = TwNewBar("TweakBar");
	TwDefine(" GLOBAL help='This is rotate and zoom the skeleton also to change the lighting effects' ");
	TwDefine(" TweakBar size='200 400' color='96 216 224' ");

	TwAddButton(bar, "Reset", ResetValues, NULL, " label='Resets the View' ");
	TwAddButton(bar, "Animate", StartAnimation, NULL, " label='Starts the animation' ");
	TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom,
		" min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");
	TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation,
		" label='Object rotation' opened=true help='Change the object orientation.' ");

	TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL,
		" label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");
	TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier,
		" label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");
	TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection,
		" label='Light direction' opened=true help='Change the light direction.' ");
	TwAddVarRW(bar, "LightDir2", TW_TYPE_DIR3F, &g_LightDirection2,
		" label='Light direction' opened=true help='Change the light direction.' ");

	TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient1, " group='Material' ");

	TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse1, " group='Material' ");

	{
		TwEnumVal shapeEV[NUM_SHAPES] = { { WASP, "Wasp" } };
		TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
		TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
	}

	g_RotateTime = GetTimeMs();
	SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
	SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
	CreateBar();
	glutMainLoop();

	return 0;
}
示例#8
0
void Display(void)
{
	//display the background image here
	
	/*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 1, 0, 1, -1, 1);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glDepthMask(GL_FALSE);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glRasterPos2i(0, 0);
	glDrawPixels()*/

	/*
	glClearColor(1.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	*/
	//background();


		float v[4]; 
		float v1[4];
		float mat[4 * 4];

		glClearColor(0, 0, 0, 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glEnable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);
		glEnable(GL_NORMALIZE);

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		v[0] = v[1] = v[2] = g_LightMultiplier*0.4f; v[3] = 1.0f;
		glLightfv(GL_LIGHT0, GL_AMBIENT, v);
		v[0] = v[1] = v[2] = g_LightMultiplier*0.8f; v[3] = 1.0f;
		glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
		v[0] = -g_LightDirection[0]; v[1] = -g_LightDirection[1]; v[2] = -g_LightDirection[2]; v[3] = 0.0f;
		glLightfv(GL_LIGHT0, GL_POSITION, v);
		

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT1);
		v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.4f; v1[3] = 1.0f;
		glLightfv(GL_LIGHT1, GL_AMBIENT, v1);
		v1[0] = v1[1] = v1[2] = g_LightMultiplier*0.8f; v1[3] = 1.0f;
		glLightfv(GL_LIGHT1, GL_DIFFUSE, v1);
		v1[0] = -g_LightDirection2[0]; v1[1] = -g_LightDirection2[1]; v1[2] = -g_LightDirection2[2]; v1[3] = 0.0f;
		glLightfv(GL_LIGHT1, GL_POSITION, v1);

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient1);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse1);

		glPushMatrix();
		glTranslatef(0.5f, -0.3f, 0.0f);
		if (g_AutoRotate)
		{
			float axis[3] = { 0, 1, 0 };
			float angle = (float)(GetTimeMs() - g_RotateTime) / 1000.0f;
			float quat[4];
			SetQuaternionFromAxisAngle(axis, angle, quat);
			MultiplyQuaternions(g_RotateStart, quat, g_Rotation);
		}
		ConvertQuaternionToMatrix(g_Rotation, mat);
		glMultMatrixf(mat);
		glScalef(g_Zoom, g_Zoom, g_Zoom);
		Matrices identity;
		animation->evaluate(newTime);
		if (animate){
			float timeDiff = currentTime - prevTime;
			prevTime = currentTime;
			currentTime = time(NULL);
			newTime = newTime + 0.01;
		}
		skeletonWasp->calculate(identity.IDENTITY);
		skinningWasp->update();
		skinningWasp->draw();		
		glPopMatrix();
	

	TwDraw();

	glutSwapBuffers();

	glutPostRedisplay();
}
// Setup new sub-window
void SetupSubWindow(int subWinIdx) 
{
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;
    SubWindowData *win;
    
    win = &g_SubWindowData[subWinIdx];
    win->ObjectShape = (subWinIdx == 0) ? SHAPE_TEAPOT : SHAPE_TORUS;
	win->Zoom = 1;
	win->AutoRotate = (subWinIdx == 0);
    win->MatAmbient[0] = (subWinIdx == 1) ? 0.0f : 0.5f;; win->MatAmbient[1] = win->MatAmbient[2] = 0.2f; win->MatAmbient[3] = 1;
    win->MatDiffuse[0] = (subWinIdx == 1) ? 0.0f : 1.0f; win->MatDiffuse[1] = 1; win->MatDiffuse[2] = 0; win->MatDiffuse[3] = 1;
	win->LightMultiplier = 1;
    win->LightDirection[0] = win->LightDirection[1] = win->LightDirection[2] = -0.57735f;
    win->RotateTime = GetTimeMs();
    SetQuaternionFromAxisAngle(axis, angle, win->Rotation);
    SetQuaternionFromAxisAngle(axis, angle, win->RotateStart);
	
	glutSetWindow(win->WinID);
    // Set GLUT callbacks
    glutDisplayFunc(DisplaySubWindow);
    glutReshapeFunc(ReshapeSubWindow);
    // Set GLUT event callbacks
    // - Register mouse button events callback
    glutMouseFunc((GLUTmousebuttonfun)MouseButtonCB);
    // - Register mouse motion events callback
    glutMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register mouse "passive" motion events (same as Motion)
    glutPassiveMotionFunc((GLUTmousemotionfun)MouseMotionCB);
    // - Register keyboard events callback
    glutKeyboardFunc((GLUTkeyboardfun)KeyboardCB);
    // - Register special key events callback
    glutSpecialFunc((GLUTspecialfun)SpecialKeyCB);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Declare this window as current for AntTweakBar.
    // Here, this will create a new AntTweakBar context for this window,
    // which will be identified by the number WinID.
    TwSetCurrentWindow(win->WinID);

    // Create a tweak bar
    win->Bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to use AntTweakBar with multiple windows.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'win->Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(win->Bar, "Zoom", TW_TYPE_FLOAT, &win->Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'win->Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(win->Bar, "ObjRotation", TW_TYPE_QUAT4F, &win->Rotation, 
               " label='Object rotation' open help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(win->Bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, win, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'win->LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(win->Bar, "Multiplier", TW_TYPE_FLOAT, &win->LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'win->LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(win->Bar, "LightDir", TW_TYPE_DIR3F, &win->LightDirection, 
               " label='Light direction' open help='Change the light direction.' ");

    // Add 'win->MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(win->Bar, "Ambient", TW_TYPE_COLOR3F, &win->MatAmbient, " group='Material' ");

    // Add 'win->MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(win->Bar, "Diffuse", TW_TYPE_COLOR3F, &win->MatDiffuse, " group='Material' ");

    // Add the enum variable 'win->ObjectShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'win->CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(win->Bar, "Shape", shapeType, &win->ObjectShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }
}