void myPreSyncFun() { if( gEngine->isMaster() ) { curr_time.setVal( sgct::Engine::getTime() ); if( arrowButtons[FORWARD] ) dist.setVal( dist.getVal() + (navigation_speed * gEngine->getDt())); if( arrowButtons[BACKWARD] ) dist.setVal( dist.getVal() - (navigation_speed * gEngine->getDt())); } }
void myDrawFun() { glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); double speed = 25.0; //create scene transform (animation) glm::mat4 scene_mat = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -3.0f)); scene_mat = glm::rotate(scene_mat, static_cast<float>(curr_time.getVal() * speed), glm::vec3(0.0f, -1.0f, 0.0f)); scene_mat = glm::rotate(scene_mat, static_cast<float>(curr_time.getVal() * (speed / 2.0)), glm::vec3(1.0f, 0.0f, 0.0f)); glm::mat4 MVP = gEngine->getActiveModelViewProjectionMatrix() * scene_mat; glm::mat4 MV = gEngine->getActiveModelViewMatrix() * scene_mat; glm::mat3 NormalMatrix = glm::inverseTranspose(glm::mat3(MV)); glActiveTexture(GL_TEXTURE0); //glBindTexture( GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureByName("box") ); glBindTexture(GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureByHandle(myTextureHandle)); sgct::ShaderManager::instance()->bindShaderProgram("MRT"); glUniformMatrix4fv(m_MVPMatrixID, 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv(m_worldMatrixTransposeID, 1, GL_TRUE, &MV[0][0]); //transpose in transfere glUniformMatrix3fv(m_normalMatrix, 1, GL_FALSE, &NormalMatrix[0][0]); glUniform1i(m_textureID, 0); //draw the box myBox->draw(); sgct::ShaderManager::instance()->unBindShaderProgram(); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); }
void myDrawFun() { glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); double speed = 0.44; //create scene transform (animation) glm::mat4 scene_mat = glm::translate( glm::mat4(1.0f), glm::vec3( 0.0f, 0.0f, -3.0f) ); scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * speed ), glm::vec3(0.0f, -1.0f, 0.0f)); scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * (speed/2.0) ), glm::vec3(1.0f, 0.0f, 0.0f)); glm::mat4 MVP = gEngine->getCurrentModelViewProjectionMatrix() * scene_mat; glActiveTexture(GL_TEXTURE0); if(texIndex.getVal() != -1) glBindTexture(GL_TEXTURE_2D, texIds.getValAt(texIndex.getVal())); else glBindTexture(GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureId("box")); sgct::ShaderManager::instance()->bindShaderProgram( "xform" ); glUniformMatrix4fv(Matrix_Loc, 1, GL_FALSE, &MVP[0][0]); //draw the box myBox->draw(); sgct::ShaderManager::instance()->unBindShaderProgram(); glDisable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); }
void myPreSyncFun() { if( gEngine->isMaster() && !mPause) { curr_time.setVal( curr_time.getVal() + gEngine->getAvgDt()); } }
void myDrawFun() { glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); gEngine->setClearColor(clear_color.x, clear_color.y, clear_color.z, 1.0f); //create scene transform (animation) glm::mat4 scene_mat = glm::translate( glm::mat4(1.0f), glm::vec3( 0.0f, 0.0f, -3.0f) ); scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * speed ), glm::vec3(0.0f, -1.0f, 0.0f)); scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * (speed/2.0) ), glm::vec3(1.0f, 0.0f, 0.0f)); glm::mat4 MVP = gEngine->getCurrentModelViewProjectionMatrix() * scene_mat; glActiveTexture(GL_TEXTURE0); glBindTexture( GL_TEXTURE_2D, (use_texture ? sgct::TextureManager::instance()->getTextureId("box") : NULL)); sgct::ShaderManager::instance()->bindShaderProgram( "xform" ); glUniformMatrix4fv(Matrix_Loc, 1, GL_FALSE, &MVP[0][0]); //draw the box myBox->draw(); sgct::ShaderManager::instance()->unBindShaderProgram(); glDisable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); if( gEngine->isMaster() ) { ImGui_ImplGlfwGL3_NewFrame(gEngine->getCurrentWindowPtr()->getXFramebufferResolution(), gEngine->getCurrentWindowPtr()->getYFramebufferResolution()); // Show a settings window custom made for this application // Toggle this windows with the 'W' key. if(show_settings_window) { ImGui::SetNextWindowSize(ImVec2(300, 200), ImGuiSetCond_FirstUseEver); ImGui::Begin("Settings"); ImGui::SliderFloat("Rotation Speed", &(speed), 0.0f, 1.0f); ImGui::Checkbox("Texture On/Off", &use_texture); ImGui::ColorEdit3("Clear Color", (float*)&clear_color); if (ImGui::Button("Toggle Test Window")) show_test_window ^= 1; ImGui::End(); } // Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { ImGui::SetNextWindowPos(ImVec2(100, 20), ImGuiSetCond_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } ImGui::Render(); } }
void myDrawFun() { float speed = 50.0f; glm::mat4 scene_mat = glm::rotate( glm::mat4(1.0f), static_cast<float>( curr_time.getVal() ) * speed, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 MVP = gEngine->getActiveModelViewProjectionMatrix() * scene_mat; sgct::ShaderManager::instance()->bindShaderProgram( "xform" ); glUniformMatrix4fv(matrix_loc, 1, GL_FALSE, &MVP[0][0]); glUniform1f( time_loc, static_cast<float>( curr_time.getVal() ) ); glBindVertexArray(vertexArray); // Draw the triangle ! glDrawArrays(GL_TRIANGLES, 0, 3); //unbind glBindVertexArray(0); sgct::ShaderManager::instance()->unBindShaderProgram(); }
void myDrawFun() { #ifndef Test glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glTranslatef( 0.0f, -0.15f, 2.5f ); glRotatef( static_cast<float>( curr_time.getVal() ) * 8.0f, 0.0f, 1.0f, 0.0f ); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureId("heightmap")); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureId("normalmap")); glEnable(GL_TEXTURE_2D); //set current shader program sgct::ShaderManager::instance()->bindShaderProgram("Heightmap"); glUniform1f( curr_timeLoc, static_cast<float>( curr_time.getVal() ) ); glUniform1i( myTextureLocations[0], 0 ); glUniform1i( myTextureLocations[1], 1 ); //glUniform1f(curr_timeLoc, 0.0f); glLineWidth(2.0); //for wireframe glCallList(myTerrainDisplayList); //unset current shader program sgct::ShaderManager::instance()->unBindShaderProgram(); glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); #else mySphere->draw(); #endif }
void myDrawFun() { glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); glEnable( GL_TEXTURE_2D ); double speed = 0.44; //create scene transform (animation) glm::mat4 scene_mat = glm::translate( glm::mat4(1.0f), glm::vec3( 0.0f, 0.0f, -3.0f) ); scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * speed ), glm::vec3(0.0f, -1.0f, 0.0f)); glMultMatrixf( glm::value_ptr(scene_mat) ); //multiply the modelview matrix with the scene transform // ------ draw model --------------- // glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); //push attributes to the stack in order to unset them correctly glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[ VBO_POSITIONS ] ); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, reinterpret_cast<void*>(0)); if(hasUVs) { glClientActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sgct::TextureManager::instance()->getTextureId("box")); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[ VBO_UVS ] ); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, reinterpret_cast<void*>(0)); } if(hasNormals) { glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[ VBO_NORMALS ] ); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, reinterpret_cast<void*>(0)); } glDrawArrays(GL_TRIANGLES, 0, numberOfVertices); glBindBuffer(GL_ARRAY_BUFFER, GL_FALSE); //unbind glPopClientAttrib(); // ----------------------------------// glDisable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); }
void myPostSyncPreDrawFun() { gEngine->setWireframe(wireframe.getVal()); gEngine->setDisplayInfoVisibility(info.getVal()); gEngine->setStatsGraphVisibility(stats.getVal()); if( takeScreenshot.getVal() ) { gEngine->takeScreenshot(); takeScreenshot.setVal(false); } light.getVal() ? mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE) : mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); mSceneTrans->setMatrix(osg::Matrix::rotate( glm::radians(curr_time.getVal() * 8.0), 0.0, 1.0, 0.0)); mSceneTrans->postMult(osg::Matrix::translate(0.0, -0.1, dist.getVal())); //transform to scene transformation from configuration file mSceneTrans->postMult( osg::Matrix( glm::value_ptr( gEngine->getModelMatrix() ) )); //update the frame stamp in the viewer to sync all //time based events in osg mFrameStamp->setFrameNumber( gEngine->getCurrentFrameNumber() ); mFrameStamp->setReferenceTime( curr_time.getVal() ); mFrameStamp->setSimulationTime( curr_time.getVal() ); mViewer->setFrameStamp( mFrameStamp.get() ); mViewer->advance( curr_time.getVal() ); //update //traverse if there are any tasks to do if (!mViewer->done()) { mViewer->eventTraversal(); //update travelsal needed for pagelod object like terrain data etc. mViewer->updateTraversal(); } }
void myPreSyncFun() { //set the time only on the master if( gEngine->isMaster() ) { //get the time in seconds curr_time.setVal(sgct::Engine::getTime()); } float f = static_cast<float>( curr_time.getVal() ) / 2.0f; audio.setSoundPositionAndVelocity( 0, glm::vec3(-2.0f * sinf( f ), 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f) ); audio.setSoundPositionAndVelocity( 1, glm::vec3(2.0f * sinf( f ), 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f) ); audio.update(); //const float * spectrum = audio.getSoundItemAtIndex(0)->mChannel }