bool ATB::Init() { bool ret = false; if (TwInit(TW_OPENGL_CORE, NULL) == 1) { TwStructMember Vector3fMembers[] = { { "x", TW_TYPE_FLOAT, offsetof(Vector3f, x), "" }, { "y", TW_TYPE_FLOAT, offsetof(Vector3f, y), "" }, { "z", TW_TYPE_FLOAT, offsetof(Vector3f, z), "" } }; TW_TYPE_OGLDEV_VECTOR3F = TwDefineStruct("Vector3f", Vector3fMembers, 3, sizeof(Vector3f), NULL, NULL); TwStructMember AttenuationMembers[] = { { "Const", TW_TYPE_FLOAT, offsetof(LightAttenuation, Constant), "" }, { "Linear", TW_TYPE_FLOAT, offsetof(LightAttenuation, Linear), "" }, { "Exp", TW_TYPE_FLOAT, offsetof(LightAttenuation, Exp), "" } }; TW_TYPE_OGLDEV_ATTENUATION = TwDefineStruct("Attenuation", AttenuationMembers, 3, sizeof(LightAttenuation), NULL, NULL); ret = true; } return ret; }
/* ============================== ============================== */ TwStructs::TwStructs() { ASSERT(instance == 0); instance = this; // adding euler struct types[TW_STRUCT_EULER] = TwDefineStruct("Euler", eulerMembers, 3, sizeof(float)*3, NULL, NULL); types[TW_STRUCT_POSITION] = TwDefineStruct("Position", positionMembers, 3, sizeof(float)*3, NULL, NULL); }
SceneDialog::SceneDialog() { // Create a tweak bar m_dialog = TwNewBar("Scene"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar into a DirectX11 application.' "); // Message added to the help bar. int barSize[2] = {200, 1060}; TwSetParam(m_dialog, NULL, "size", TW_PARAM_INT32, 2, barSize); TwDefine(" Scene position='10 10' "); TwAddButton(m_dialog, "Load Scene", LoadAGL, this, " label='Load Scene' key=c help='Load an Agile file into the editor.' group='I/O'"); TwAddButton(m_dialog, "Save Scene", SaveAGL, this, " label='Save Scene' key=c help='Save a scene into an Agile file.' group='I/O'"); TwAddVarRW(m_dialog, "Rotation", TW_TYPE_QUAT4F, Scene::GetInstance()->GetQuaternionRotation(), "opened=true axisz=-z"); TwStructMember pointMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(AglVector3, x), " Step=0.01 " }, { "Y", TW_TYPE_FLOAT, offsetof(AglVector3, y), " Step=0.01 " }, { "Z", TW_TYPE_FLOAT, offsetof(AglVector3, z), " Step=0.01 " }}; TwType pointType = TwDefineStruct("POINT", pointMembers, 3, sizeof(AglVector3), NULL, NULL); TwAddVarRW(m_dialog, "Position", pointType, Scene::GetInstance()->GetPosition(), ""); TwAddVarRW(m_dialog, "ShowHideDiffuse", TW_TYPE_BOOLCPP, &DIFFUSEON, "group='Show/Hide'"); TwAddVarRW(m_dialog, "ShowHideSpec", TW_TYPE_BOOLCPP, &SPECULARON, "group='Show/Hide'"); TwAddVarRW(m_dialog, "ShowHideGlow", TW_TYPE_BOOLCPP, &GLOWON, "group='Show/Hide'"); TwAddVarRW(m_dialog, "ShowHideNormal", TW_TYPE_BOOLCPP, &NORMALON, "group='Show/Hide'"); m_meshDialog = new MeshDialog(); m_materialDialog = new MaterialDialog(); m_particleSystemDialog = new ParticleSystemDialog(); m_mergeDialog = new MergeDialog(); }
void MaterialDialog::setMaterial(int pIndex) { if (m_dialog) TwDeleteBar(m_dialog); // Create a tweak bar m_dialog = TwNewBar("Material"); int barSize[2] = {200, 1060}; TwDefine(" Material position='1710 10' "); TwSetParam(m_dialog, NULL, "size", TW_PARAM_INT32, 2, barSize); m_material = Scene::GetInstance()->GetMaterial(pIndex); TwAddVarCB(m_dialog, "MaterialName", TW_TYPE_CDSTRING, SetName, GetName, (void*)this, " label='Name: '"); TwAddVarRW(m_dialog, "Ambient", TW_TYPE_COLOR3F, (void*)&m_material->ambient, " help='Light color.' group='Properties'"); TwAddVarRW(m_dialog, "Diffuse", TW_TYPE_COLOR3F, (void*)&m_material->diffuse, " help='Light color.' group='Properties'"); TwAddVarRW(m_dialog, "Specular", TW_TYPE_COLOR3F, (void*)&m_material->specular, " help='Light color.' group='Properties'"); TwAddVarRW(m_dialog, "Emissive", TW_TYPE_COLOR3F, (void*)&m_material->emissive, " help='Light color.' group='Properties'"); TwAddVarRW(m_dialog, "Opacity", TW_TYPE_FLOAT, (void*)&m_material->opacity, " help='Light color.' group='Properties' min=0.0 max=1.0 step=0.01"); TwAddVarRW(m_dialog, "Reflectivity", TW_TYPE_FLOAT, (void*)&m_material->reflectivity, " help='Light color.' group='Properties' min=0.0 max=1.0 step=0.01"); TwAddVarRW(m_dialog, "Shininess", TW_TYPE_FLOAT, (void*)&m_material->shininess, " help='Light color.' group='Properties' min=0.0 max=100.0 step=1.0"); TwAddVarRW(m_dialog, "Texture Scale", TW_TYPE_FLOAT, (void*)&m_material->textureScale, " help='Light color.' group='Properties' min=0.0 max=10.0 step=0.01"); TwAddButton(m_dialog, "Load Diffuse Texture", LoadDiffuse, this, " label='Diffuse Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwAddButton(m_dialog, "Load Specular Texture", LoadSpecular, this, " label='Specular Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwAddButton(m_dialog, "Load Glow Texture", LoadGlow, this, " label='Glow Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwAddButton(m_dialog, "Load Normal Texture", LoadNormal, this, " label='Normal Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwAddButton(m_dialog, "Load Displacement Texture", LoadDisplacement, this, " label='Displacement Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwAddButton(m_dialog, "Load Gradient Texture", LoadGradient, this, " label='Gradient Texture' key=c help='Load an Agile file into the editor.' group='Load'"); TwStructMember tessMembers[] = { { "Edge1", TW_TYPE_FLOAT, offsetof(AglVector4, x), " Step=0.1 min=1.0 max=64.0" }, { "Edge2", TW_TYPE_FLOAT, offsetof(AglVector4, y), " Step=0.1 min=1.0 max=64.0" }, { "Edge3", TW_TYPE_FLOAT, offsetof(AglVector4, z), " Step=0.1 min=1.0 max=64.0" }, { "Internal", TW_TYPE_FLOAT, offsetof(AglVector4, w), " Step=0.1 min=1.0 max=64.0" }}; TwType tessType = TwDefineStruct("TESSELATIONFACTORS", tessMembers, 4, sizeof(AglVector4), NULL, NULL); TwAddVarRW(m_dialog, "Tess", tessType, &m_material->tesselationFactor, " group='Properties' "); TwAddVarRW(m_dialog, "Displacement", TW_TYPE_FLOAT, (void*)&m_material->displacement, " group='Properties' min=0.0 max=10.0 step=0.01"); TwAddButton(m_dialog, "Add Layer", AddLayer, this, " label='Add Layer' key=c help='Load an Agile file into the editor.' group='Gradient Mapping'"); TwAddButton(m_dialog, "Delete", Delete, this, ""); if (m_material->gradientDataIndex >= 0) { AglGradient* g = Scene::GetInstance()->GetGradient(m_material->gradientDataIndex); vector<AglGradientMaterial*> layers = g->getLayers(); for (unsigned int i = 0; i < layers.size(); i++) { AddLayer(g, layers[i], i); } } show(); }
void ControlUI::initTwType() { TwStructMember vec3fMembers[] = { { "x", TW_TYPE_FLOAT, offsetof(math::Vector3f, x), "" }, { "y", TW_TYPE_FLOAT, offsetof(math::Vector3f, y), "" }, { "z", TW_TYPE_FLOAT, offsetof(math::Vector3f, z), "" } }; mVector3fType = TwDefineStruct("Vector3f", vec3fMembers, 3, sizeof(math::Vector3f), 0, 0); //----- TwStructMember vec4fMembers[] = { { "x", TW_TYPE_FLOAT, offsetof(XMVECTOR, x), "" }, { "y", TW_TYPE_FLOAT, offsetof(XMVECTOR, y), "" }, { "z", TW_TYPE_FLOAT, offsetof(XMVECTOR, z), "" }, { "w", TW_TYPE_FLOAT, offsetof(XMVECTOR, w), "" } }; mVector4fType = TwDefineStruct("Vector4f", vec4fMembers, 4, sizeof(XMVECTOR), NULL, NULL); }
void TweakBar::Create(ID3D11Device* pd3dDevice) { TwInit(TW_DIRECT3D11, pd3dDevice); TwType TW_TYPE_XMINT3 = TwDefineStruct("TW_TYPE_XMINT3", TW_XMINT3, 3, sizeof(XMINT3), nullptr, nullptr); TwType TW_TYPE_BLOCK = TwDefineStruct("TW_TYPE_BLOCK", TW_BLOCK, 5, sizeof(Block), nullptr, nullptr); //m_pBar = TwNewBar("DebugTweakBar"); //TwAddSeparator(m_pBar, "Timing", nullptr); //TwAddVarRO(m_pBar, "FPS", TW_TYPE_FLOAT, &RATHEngine::GetEngine()->m_State.m_FPS, " label='FPS: ' "); //TwAddVarRO(m_pBar, "Runtime", TW_TYPE_DOUBLE, &RATHEngine::GetEngine()->m_State.m_Time, " label='Runtime: ' "); //TwAddSeparator(m_pBar, "Light", nullptr); //TwAddVarRW(m_pBar, "Lightdirection", TW_TYPE_DIR3F, &pScene->mLightDirection, " label='Light direction: ' opened=true axisz=-z showval=false"); //TwAddSeparator(m_pBar, "Blockview", nullptr); //TwAddVarRO(m_pBar, "Block", TW_TYPE_BLOCK, &pScene->mViewedBlock, " label='Block: ' "); //TwAddVarRO(m_pBar, "Blockpos", TW_TYPE_XMINT3, &pScene->mBlockCoord, " label='Block position: ' "); //TwDefine(" DebugTweakBar iconified=true "); }
CDebugHelperImplementation::CDebugHelperImplementation(void *device) { // TODO: inicializar AntTweakBar int status = TwInit(TW_DIRECT3D11, device); assert(status); { TwStructMember structMembers[] = { { "x", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Position) + offsetof(Vect3f, x), "step=0.5 precision=1" }, { "y", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Position) + offsetof(Vect3f, y), "step=0.5 precision=1" }, { "z", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Position) + offsetof(Vect3f, z), "step=0.5 precision=1" }, { "yaw", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Yaw), "step=0.05 precision=2" }, { "pitch", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Pitch), "step=0.05 precision=2" }, { "roll", TW_TYPE_FLOAT, offsetof(SPositionOrientation, Roll), "step=0.05 precision=2" } }; m_PosRotType = TwDefineStruct("POSITION_ORIENTATION", structMembers, 6, sizeof(SPositionOrientation), nullptr, nullptr); } }
// Create a tweak bar for lights. // New enum type and struct type are defined and used by this bar. void Scene::CreateBar() { // Create a new tweak bar and change its label, position and transparency lightsBar = TwNewBar("Lights"); TwDefine(" Lights label='Lights TweakBar' position='580 16' alpha=0 help='Use this bar to edit the lights in the scene.' "); // Add a variable of type int to control the number of lights TwAddVarRW(lightsBar, "NumLights", TW_TYPE_INT32, &NumLights, " label='Number of lights' keyIncr=l keyDecr=L help='Changes the number of lights in the scene.' "); // Set the NumLights min value (=0) and max value (depends on the user graphic card) int zero = 0; TwSetParam(lightsBar, "NumLights", "min", TW_PARAM_INT32, 1, &zero); TwSetParam(lightsBar, "NumLights", "max", TW_PARAM_INT32, 1, &maxLights); // Note, TwDefine could also have been used for that pupose like this: // char def[256]; // _snprintf(def, 255, "Lights/NumLights min=0 max=%d", maxLights); // TwDefine(def); // min and max are defined using a definition string // Add a button to re-initialize the lights; this button calls the ReinitCB callback function TwAddButton(lightsBar, "Reinit", ReinitCB, this, " label='Change lights' key=c help='Random changes of lights parameters.' "); // Define a new enum type for the tweak bar TwEnumVal modeEV[] = // array used to describe the Scene::AnimMode enum values { { Light::ANIM_FIXED, "Fixed" }, { Light::ANIM_BOUNCE, "Bounce" }, { Light::ANIM_ROTATE, "Rotate" }, { Light::ANIM_COMBINED, "Combined" } }; TwType modeType = TwDefineEnum("Mode", modeEV, 4); // create a new TwType associated to the enum defined by the modeEV array // Define a new struct type: light variables are embedded in this structure TwStructMember lightMembers[] = // array used to describe tweakable variables of the Light structure { { "Active", TW_TYPE_BOOLCPP, offsetof(Light, Active), " help='Enable/disable the light.' " }, // Light::Active is a C++ boolean value { "Color", TW_TYPE_COLOR4F, offsetof(Light, Color), " noalpha help='Light color.' " }, // Light::Color is represented by 4 floats, but alpha channel should be ignored { "Radius", TW_TYPE_FLOAT, offsetof(Light, Radius), " min=0 max=4 step=0.02 help='Light radius.' " }, { "Animation", modeType, offsetof(Light, Animation), " help='Change the animation mode.' " }, // use the enum 'modeType' created before to tweak the Light::Animation variable { "Speed", TW_TYPE_FLOAT, offsetof(Light, Speed0), " readonly=true help='Light moving speed.' " } // Light::Speed is made read-only }; TwType lightType = TwDefineStruct("Light", lightMembers, 5, sizeof(Light), NULL, NULL); // create a new TwType associated to the struct defined by the lightMembers array // Use the newly created 'lightType' to add variables associated with lights for(int i=0; i<maxLights; ++i) // Add 'maxLights' variables of type lightType; { // unused lights variables (over NumLights) will hidden by Scene::Update( ) _snprintf(lights[i].Name, sizeof(lights[i].Name), "%d", i+1); // Create a name for each light ("1", "2", "3",...) TwAddVarRW(lightsBar, lights[i].Name, lightType, &lights[i], " group='Edit lights' "); // Add a lightType variable and group it into the 'Edit lights' group // Set 'label' and 'help' parameters of the light char paramValue[64]; _snprintf(paramValue, sizeof(paramValue), "Light #%d", i+1); TwSetParam(lightsBar, lights[i].Name, "label", TW_PARAM_CSTRING, 1, paramValue); // Set label _snprintf(paramValue, sizeof(paramValue), "Parameters of the light #%d", i+1); TwSetParam(lightsBar, lights[i].Name, "help", TW_PARAM_CSTRING, 1, paramValue); // Set help // Note, parameters could also have been set using the define string of TwAddVarRW like this: // char def[256]; // _snprintf(def, sizeof(def), "group='Edit lights' label='Light #%d' help='Parameters of the light #%d' ", i+1, i+1); // TwAddVarRW(lightsBar, lights[i].Name, lightType, &lights[i], def); // Add a lightType variable, group it into the 'Edit lights' group, and name it 'Light #n' } }
TwType myDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize) { return TwDefineStruct(name, structMembers, nbMembers, structSize, HandleSummary, NULL); }
int main(int argc, char *argv[]) { const SDL_VideoInfo* video = NULL; bool bQuit = false; if( g_Screen.initialize() < 0 ) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } video = SDL_GetVideoInfo(); if( !video ) { fprintf(stderr, "Video query failed: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); g_Screen.m_bpp = video->vfmt->BitsPerPixel; fprintf(stderr, "BPP %d\n", video->vfmt->BitsPerPixel); if (g_Screen.m_bpp == 16) { fprintf(stderr, "WARNING:Running at 16bit expecting decreased performance\nChanging Desktop depth to 32bit may correct this problem\n"); } g_Screen.m_flags = SDL_OPENGL | SDL_HWSURFACE | SDL_RESIZABLE; g_Screen.m_width = 800; g_Screen.m_height = 600; g_Screen.m_useVBO = false; //flags |= SDL_FULLSCREEN; if( !g_Screen.setVideoMode() ) { fprintf(stderr, "Video mode set failed: %s", SDL_GetError()); SDL_Quit(); exit(1); } SDL_WM_SetCaption("Pie Toaster powered by AntTweakBar+SDL", "WZ Stats Tools"); // Enable SDL unicode and key-repeat SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Set OpenGL viewport and states glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); // use default light diffuse and position //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glShadeModel(GL_SMOOTH); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); /// pie vertex type TwStructMember vertice3fMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.x), "step=0.1" }, { "Y", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.y), "step=0.1" }, { "Z", TW_TYPE_FLOAT, offsetof(_vertice_list, vertice.z), "step=0.1" }, { "Selected", TW_TYPE_BOOLCPP, offsetof(_vertice_list, selected), "" }, }; g_tw_pieVertexType = TwDefineStruct("VerticePie", vertice3fMembers, 4, sizeof(_vertice_list), NULL, NULL); TwStructMember vector2fMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(Vector2f, x), "min=0 max=4096 step=1" }, { "Y", TW_TYPE_FLOAT, offsetof(Vector2f, y), "min=0 max=4096 step=1" }, }; g_tw_pieVector2fType = TwDefineStruct("Vector2fPie", vector2fMembers, 2, sizeof(Vector2f), NULL, NULL); // Tell the window size to AntTweakBar TwWindowSize(g_Screen.m_width, g_Screen.m_height); iIMDShape *testIMD = NULL; //ResMaster = new CResMaster; ResMaster.getOGLExtensionString(); if (ResMaster.isOGLExtensionAvailable("GL_ARB_vertex_buffer_object")) { g_Screen.initializeVBOExtension(); } ResMaster.cacheGridsVertices(); ResMaster.readTextureList("pages.txt"); ResMaster.loadTexPages(); ResMaster.addGUI(); #ifdef SDL_TTF_TEST if (!(ResMaster.initFont() && ResMaster.loadFont("FreeMono.ttf", 12))) { return 1; } #endif //argc = 2; //argv[1] = "building1b.pie"; if (argc < 2) { fprintf(stderr, "NOTE:no file specified\n"); //ResMaster.addPie(testIMD, "newpie"); //No need to add new pie for now } else { testIMD = iV_ProcessIMD(argv[1]); if (testIMD == NULL) { fprintf(stderr, "no file specified\n creating new one...\n"); ResMaster.addPie(testIMD, "newpie"); } else { ResMaster.addPie(testIMD, argv[1]); } } //ResMaster.getPieAt(0)->ToFile("test13.pie"); OpenFileDialog.m_Up = false; while( !bQuit ) { SDL_Event event; int handled; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Set OpenGL camera glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //updateBars(); inputUpdate(); // Process incoming events while( SDL_PollEvent(&event) ) { if (OpenFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { OpenFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { OpenFileDialog.doFunction(); OpenFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; OpenFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } OpenFileDialog.incrementChar(key); } OpenFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (AddSubModelDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { AddSubModelDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { AddSubModelDialog.doFunction(); AddSubModelDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; AddSubModelDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } AddSubModelDialog.incrementChar(key); } AddSubModelDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (AddSubModelFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { AddSubModelFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { AddSubModelFileDialog.doFunction(); AddSubModelFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; AddSubModelFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } AddSubModelFileDialog.incrementChar(key); } AddSubModelFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (ReadAnimFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { ReadAnimFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { ReadAnimFileDialog.doFunction(); ReadAnimFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; ReadAnimFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } ReadAnimFileDialog.incrementChar(key); } ReadAnimFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } else if (WriteAnimFileDialog.m_Up) { if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if (key == SDLK_BACKSPACE) { WriteAnimFileDialog.decrementChar(); } else if (key == SDLK_KP_ENTER || key == SDLK_RETURN) { WriteAnimFileDialog.doFunction(); WriteAnimFileDialog.deleteTextBox(); continue; } else if (key == SDLK_PAUSE || key == SDLK_ESCAPE) { //cancels current action and closes text box //OpenFileDialog.text_pointer = NULL; WriteAnimFileDialog.deleteTextBox(); continue; } else if (key > 12 && key < 128) { if (modifier & KMOD_CAPS || modifier & KMOD_LSHIFT || modifier & KMOD_RSHIFT) { if (key >= 'a' && key <= 'z') { key = toupper(key); } else { key = shiftChar(key); } } WriteAnimFileDialog.incrementChar(key); } WriteAnimFileDialog.updateTextBox(); //interrupts input when text box is up continue; } } if (event.type == SDL_KEYDOWN) { Uint16 key = event.key.keysym.sym; SDLMod modifier = event.key.keysym.mod; if ((key == SDLK_KP_ENTER || key == SDLK_RETURN) && modifier & KMOD_LALT) { // Resize SDL video mode g_Screen.m_flags ^= SDL_FULLSCREEN; if( !g_Screen.setVideoMode() ) fprintf(stderr, "WARNING: Video mode set failed: %s", SDL_GetError()); // Resize OpenGL viewport glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); if (ResMaster.isTextureMapperUp()) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, g_Screen.m_width, 0, g_Screen.m_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } else { // Restore OpenGL states (SDL seems to lost them) glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); } glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); // Reloads texture and bind ResMaster.freeTexPages(); ResMaster.loadTexPages(); ResMaster.cacheGridsVertices(); // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { ResMaster.getPieAt(index)->flushVBOPolys(); } SDL_Event newEvent; newEvent.type = SDL_VIDEORESIZE; newEvent.resize.w = g_Screen.m_width; newEvent.resize.h = g_Screen.m_height; SDL_PushEvent(&newEvent); } } // Send event to AntTweakBar handled = TwEventSDL(&event); // If event has not been handled by AntTweakBar, process it if( !handled ) { switch( event.type ) { case SDL_KEYUP: case SDL_KEYDOWN: inputKeyEvent(event.key, event.type); break; case SDL_MOUSEMOTION: inputMotionMouseEvent(event.motion); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: inputButtonMouseEvent(event.button, event.type); break; case SDL_QUIT: // Window is closed bQuit = true; break; case SDL_VIDEORESIZE: // Window size has changed // Resize SDL video mode g_Screen.m_width = event.resize.w; g_Screen.m_height = event.resize.h; if( !g_Screen.setVideoMode() ) fprintf(stderr, "WARNING: Video mode set failed: %s", SDL_GetError()); // Resize OpenGL viewport glViewport(0, 0, g_Screen.m_width, g_Screen.m_height); if (ResMaster.isTextureMapperUp()) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, g_Screen.m_width, 0, g_Screen.m_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } else { // Restore OpenGL states (SDL seems to lost them) glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); gluPerspective(30, (double)g_Screen.m_width/g_Screen.m_height, 1, 1000); gluLookAt(0,0,250, 0,0,0, 0,1,0); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glEnable(GL_NORMALIZE); //glEnable(GL_COLOR_MATERIAL); } glDisable(GL_CULL_FACE); //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); // Reloads texture and bind ResMaster.freeTexPages(); ResMaster.loadTexPages(); ResMaster.cacheGridsVertices(); // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { ResMaster.getPieAt(index)->flushVBOPolys(); } // TwWindowSize has been called by TwEventSDL, so it is not necessary to call it again here. break; } } else { // Resets all keys and buttons inputInitialize(); // Input in TwBars rebuilds vbo's switch( event.type ) { case SDL_KEYUP: case SDL_KEYDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: // Flush vbo id's Uint32 index; for (index = 0;index < ResMaster.m_pieCount;index++) { CPieInternal *temp = ResMaster.getPieAt(index); if (temp) { temp->flushVBOPolys(); } } break; default: break; } } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,0.0f,0.0f); glColor4ub(255, 255, 255, 255); ResMaster.logic(); ResMaster.draw(); ResMaster.updateInput(); // Draw tweak bars TwDraw(); // Present frame buffer SDL_GL_SwapBuffers(); SDL_Delay(10); } // Remove TW bars //removeBars(); // Terminate AntTweakBar TwTerminate(); // Terminate SDL SDL_Quit(); ResMaster.~CResMaster(); return 1; }
// ------ AntTweakBar setup ----------------- bool rtvsD3dApp::setupAntTW(LPDIRECT3DDEVICE9 pd3dDevice) { TwInit(TW_DIRECT3D9, pd3dDevice); // for Direct3D 9 TwBar *myBar; myBar = TwNewBar("Options"); TwDefine(" Options label='Raytracer Options' refresh=0.5 position='16 16' size='260 320' alpha=0"); // for camera position.. struct position { float x, y, z; }; TwStructMember positionMembers[] = { {"x", TW_TYPE_FLOAT, offsetof(position, x), " Min=-12 Max=12 " }, {"y", TW_TYPE_FLOAT, offsetof(position, y), " Min=-7 Max=7 " }, {"z", TW_TYPE_FLOAT, offsetof(position, z), " Min=-5 Max=25 " } }; TwType positionType = TwDefineStruct("Position", positionMembers, 3, sizeof(position), NULL, NULL); Raytracer::Primitive* primitive; int primCount = m_pTracer->tracer->GetScene()->GetNrPrimitives(); for (int i = 0; i < primCount; i++) { static char label[32]; static char def[128]; static char grouping[64]; primitive = m_pTracer->tracer->GetScene()->GetPrimitive(i); int type = primitive->GetType(); switch (type) { case Raytracer::Primitive::SPHERE: if(primitive->IsLight()) { // add a light sprintf_s(label, 32, "Color%d", i+1); sprintf_s(def, 128, " group='Light%d' label='Color' ", i+1); TwAddVarRW(myBar, label, TW_TYPE_COLOR3F, &primitive->m_Material->m_Color, def ); sprintf_s(label, 32, "Position%d", i+1); sprintf_s(def, 128, " group='Light%d' label='Position' ", i+1); TwAddVarRW(myBar, label, positionType, &((Raytracer::Sphere*)primitive)->m_Centre, def ); sprintf_s(grouping, 64, " Options/Light%d group='Lights'", i+1); TwDefine(grouping); } else { // add a sphere sprintf_s(label, 32, "Color%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Color' ", i+1); TwAddVarRW(myBar, label, TW_TYPE_COLOR3F, &primitive->m_Material->m_Color, def ); sprintf_s(label, 32, "Position%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Position' ", i+1); TwAddVarRW(myBar, label, positionType, &((Raytracer::Sphere*)primitive)->m_Centre, def ); sprintf_s(label, 32, "Reflection%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Reflection' Min=0 Max=2.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Refl, def ); sprintf_s(label, 32, "Refraction%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Refraction' Min=0 Max=2.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Refr, def ); sprintf_s(label, 32, "Diffuse%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Diffuse' Min=0 Max=5.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Diff, def ); sprintf_s(label, 32, "Specular%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Specular' Min=0 Max=2.5 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Spec, def ); sprintf_s(label, 32, "Refraction Index%d", i+1); sprintf_s(def, 128, " group='Sphere%d' label='Refraction Index' Min=0 Max=5 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_RIndex, def ); sprintf_s(grouping, 64, " Options/Sphere%d group='Spheres' opened=false ", i+1); TwDefine(grouping); } break; case Raytracer::Primitive::PLANE: // add a plane break; case Raytracer::Primitive::AABB: // add a box sprintf_s(label, 32, "Color%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Color' ", i+1); TwAddVarRW(myBar, label, TW_TYPE_COLOR3F, &primitive->m_Material->m_Color, def ); sprintf_s(label, 32, "Position%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Position' ", i+1); TwAddVarRW(myBar, label, positionType, &((Raytracer::Sphere*)primitive)->m_Centre, def ); sprintf_s(label, 32, "Reflection%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Reflection' Min=0 Max=2.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Refl, def ); sprintf_s(label, 32, "Refraction%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Refraction' Min=0 Max=2.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Refr, def ); sprintf_s(label, 32, "Diffuse%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Diffuse' Min=0 Max=5.0 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Diff, def ); sprintf_s(label, 32, "Specular%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Specular' Min=0 Max=2.5 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_Spec, def ); sprintf_s(label, 32, "Refraction Index%d", i+1); sprintf_s(def, 128, " group='Box%d' label='Refraction Index' Min=0 Max=5 step=0.1 precision=1 ", i+1); TwAddVarRW(myBar, label, TW_TYPE_FLOAT, &((Raytracer::Sphere*)primitive)->m_Material->m_RIndex, def ); sprintf_s(grouping, 64, " Options/Box%d group='Box' opened=false ", i+1); TwDefine(grouping); break; } } TwDefine(" Options/Lights group='Settings' opened=false "); // put light group into settings group TwDefine(" Options/Spheres group='Settings' opened=false "); // put sphere group into settings group TwDefine(" Options/Box group='Settings' opened=false "); // put box group into settings group TwAddVarRW(myBar, "Position", positionType, &m_pTracer->m_cameraPosition, " group='Camera' "); TwAddVarRW(myBar, "Target", TW_TYPE_DIR3F, &m_pTracer->m_cameraTarget, " group='Camera' "); TwDefine(" Options/Camera group='Settings' "); // put camera group into settings group TwAddSeparator(myBar, "sepReset", " group='Settings' "); TwAddButton(myBar, "Reset Positions", TW_reset, this, " group='Settings' " ); TwAddSeparator(myBar, "sepActions", " group='Settings' "); TwAddVarRW(myBar, "Render", TW_TYPE_BOOLCPP, &m_antShouldRender, " key=SPACE "); TwAddButton(myBar, "Cancel", TW_cancel, this, NULL); TwAddButton(myBar, "Save", TW_save, this, " key=ENTER " ); return true; }
void CreateMenus (void) { { TwBar *bar = TwNewBar ("pentachoron"); TwDefine ("pentachoron label='Pentachoron'"); TwType rendermodeType; TwEnumVal rendermodeEV[] = { { 0, "compose" }, { 1, "color" }, { 2, "normal" }, { 3, "specular" }, { 4, "depth" }, { 5, "glow" }, { 6, "shadow" } }; rendermodeType = TwDefineEnum ("rendermode", rendermodeEV, 7); TwAddVarCB (bar, "FPS", TW_TYPE_UINT32, NULL, [&] (void *v, void*) { *(unsigned int*)v = fps; }, NULL, NULL); TwAddVarCB (bar, "rendermode", rendermodeType, [&] (const void *v, void*) { r->postprocess.SetRenderMode (*(unsigned int*)v); }, [&] (void *v, void*) { *(unsigned int*)v = r->postprocess.GetRenderMode (); }, NULL, NULL); TwAddVarCB (bar, "tile-based light culling", TW_TYPE_BOOLCPP, [&] (const void *v, void*) { r->composition.SetTileBased (*(bool*)v); }, [&] (void *v, void*){ *(bool*)v = r->composition.GetTileBased (); }, NULL, NULL); TwAddVarCB (bar, "wireframe", TW_TYPE_BOOLCPP, [&] (const void *v, void*) { r->gbuffer.SetWireframe (*(bool*)v); }, [&] (void *v, void*) { *(bool*)v = r->gbuffer.GetWireframe (); }, NULL, NULL); TwAddVarCB (bar, "tesslevel", TW_TYPE_UINT32, [&] (const void *v, void*) { r->geometry.SetTessLevel (*(uint32_t*)v); }, [&] (void *v, void*) { *(uint32_t*)v = r->geometry.GetTessLevel (); }, NULL, "label='tessellation level' min=1 max=64"); TwAddVarCB (bar, "displacement", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->geometry.SetDisplacement (*(float*)v); }, [&] (void *v, void*) { *(float*)v = r->geometry.GetDisplacement (); }, NULL, "label='displacement' min=0 step=0.01"); } { TwBar *bar = TwNewBar ("lights"); TwDefine ("lights label='Lights' iconified=true"); TwAddButton (bar, "add light", [&] (void*) { AddLight (); }, NULL, NULL); TwAddButton (bar, "remove", [&] (void*) { RemoveLight (); }, NULL, "label='remove light' visible=false"); TwAddVarRW (bar, "active", TW_TYPE_UINT32, &active_light, "label='active light' visible=false"); TwAddSeparator (bar, NULL, NULL); TwStructMember lightposDesc[] = { { "x", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.1" }, { "y", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.1" }, { "z", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.1" } }; TwStructMember attenuationDesc[] = { { "constant", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.01" }, { "linear", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.01" }, { "quadratic", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.01" }, { "cull distance", TW_TYPE_FLOAT, offsetof (glm::vec4, w), "step=0.1" } }; typedef struct spotparam { float angle; float penumbra_angle; float exponent; } spotparam_t; TwStructMember spotDesc[] = { { "angle", TW_TYPE_FLOAT, offsetof (spotparam_t, angle), "step=1 min=0 max=360" }, { "penumbra angle", TW_TYPE_FLOAT, offsetof (spotparam_t, penumbra_angle), "step=1 min=0 max=360" }, { "exponent", TW_TYPE_FLOAT, offsetof (spotparam_t, exponent), "step=0.1" } }; TwType lightposType = TwDefineStruct ("lightpos", lightposDesc, 3, sizeof (glm::vec4), NULL, NULL); TwType spotdescType = TwDefineStruct ("spotdesc", spotDesc, 3, sizeof (spotparam_t), NULL, NULL); TwType attenuationType = TwDefineStruct ("attenuation", attenuationDesc, 4, sizeof (glm::vec4), NULL, NULL); TwAddVarCB (bar, "position", lightposType, [&] (const void *v, void*) { r->GetLight (active_light).position = *(glm::vec4*)v; r->UpdateLight (active_light); }, [&] (void *v, void*) { *(glm::vec4*)v = r->GetLight (active_light).position; }, NULL, "visible=false"); TwAddVarCB (bar, "direction", TW_TYPE_DIR3F, [&] (const void *v, void*) { r->GetLight (active_light).direction = glm::vec4 (*(const glm::vec3*)v, 0.0f); r->UpdateLight (active_light); }, [&] (void *v, void*) { *(glm::vec3*)v = glm::vec3 (r->GetLight (active_light).direction); }, NULL, "visible=false"); TwAddVarCB (bar, "color", TW_TYPE_COLOR3F, [&] (const void *v, void*) { r->GetLight (active_light).color = glm::vec4 (*(const glm::vec3*)v, 1.0f); r->UpdateLight (active_light); }, [&] (void *v, void*) { *(glm::vec3*)v = glm::vec3 (r->GetLight (active_light).color); }, NULL, "visible=false"); TwAddVarCB (bar, "spot", spotdescType, [&] (const void *v, void*) { Light &light = r->GetLight (active_light); light.spot.exponent = ((spotparam_t*)v)->exponent; light.spot.angle = (((spotparam_t*)v)->angle) * PCH_PI / 180.0f; light.spot.cosine = cosf (light.spot.angle); light.spot.tangent = tanf (light.spot.angle); light.spot.penumbra_angle = ((spotparam_t*)v)->penumbra_angle * PCH_PI / 180.0f; light.spot.penumbra_cosine = cosf (light.spot.penumbra_angle); r->UpdateLight (active_light); }, [&] (void *v, void*){ const Light &light = r->GetLight (active_light); ((spotparam_t*)v)->exponent = light.spot.exponent; ((spotparam_t*)v)->angle = light.spot.angle * 180.0f / PCH_PI; ((spotparam_t*)v)->penumbra_angle = light.spot.penumbra_angle * 180.0f / PCH_PI; }, NULL, "visible=false"); TwAddVarCB (bar, "attenuation", attenuationType, [&] (const void *v, void*) { r->GetLight (active_light).attenuation = *(glm::vec4*)v; r->GetLight (active_light).attenuation.z /= 100.0f; r->UpdateLight (active_light); }, [&] (void *v, void*) { *(glm::vec4*)v = r->GetLight (active_light).attenuation; ((glm::vec4*)v)->z *= 100.0f; }, NULL, "visible=false"); TwAddVarCB (bar, "specular", TW_TYPE_COLOR3F, [&] (const void *v, void*) { r->GetLight (active_light).specular.color = *(const glm::vec3*)v; r->UpdateLight (active_light); }, [&] (void *v, void*) { *(glm::vec3*)v = r->GetLight (active_light).specular.color; }, NULL, "label='specular color' visible=false"); } { TwBar *bar = TwNewBar ("sky"); TwDefine ("sky label='Sky' iconified=true"); typedef struct perezcoefficients { union { struct { float A, B, C, D, E; }; float p[5]; }; } perezcoefficients_t; TwStructMember perezDesc[] = { { "Darkening/Brightening to the horizon", TW_TYPE_FLOAT, offsetof (perezcoefficients_t, A), "step=0.01" }, { "Luminance gradient near the horizon", TW_TYPE_FLOAT, offsetof (perezcoefficients_t, B), "step=0.01" }, { "Relative intensity of circumsolar region", TW_TYPE_FLOAT, offsetof (perezcoefficients_t, C), "step=0.01" }, { "Width of the circumsolar region", TW_TYPE_FLOAT, offsetof (perezcoefficients_t, D), "step=0.01" }, { "Relative backscatered light at the earth surface", TW_TYPE_FLOAT, offsetof (perezcoefficients_t, E), "step=0.01" } }; TwType perezType = TwDefineStruct ("perez", perezDesc, 5, sizeof (perezcoefficients_t), NULL, NULL); TwAddVarCB (bar, "turbidity", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.SetTurbidity (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetTurbidity (); }, NULL, "step=0.1 min=1.0 max=10.0"); TwAddVarCB (bar, "time", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.SetTimeOfDay (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetTimeOfDay (); }, NULL, "step=0.01 min=0.0 max=24.0"); TwType monthType; TwEnumVal monthEV[] = { { 0, "January" }, { 1, "February" }, { 2, "March" }, { 3, "April" }, { 4, "May" }, { 5, "June" }, { 6, "July" }, { 7, "August" }, { 8, "September" }, { 9, "October" }, { 10, "November" }, { 11, "December" } }; monthType = TwDefineEnum ("month", monthEV, 12); TwAddVarCB (bar, "month", monthType, [&] (const void *v, void*) { int month, day; ToCalendarDate (r->composition.GetDate (), &month, &day); month = *(const unsigned int*)v; r->composition.SetDate (ToOrdinalDate (month, day)); }, [&] (void *v, void*) { int month, day; ToCalendarDate (r->composition.GetDate (), &month, &day); *(unsigned int*)v = month; }, NULL, NULL); TwAddVarCB (bar, "day", TW_TYPE_UINT8, [&] (const void *v, void*) { int month, day; ToCalendarDate (r->composition.GetDate (), &month, &day); day = *(const unsigned char*)v; r->composition.SetDate (ToOrdinalDate (month, day)); }, [&] (void *v, void*) { int month, day; ToCalendarDate (r->composition.GetDate (), &month, &day); *(unsigned char*)v = day; }, NULL, "min=1 max=31"); TwAddVarCB (bar, "luminosity", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.SetSkyLuminosity (0.01f * *(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetSkyLuminosity () * 100.0f; }, NULL, "step=0.01"); TwAddVarCB (bar, "latitude", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.SetLatitude (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetLatitude (); }, NULL, "step=0.1 min=0.0 max=90.0"); TwAddVarCB (bar, "Y", perezType, [&] (const void *v, void*) { for (auto i = 0; i < 5; i++) r->composition.SetPerezY (i, ((perezcoefficients_t*)v)->p[i]); }, [&] (void *v, void *) { for (auto i = 0; i < 5; i++) ((perezcoefficients_t*)v)->p[i] = r->composition.GetPerezY (i); }, NULL, "label='Coefficients Y'"); TwAddVarCB (bar, "x", perezType, [&] (const void *v, void*) { for (auto i = 0; i < 5; i++) r->composition.SetPerezx (i, ((perezcoefficients_t*)v)->p[i]); }, [&] (void *v, void *) { for (auto i = 0; i < 5; i++) ((perezcoefficients_t*)v)->p[i] = r->composition.GetPerezx (i); }, NULL, "label='Coefficients x'"); TwAddVarCB (bar, "y", perezType, [&] (const void *v, void*) { for (auto i = 0; i < 5; i++) r->composition.SetPerezy (i, ((perezcoefficients_t*)v)->p[i]); }, [&] (void *v, void *) { for (auto i = 0; i < 5; i++) ((perezcoefficients_t*)v)->p[i] = r->composition.GetPerezy (i); }, NULL, "label='Coefficients y'"); } { TwBar *bar = TwNewBar ("tonemapping"); TwDefine ("tonemapping label='Tonemapping' iconified=true"); TwEnumVal tonemappingmodeEV[] = { { 0, "Default" }, { 1, "Reinhard" }, { 2, "Logarithmic" }, { 3, "URQ" }, { 4, "Exponential" }, { 5, "Drago" }, }; TwType tonemappingmodeType; tonemappingmodeType = TwDefineEnum ("tonemappingmode", tonemappingmodeEV, 6); TwAddVarCB (bar, "Mode", tonemappingmodeType, [&] (const void *v, void*) { r->postprocess.SetTonemappingMode (*(const unsigned int*)v); }, [&] (void *v, void*) { *(unsigned int*)v = r->postprocess.GetTonemappingMode (); }, NULL, NULL); TwAddVarCB (bar, "Image Key", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->postprocess.SetImageKey (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->postprocess.GetImageKey (); }, NULL, "step=0.001 min=0.001 max=5.0"); TwAddVarCB (bar, "White threshold", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->postprocess.SetWhiteThreshold (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->postprocess.GetWhiteThreshold (); }, NULL, "step=0.01 min=0.0 max=5.0"); TwAddVarCB (bar, "Sigma", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->postprocess.SetTonemappingSigma (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->postprocess.GetTonemappingSigma (); }, NULL, "step=0.01 min=0.0 max=5.0"); TwAddVarCB (bar, "Exponent", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->postprocess.SetTonemappingExponent (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->postprocess.GetTonemappingExponent (); }, NULL, "step=0.01 min=0.0"); TwStructMember avglumDesc[] = { { "constant", TW_TYPE_FLOAT, offsetof (glm::vec4, x), "step=0.01" }, { "linear", TW_TYPE_FLOAT, offsetof (glm::vec4, y), "step=0.01" }, { "delta", TW_TYPE_FLOAT, offsetof (glm::vec4, z), "step=0.01" }, { "lod", TW_TYPE_FLOAT, offsetof (glm::vec4, w), "step=0.1" } }; TwType avglumType = TwDefineStruct ("avglum", avglumDesc, 4, sizeof (glm::vec4), NULL, NULL); TwAddVarCB (bar, "avgLum", avglumType, [&] (const void *v, void*) { r->postprocess.SetAvgLumConst (((const glm::vec4*)v)->x); r->postprocess.SetAvgLumLinear (((const glm::vec4*)v)->y); r->postprocess.SetAvgLumDelta (((const glm::vec4*)v)->z); r->postprocess.SetAvgLumLod (((const glm::vec4*)v)->w); }, [&] (void *v, void*) { ((glm::vec4*)v)->x = r->postprocess.GetAvgLumConst (); ((glm::vec4*)v)->y = r->postprocess.GetAvgLumLinear (); ((glm::vec4*)v)->z = r->postprocess.GetAvgLumDelta (); ((glm::vec4*)v)->w = r->postprocess.GetAvgLumLod (); }, NULL, "label='Average Luminance'"); TwEnumVal rgbworkingspaceEV[] = { { 0, "Adobe RGB (1998)" }, { 1, "AppleRGB" }, { 2, "Best RGB" }, { 3, "Beta RGB" }, { 4, "Bruce RGB" }, { 5, "CIE RGB" }, { 6, "ColorMatch RGB" }, { 7, "Don RGB 4" }, { 8, "ECI RGB" }, { 9, "Ekta Space PS5" }, { 10, "NTSC RGB" }, { 11, "PAL/SECAM RGB" }, { 12, "ProPhoto RGB" }, { 13, "SMPTE-C RGB" }, { 14, "sRGB" }, { 15, "Wide Gamut RGB" } }; TwType rgbworkingspaceType; rgbworkingspaceType = TwDefineEnum ("rgbworkingspace", rgbworkingspaceEV, 16); TwAddVarCB (bar, "RGB Working Space", rgbworkingspaceType, [&] (const void *v, void*) { r->postprocess.SetRGBWorkingSpace (*(const unsigned int*)v); }, [&] (void *v, void*) { *(unsigned int*)v = r->postprocess.GetRGBWorkingSpace (); }, NULL, NULL); } { TwBar *bar = TwNewBar ("antialiasing"); TwDefine ("antialiasing label='Antialiasing' iconified=true"); TwEnumVal samplesEV[] = { { 0, "disabled" }, { 4, "4x" }, { 8, "8x" }, { 12, "12x" }, { 16, "16x" }, }; TwType samplesType; samplesType = TwDefineEnum ("samples", samplesEV, 5); TwAddVarCB (bar, "Mode", samplesType, [&] (const void *v, void*) { r->SetAntialiasing (*(const unsigned int*)v); }, [&] (void *v, void*) { *(unsigned int*)v = r->GetAntialiasing (); }, NULL, NULL); TwAddVarCB (bar, "Threshold", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->postprocess.SetAntialiasingThreshold (0.01f * *(const float*)v); }, [&] (void *v, void*) { *(float*)v = 100.0f * r->postprocess.GetAntialiasingThreshold (); }, NULL, "step=0.1 min=0.0"); } { TwBar *bar = TwNewBar ("glow"); TwDefine ("glow label='Glow' iconified=true"); TwAddVarCB (bar, "blur size", TW_TYPE_UINT32, [&] (const void *v, void*) { r->composition.GetGlow ().SetSize (*(const unsigned int*)v); }, [&] (void *v, void*) { *(unsigned int*)v = r->composition.GetGlow ().GetSize (); }, NULL, "min=0 max=256"); TwAddVarCB (bar, "luminance threshold", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.SetLuminanceThreshold (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetLuminanceThreshold (); }, NULL, "step=0.01 min=0"); // TODO: NOT YET REIMPLEMENTED! TwAddVarCB (bar, "limit", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.GetGlow ().SetLimit (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetGlow ().GetLimit (); }, NULL, "step=0.01 min=0 visible=false"); TwAddVarCB (bar, "exponent", TW_TYPE_FLOAT, [&] (const void *v, void*) { r->composition.GetGlow ().SetExponent (*(const float*)v); }, [&] (void *v, void*) { *(float*)v = r->composition.GetGlow ().GetExponent (); }, NULL, "step=0.01 min=0 visible=false"); } { TwBar *bar = TwNewBar ("parameter"); TwDefine ("parameter label='Material Parameters' iconified=true"); { std::vector<TwEnumVal> paramNames; for (auto i = 0; i < r->GetNumParameters (); i++) { paramNames.push_back (TwEnumVal ()); paramNames.back ().Value = i; paramNames.back ().Label = r->GetParameterName (i).c_str (); } TwType paramnameType; paramnameType = TwDefineEnum ("paramname", ¶mNames[0], paramNames.size ()); TwAddVarRW (bar, "active", paramnameType, &active_light, "label='active parameter set'"); } TwAddSeparator (bar, NULL, NULL); TwEnumVal specmodelEV[] = { { 0, "None" }, { 1, "Gaussian" }, { 2, "Phong" }, { 3, "Beckmann" } }; TwType specmodelType; specmodelType = TwDefineEnum ("specmodel", specmodelEV, 4); typedef struct matspec { unsigned int model; float param1; float param2; float fresnel_n; float fresnel_k; } matspec_t; TwStructMember matspecDesc[] = { { "Specular Model", specmodelType, offsetof (matspec_t, model), NULL}, { "Smoothness/Shininess", TW_TYPE_FLOAT, offsetof (matspec_t, param1), "step=0.01" }, { "Gauss Factor/Ignored", TW_TYPE_FLOAT, offsetof (matspec_t, param2), "step=0.01" }, { "Fresnel n", TW_TYPE_FLOAT, offsetof (matspec_t, fresnel_n), "step=0.01" }, { "Fresnel k", TW_TYPE_FLOAT, offsetof (matspec_t, fresnel_k), "step=0.01" } }; TwType matspecType = TwDefineStruct ("matspectype", matspecDesc, 5, sizeof (matspec_t), NULL, NULL); TwAddVarCB (bar, "matspec", matspecType, [&] (const void *v, void*) { Parameter &p = r->GetParameters (active_parameter); const matspec_t *m = (const matspec_t*) v; p.specular.model = m->model; p.specular.param1 = m->param1; p.specular.param2 = m->param2; p.specular.fresnel.n = m->fresnel_n; p.specular.fresnel.k = m->fresnel_k; r->UpdateParameters (active_parameter); }, [&] (void *v, void*) { Parameter &p = r->GetParameters (active_parameter); matspec_t *m = (matspec_t*) v; m->model = p.specular.model; m->param1 = p.specular.param1; m->param2 = p.specular.param2; m->fresnel_n = p.specular.fresnel.n; m->fresnel_k = p.specular.fresnel.k; }, NULL, "label='Specular Parameters'"); typedef struct matrefl { float factor; float fresnel_n; float fresnel_k; } matrefl_t; TwStructMember matreflDesc[] = { { "Factor", TW_TYPE_FLOAT, offsetof (matrefl_t, factor), "step=0.01 min=0.0 max=1.0" }, { "Fresnel n", TW_TYPE_FLOAT, offsetof (matrefl_t, fresnel_n), "step=0.01" }, { "Fresnel k", TW_TYPE_FLOAT, offsetof (matrefl_t, fresnel_k), "step=0.01" } }; TwType matreflType = TwDefineStruct ("matrefltype", matreflDesc, 3, sizeof (matrefl_t), NULL, NULL); TwAddVarCB (bar, "matrefl", matreflType, [&] (const void *v, void*) { Parameter &p = r->GetParameters (active_parameter); const matrefl_t *m = (const matrefl_t*) v; p.reflection.factor = m->factor; p.reflection.fresnel.n = m->fresnel_n; p.reflection.fresnel.k = m->fresnel_k; r->UpdateParameters (active_parameter); }, [&] (void *v, void*) { Parameter &p = r->GetParameters (active_parameter); matrefl_t *m = (matrefl_t*) v; m->factor = p.reflection.factor; m->fresnel_n = p.reflection.fresnel.n; m->fresnel_k = p.reflection.fresnel.k; }, NULL, "label='Reflection'"); } }
bool Application::OnCreate() { Utilities::ConsoleShow(true); //System m_pWindow = Window::Create("Labyrinth Test App",1280,720,true,true); m_pRenderer = lcRenderer::Create(m_pWindow); m_pKeyboard = lcKeyboard::Create(); m_pMouse = lcMouse::Create(); lcTime::Create(); m_pWindow->EnableFileDrop(true); m_pWindow->OnDropFile = &HandleShaderFiles; //m_pMouse->LockToWindow(true); g_pkDevTweakBar = TwNewBar("DevBar"); //Camera lcFrustrum oFustrum; oFustrum.m_fFieldOfView = ((float)LM_PI_HALF * 0.5f); oFustrum.m_fScreenAspect = ((float)Window::Width() / (float)Window::Height()); oFustrum.m_fNear = 0.01f; oFustrum.m_fFar = 1000000.0f; m_pCamera = lcCamera::Create(oFustrum); m_pCamera->SetTranslate(D3DXVECTOR3(0,0,-10)); m_pCamera->LookAt(D3DXVECTOR3(0,0,0)); m_pCamera->Update(); m_pScene = new lcNode(); pkShader = ShaderProperty::Create("./data/shaders/diff.hlsl"); g_pkBox = dynamic_cast<lcMesh*>(CreateCube(lmVec3(0,0,0),lmVec3(1,1,1))); g_pkBox->AttachProperty(pkShader); m_pScene->AttachChild(g_pkBox); TwStructMember positionDef[] = { {"X",TW_TYPE_FLOAT,0,"step=0.01"}, {"Y",TW_TYPE_FLOAT,4,"step=0.01"}, {"Z",TW_TYPE_FLOAT,8,"step=0.01"} }; TwType positionType = TwDefineStruct("PositionType",positionDef,3,sizeof(D3DXVECTOR3),nullptr,nullptr); //Movement Bar //TwAddVarRW(g_pkDevTweakBar,"Wireframe",TW_TYPE_BOOL8,&g_bWireframe,nullptr); //TwAddSeparator(g_pkDevTweakBar,"Space0",nullptr); TwAddVarRW(g_pkDevTweakBar,"Root Translate",positionType,&g_kRootPosition,nullptr); TwAddVarRW(g_pkDevTweakBar,"Root Rotate",TW_TYPE_QUAT4F,&g_kRootRotation,nullptr); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //CREATE TEXTURE PROPERTY SO THAT TEXTURES CHANGE PER OBJECT USING THE SAME SHADER HURR DURR //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! lcTexture2D* pkCrateTexture = new lcTexture2D("./data/textures/crate.jpg"); lcTexture2D* pkDevTexture = new lcTexture2D("./data/textures/dev01.png"); lcTextureProperty* pkTextures = new lcTextureProperty(); pkTextures->SetDiffuse(pkCrateTexture); pkTextures->SetNormal(pkDevTexture); g_pkBox->AttachProperty(pkTextures); D3D11_SAMPLER_DESC sampDesc; ZeroMemory( &sampDesc, sizeof(sampDesc) ); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; lcRenderer::GetDevice()->CreateSamplerState(&sampDesc,&CubeSampleState); lmMatrix4 kYRot; lmMatrix4 kXRot; kYRot.MakeYRotate(LM_PI_HALF / 2.0f); kXRot.MakeXRotate(LM_PI_HALF / 2.0f); lmMatrix4 kOutMat; lmMatrix4Mul(kOutMat,kXRot,kYRot); g_pkBox->SetRotate(kOutMat.m_v); return true; }
// Main int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) { // Register our window class WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW, MessageProc, 0L, 0L, instance, NULL, NULL, NULL, NULL, L"TwDX10", NULL }; RegisterClassEx(&wcex); // Create a window RECT rc = { 0, 0, 640, 480 }; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE); HWND wnd = CreateWindow(L"TwDX10", L"AntTweakBar simple example using DirectX10", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, instance, NULL); if( !wnd ) { MessageBox(NULL, L"Cannot create window", L"Error", MB_OK|MB_ICONERROR); return 0; } // Initialize D3D10 if( FAILED(InitDevice(wnd)) ) { Cleanup(); MessageBox(wnd, L"Cannot create D3D10 device", L"Error", MB_OK|MB_ICONERROR); return 0; } // Initialize the 3D scene if( FAILED(InitScene()) ) { Cleanup(); MessageBox(wnd, L"Scene initialization failed.", L"Error", MB_OK|MB_ICONERROR); return 0; } // Initialize AntTweakBar if( !TwInit(TW_DIRECT3D10, g_D3DDevice) ) { Cleanup(); MessageBoxA(wnd, TwGetLastError(), "AntTweakBar initialization failed", MB_OK|MB_ICONERROR); return 0; } // Create a tweak bar TwBar *bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar in a DirectX10 application.' "); // Message added to the help bar. // Add rotation and scale vars to bar TwAddVarRW(bar, "Rotation", TW_TYPE_INT32, &g_Angle, " KeyIncr=r KeyDecr=R Help='Rotates the triangle (angle in degree).' "); TwAddVarRW(bar, "Scale", TW_TYPE_FLOAT, &g_Scale, " Min=-2 Max=2 Step=0.01 KeyIncr=s KeyDecr=S Help='Scales the triangle (1=original size).' "); // Create a new TwType to edit 2D points: a struct that contains two floats TwStructMember pointMembers[] = { { "X", TW_TYPE_FLOAT, offsetof(Point, X), " Min=-1 Max=1 Step=0.01 " }, { "Y", TW_TYPE_FLOAT, offsetof(Point, Y), " Min=-1 Max=1 Step=0.01 " } }; TwType pointType = TwDefineStruct("POINT", pointMembers, 2, sizeof(Point), NULL, NULL); // Add color and position of the 3 vertices of the triangle TwAddVarRW(bar, "Color0", TW_TYPE_COLOR4F, &g_Colors[0], " Alpha HLS Group='Vertex 0' Label=Color "); TwAddVarRW(bar, "Pos0", pointType, &g_Positions[0], " Group='Vertex 0' Label='Position' "); TwAddVarRW(bar, "Color1", TW_TYPE_COLOR4F, &g_Colors[1], " Alpha HLS Group='Vertex 1' Label=Color "); TwAddVarRW(bar, "Pos1", pointType, &g_Positions[1], " Group='Vertex 1' Label='Position' "); TwAddVarRW(bar, "Color2", TW_TYPE_COLOR4F, &g_Colors[2], " Alpha HLS Group='Vertex 2' Label=Color "); TwAddVarRW(bar, "Pos2", pointType, &g_Positions[2], " Group='Vertex 2' Label='Position' "); // Show and update the window ShowWindow(wnd, cmdShow); UpdateWindow(wnd); // Main message loop. // Passive loop: Content is repaint only when needed. MSG msg = {0}; while( GetMessage(&msg, NULL, 0, 0) > 0 ) { TranslateMessage(&msg); DispatchMessage(&msg); } TwTerminate(); Cleanup(); return (int)msg.wParam; }