|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
On mac os x compile with:
|
|
On mac os x compile with:
|
|
|
|
|
|
- g++ -c example.cpp -o example.o
|
|
|
|
|
|
+ g++ -c example.cpp -o example.o
|
|
g++ -o example example.o -framework OpenGL -framework GLUT -lAntTweakBar
|
|
g++ -o example example.o -framework OpenGL -framework GLUT -lAntTweakBar
|
|
rm *.o
|
|
rm *.o
|
|
|
|
|
|
@@ -21,7 +21,7 @@
|
|
// AntTweakBar: http://www.antisphere.com/Wiki/tools:anttweakbar
|
|
// AntTweakBar: http://www.antisphere.com/Wiki/tools:anttweakbar
|
|
// OpenGL: http://www.opengl.org
|
|
// OpenGL: http://www.opengl.org
|
|
// GLUT: http://opengl.org/resources/libraries/glut
|
|
// GLUT: http://opengl.org/resources/libraries/glut
|
|
-//
|
|
|
|
|
|
+//
|
|
// @author Philippe Decaudin - http://www.antisphere.com
|
|
// @author Philippe Decaudin - http://www.antisphere.com
|
|
// @date 2006/05/20
|
|
// @date 2006/05/20
|
|
//
|
|
//
|
|
@@ -39,7 +39,7 @@ using namespace igl;
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
-// MiniGLUT.h is provided to avoid the need of having GLUT installed to
|
|
|
|
|
|
+// MiniGLUT.h is provided to avoid the need of having GLUT installed to
|
|
// recompile this example. Do not use it in your own programs, better
|
|
// recompile this example. Do not use it in your own programs, better
|
|
// install and use the actual GLUT library SDK.
|
|
// install and use the actual GLUT library SDK.
|
|
# define USE_MINI_GLUT
|
|
# define USE_MINI_GLUT
|
|
@@ -88,7 +88,7 @@ void SetQuaternionFromAxisAngle(const float *axis, float angle, float *quat)
|
|
quat[1] = sina2 * axis[1] / norm;
|
|
quat[1] = sina2 * axis[1] / norm;
|
|
quat[2] = sina2 * axis[2] / norm;
|
|
quat[2] = sina2 * axis[2] / norm;
|
|
quat[3] = (float)cos(0.5f * angle);
|
|
quat[3] = (float)cos(0.5f * angle);
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -140,15 +140,15 @@ void Display(void)
|
|
{
|
|
{
|
|
float v[4]; // will be used to set light paramters
|
|
float v[4]; // will be used to set light paramters
|
|
float mat[4*4]; // rotation matrix
|
|
float mat[4*4]; // rotation matrix
|
|
-
|
|
|
|
|
|
+
|
|
// Clear frame buffer
|
|
// Clear frame buffer
|
|
glClearColor(0, 0, 0, 1);
|
|
glClearColor(0, 0, 0, 1);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
-
|
|
|
|
|
|
+
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_DEPTH_TEST);
|
|
glDisable(GL_CULL_FACE);
|
|
glDisable(GL_CULL_FACE);
|
|
glEnable(GL_NORMALIZE);
|
|
glEnable(GL_NORMALIZE);
|
|
-
|
|
|
|
|
|
+
|
|
// Set light
|
|
// Set light
|
|
glEnable(GL_LIGHTING);
|
|
glEnable(GL_LIGHTING);
|
|
glEnable(GL_LIGHT0);
|
|
glEnable(GL_LIGHT0);
|
|
@@ -158,15 +158,15 @@ void Display(void)
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, v);
|
|
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;
|
|
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);
|
|
glLightfv(GL_LIGHT0, GL_POSITION, v);
|
|
-
|
|
|
|
|
|
+
|
|
// Set material
|
|
// Set material
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient);
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, g_MatAmbient);
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse);
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, g_MatDiffuse);
|
|
-
|
|
|
|
|
|
+
|
|
// Rotate and draw shape
|
|
// Rotate and draw shape
|
|
glPushMatrix();
|
|
glPushMatrix();
|
|
glTranslatef(0.5f, -0.3f, 0.0f);
|
|
glTranslatef(0.5f, -0.3f, 0.0f);
|
|
- if( g_AutoRotate )
|
|
|
|
|
|
+ if( g_AutoRotate )
|
|
{
|
|
{
|
|
float axis[3] = { 0, 1, 0 };
|
|
float axis[3] = { 0, 1, 0 };
|
|
float angle = (float)(glutGet(GLUT_ELAPSED_TIME)-g_RotateTime)/1000.0f;
|
|
float angle = (float)(glutGet(GLUT_ELAPSED_TIME)-g_RotateTime)/1000.0f;
|
|
@@ -179,13 +179,13 @@ void Display(void)
|
|
glScalef(g_Zoom, g_Zoom, g_Zoom);
|
|
glScalef(g_Zoom, g_Zoom, g_Zoom);
|
|
glCallList(g_CurrentShape);
|
|
glCallList(g_CurrentShape);
|
|
glPopMatrix();
|
|
glPopMatrix();
|
|
-
|
|
|
|
|
|
+
|
|
// Draw tweak bars
|
|
// Draw tweak bars
|
|
TwDraw();
|
|
TwDraw();
|
|
-
|
|
|
|
|
|
+
|
|
// Present frame buffer
|
|
// Present frame buffer
|
|
glutSwapBuffers();
|
|
glutSwapBuffers();
|
|
-
|
|
|
|
|
|
+
|
|
// Recall Display at next frame
|
|
// Recall Display at next frame
|
|
glutPostRedisplay();
|
|
glutPostRedisplay();
|
|
}
|
|
}
|
|
@@ -203,7 +203,7 @@ void Reshape(int width, int height)
|
|
glLoadIdentity();
|
|
glLoadIdentity();
|
|
gluLookAt(0,0,5, 0,0,0, 0,1,0);
|
|
gluLookAt(0,0,5, 0,0,0, 0,1,0);
|
|
glTranslatef(0, 0.6f, -1);
|
|
glTranslatef(0, 0.6f, -1);
|
|
-
|
|
|
|
|
|
+
|
|
// Send the new window size to AntTweakBar
|
|
// Send the new window size to AntTweakBar
|
|
TwWindowSize(width, height);
|
|
TwWindowSize(width, height);
|
|
}
|
|
}
|
|
@@ -211,11 +211,11 @@ void Reshape(int width, int height)
|
|
|
|
|
|
// Function called at exit
|
|
// Function called at exit
|
|
void Terminate(void)
|
|
void Terminate(void)
|
|
-{
|
|
|
|
|
|
+{
|
|
rebar.save(REBAR_NAME);
|
|
rebar.save(REBAR_NAME);
|
|
|
|
|
|
glDeleteLists(SHAPE_TEAPOT, NUM_SHAPES);
|
|
glDeleteLists(SHAPE_TEAPOT, NUM_SHAPES);
|
|
-
|
|
|
|
|
|
+
|
|
TwTerminate();
|
|
TwTerminate();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -224,9 +224,9 @@ void Terminate(void)
|
|
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
|
|
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
|
|
{
|
|
{
|
|
(void)clientData; // unused
|
|
(void)clientData; // unused
|
|
-
|
|
|
|
|
|
+
|
|
g_AutoRotate = *(const int *)(value); // copy value to g_AutoRotate
|
|
g_AutoRotate = *(const int *)(value); // copy value to g_AutoRotate
|
|
- if( g_AutoRotate!=0 )
|
|
|
|
|
|
+ if( g_AutoRotate!=0 )
|
|
{
|
|
{
|
|
// init rotation
|
|
// init rotation
|
|
g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
|
|
g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
|
|
@@ -234,7 +234,7 @@ void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
|
|
g_RotateStart[1] = g_Rotation[1];
|
|
g_RotateStart[1] = g_Rotation[1];
|
|
g_RotateStart[2] = g_Rotation[2];
|
|
g_RotateStart[2] = g_Rotation[2];
|
|
g_RotateStart[3] = g_Rotation[3];
|
|
g_RotateStart[3] = g_Rotation[3];
|
|
-
|
|
|
|
|
|
+
|
|
// make Rotation variable read-only
|
|
// make Rotation variable read-only
|
|
TwDefine(" TweakBar/ObjRotation readonly ");
|
|
TwDefine(" TweakBar/ObjRotation readonly ");
|
|
}
|
|
}
|
|
@@ -257,28 +257,28 @@ int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
|
|
float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
|
|
float angle = 0.8f;
|
|
float angle = 0.8f;
|
|
-
|
|
|
|
|
|
+
|
|
// Initialize AntTweakBar
|
|
// Initialize AntTweakBar
|
|
// (note that AntTweakBar could also be intialized after GLUT, no matter)
|
|
// (note that AntTweakBar could also be intialized after GLUT, no matter)
|
|
if( !TwInit(TW_OPENGL, NULL) )
|
|
if( !TwInit(TW_OPENGL, NULL) )
|
|
{
|
|
{
|
|
- // A fatal error occured
|
|
|
|
|
|
+ // A fatal error occured
|
|
fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
|
|
fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Initialize GLUT
|
|
// Initialize GLUT
|
|
glutInit(&argc, argv);
|
|
glutInit(&argc, argv);
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
|
glutInitWindowSize(640, 480);
|
|
glutInitWindowSize(640, 480);
|
|
glutCreateWindow("AntTweakBar simple example using GLUT");
|
|
glutCreateWindow("AntTweakBar simple example using GLUT");
|
|
glutCreateMenu(NULL);
|
|
glutCreateMenu(NULL);
|
|
-
|
|
|
|
|
|
+
|
|
// Set GLUT callbacks
|
|
// Set GLUT callbacks
|
|
glutDisplayFunc(Display);
|
|
glutDisplayFunc(Display);
|
|
glutReshapeFunc(Reshape);
|
|
glutReshapeFunc(Reshape);
|
|
atexit(Terminate); // Called after glutMainLoop ends
|
|
atexit(Terminate); // Called after glutMainLoop ends
|
|
-
|
|
|
|
|
|
+
|
|
// Set GLUT event callbacks
|
|
// Set GLUT event callbacks
|
|
// - Directly redirect GLUT mouse button events to AntTweakBar
|
|
// - Directly redirect GLUT mouse button events to AntTweakBar
|
|
glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
|
|
glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
|
|
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
|
|
// - Send 'glutGetModifers' function pointer to AntTweakBar;
|
|
// - Send 'glutGetModifers' function pointer to AntTweakBar;
|
|
// required because the GLUT key event functions do not report key modifiers states.
|
|
// required because the GLUT key event functions do not report key modifiers states.
|
|
TwGLUTModifiersFunc(glutGetModifiers);
|
|
TwGLUTModifiersFunc(glutGetModifiers);
|
|
-
|
|
|
|
|
|
+
|
|
// Create some 3D objects (stored in display lists)
|
|
// Create some 3D objects (stored in display lists)
|
|
glNewList(SHAPE_TEAPOT, GL_COMPILE);
|
|
glNewList(SHAPE_TEAPOT, GL_COMPILE);
|
|
glutSolidTeapot(1.0);
|
|
glutSolidTeapot(1.0);
|
|
@@ -307,40 +307,40 @@ int main(int argc, char *argv[])
|
|
glNewList(SHAPE_SPHERE, GL_COMPILE);
|
|
glNewList(SHAPE_SPHERE, GL_COMPILE);
|
|
glutSolidSphere(1.0, 50, 40);
|
|
glutSolidSphere(1.0, 50, 40);
|
|
glEndList();
|
|
glEndList();
|
|
-
|
|
|
|
|
|
+
|
|
// Create a tweak bar
|
|
// Create a tweak bar
|
|
rebar.TwNewBar("TweakBar");
|
|
rebar.TwNewBar("TweakBar");
|
|
TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
|
|
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
|
|
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].
|
|
// Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
|
|
- rebar.TwAddVarRW("Zoom", TW_TYPE_FLOAT, &g_Zoom,
|
|
|
|
|
|
+ rebar.TwAddVarRW("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).' ");
|
|
" 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
|
|
// Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
|
|
- rebar.TwAddVarRW("ObjRotation", TW_TYPE_QUAT4F, &g_Rotation,
|
|
|
|
|
|
+ rebar.TwAddVarRW("ObjRotation", TW_TYPE_QUAT4F, &g_Rotation,
|
|
" label='Object rotation' open help='Change the object orientation.' ");
|
|
" label='Object rotation' open help='Change the object orientation.' ");
|
|
-
|
|
|
|
|
|
+
|
|
// Add callback to toggle auto-rotate mode (callback functions are defined above).
|
|
// Add callback to toggle auto-rotate mode (callback functions are defined above).
|
|
- rebar.TwAddVarCB("AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL,
|
|
|
|
|
|
+ rebar.TwAddVarCB("AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL,
|
|
" label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");
|
|
" 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 [-].
|
|
// Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
|
|
- rebar.TwAddVarRW("Multiplier", TW_TYPE_DOUBLE, &g_LightMultiplier,
|
|
|
|
|
|
+ rebar.TwAddVarRW("Multiplier", TW_TYPE_DOUBLE, &g_LightMultiplier,
|
|
" label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");
|
|
" 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
|
|
// Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
|
|
- rebar.TwAddVarRW("Light Dir", TW_TYPE_DIR3F, &g_LightDirection,
|
|
|
|
|
|
+ rebar.TwAddVarRW("Light Dir", TW_TYPE_DIR3F, &g_LightDirection,
|
|
" label='Light direction' open help='Change the light direction.' ");
|
|
" 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)
|
|
// 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'.
|
|
// and is inserted into a group named 'Material'.
|
|
rebar.TwAddVarRW("Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");
|
|
rebar.TwAddVarRW("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)
|
|
// 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'.
|
|
// and is inserted into group 'Material'.
|
|
rebar.TwAddVarRW("Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");
|
|
rebar.TwAddVarRW("Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");
|
|
-
|
|
|
|
|
|
+
|
|
// Add the enum variable 'g_CurrentShape' to 'bar'
|
|
// Add the enum variable 'g_CurrentShape' to 'bar'
|
|
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
|
|
// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
|
|
{
|
|
{
|
|
@@ -351,7 +351,7 @@ int main(int argc, char *argv[])
|
|
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
|
|
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
|
|
rebar.TwAddVarRW("Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
|
|
rebar.TwAddVarRW("Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Store time
|
|
// Store time
|
|
g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
|
|
g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
|
|
// Init rotation
|
|
// Init rotation
|
|
@@ -373,10 +373,10 @@ int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
printf("%s ReAntTweakBar file does not exist (yet).\n",REBAR_NAME);
|
|
printf("%s ReAntTweakBar file does not exist (yet).\n",REBAR_NAME);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Call the GLUT main loop
|
|
// Call the GLUT main loop
|
|
glutMainLoop();
|
|
glutMainLoop();
|
|
-
|
|
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|