void DisplayWindow(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // simultaneous clears are faster glColor3f(1.0, 1.0, 1.0); // draw in white glLoadIdentity(); //if (mouse_mode == GLUT_RIGHT_BUTTON && mouse_state == GLUT_DOWN) //{ // gluLookAt(camera_target_x, camera_target_y, depth, // set camera back 'depth' units along the z-axis // camera_target_x, camera_target_y, 0, // point camera at coordinates (camera_x, camera_y) // 0.0, 1.0, 0.0); // set positive on the y-axis as the up-vector // camera_position_x = camera_target_x; // camera_position_y = camera_target_y; //} //else /* gluLookAt(camera_position_x, camera_position_y, depth, // set camera back 'depth' units along the z-axis camera_target_x, camera_target_y, 0, // point camera at coordinates (camera_x, camera_y) 0.0, 1.0, 0.0); // set positive on the y-axis as the up-vector */ gluLookAt(camera_controller->mPos.x, camera_controller->mPos.y, camera_controller->mPos.z, camera_controller->mView.x, camera_controller->mView.y, camera_controller->mView.z, camera_controller->mUp.x, camera_controller->mUp.y, camera_controller->mUp.z); /* glRotatef(camera_target_x / 4, 0, 1, 0);////////////////////////////////////// glRotatef(camera_target_y / -4, 1, 0, 0);//////////////////////////////////// gluLookAt(0, 0, 1, // set camera back 'depth' units along the z-axis 0, 0, 0, // point camera at coordinates (camera_x, camera_y) 0.0, 1.0, 0.0); // set positive on the y-axis as the up-vector */ glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glRotatef(angle, 0, 1, 0); // allow rotate by 'angle' degrees with PAGE_UP and PAGE_DOWN //Draw_Skybox(0, 0, 0, 10000, 10000, 10000); // Draw the Skybox glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glPushMatrix(); Soundwave.Draw(); // draw Soundwave glTranslatef(52.5, 50, 16); glDisable(GL_LIGHTING); particleSystem->DrawParticles(); // draw sparks glEnable(GL_LIGHTING); glPopMatrix(); glPushMatrix(); glTranslatef(0, -217.5, 0); Cybertron.Draw(); // draw Cybertron Lab glPopMatrix(); glutSwapBuffers(); // glutSwapBuffers() used for double buffers } // DisplayWindow
void display( void ) { // clear the frame buffer glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); scene.Draw(program); camera.Update(program); // swap the framebuffers glutSwapBuffers(); }
// プログラムは WinMain から始まります int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ChangeWindowMode(TRUE); // ウィンドウモードに設定 SetMainWindowText("東方崩固玉"); //タイトルの指定。何にしよう SetDrawScreen(DX_SCREEN_BACK); //SetBackgroundColor(0, 0, 0); //背景の色変更5 if (DxLib_Init() == -1) // DXライブラリ初期化処理 { return -1; // エラーが起きたら直ちに終了 } Scene scene; //現在の場面 Key_Input* m_key; //キー入力用 m_key = Key_Input::GetInstance(); //int reaction_return; //Reaction()の返り値を受け取る Flag flag; //Events *events = Events::GetInstance(); //Colors colors; //コンストラクタ FPSer fpser; Common_TH common_th; //初期化する while (1) //メインループ { ClearDrawScreen(); //画面をクリア。描画処理はこれより後に書く m_key->KeyUpdate(); //key_input.KeyUpdate(); //キー入力 //reaction_return = nowpointa->Reaction(); //キー入力などによる情報の更新 scene.Reaction(); //キー入力などによる情報の更新 scene.Draw(); //現在の場面の描画 fpser.CountFPS(); //デバッグ的な ScreenFlip(); //裏と表の仲介役。描画処理よりも後に書く if (ProcessMessage()) //×クリック待ち { break; } if (CheckHitKey(KEY_INPUT_ESCAPE) == 1) //Esc入力待ち { break; } } DxLib_End(); // DXライブラリ使用の終了処理 return 0; // ソフトの終了 }
int main(void) { //Initialize platform subsystem and EGL Platform* platform = Platform::getInstance(); platform->createWindow(WINDOW_WIDTH, WINDOW_HEIGHT); EGLRuntime::initializeEGL(EGLRuntime::OPENGLES2); eglMakeCurrent(EGLRuntime::display, EGLRuntime::surface, EGLRuntime::surface, EGLRuntime::context); Scene *scene = new Scene(WINDOW_WIDTH, WINDOW_HEIGHT); scene->Initialize(); //Timer variable to calculate FPS Timer fpsTimer; fpsTimer.reset(); DWORD wait = 0; bool end = false; while (!end) { //End when something happens to the window if (platform->checkWindow() != Platform::WINDOW_IDLE) end = true; //This prints FPS every second float fFPS = fpsTimer.getFPS(); if (fpsTimer.isTimePassed(1.0f)){ LOGI("FPS:\t%.1f\n", fFPS); } scene->Draw(); eglSwapBuffers(EGLRuntime::display, EGLRuntime::surface); //Calculate how much we have to wait to achieve 30FPS, //getInterval() tells us how much time have passed //since the last call (seems to be in centi-seconds) float interval = fpsTimer.getInterval() * 100; wait = (DWORD)(1000 / (interval * 30)); Sleep(wait); } //Shutdown everything EGLRuntime::terminateEGL(); platform->destroyWindow(); delete platform; delete scene; return 0; }
void Engine::Draw(UpdateArgs& args) { Scene* curScene = scene; if (isLoading) { curScene = loadingScene; } UInt32 i = 0; UInt32 c = TIKI_MAX(1, curScene->GetCameras()->Count()); while (i < c) { DrawArgs drawArgs = DrawArgs( args.Time, DM_Geometry, (i < curScene->GetCameras()->Count() ? curScene->GetCameras()->Get(i) : 0), graphics, sprites, args, curScene->GetLighting() ); graphics->Begin(drawArgs); sprites->Begin(); UInt32 bi = 0; UInt32 bc = 1 + (useShadows ? 1 : 0); while (bi < bc) { if (bi != 0) { drawArgs.Mode = (DrawMode)bi; graphics->GetUnusedScreenTarget()->ApplyFirstAndOnly(); } curScene->Draw(drawArgs); bi++; } sprites->End(); graphics->End(); i++; } }
// Main function int main() { // Initialize GLFW if( !glfwInit() ) { // A fatal error occurred std::cerr << "GLFW initialization failed" << std::endl; return 1; } // Create a window GLFWvidmode mode; glfwGetDesktopMode(&mode); if( !glfwOpenWindow(800, 600, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) ) { // A fatal error occurred std::cerr << "Cannot open GLFW window" << std::endl; glfwTerminate(); return 1; } glfwSwapInterval(0); glfwEnable(GLFW_MOUSE_CURSOR); glfwEnable(GLFW_KEY_REPEAT); const char title[] = "AntTweakBar example: TwAdvanced1"; glfwSetWindowTitle(title); // Set GLFW event callbacks glfwSetWindowSizeCallback(OnWindowSize); glfwSetMouseButtonCallback(OnMouseButton); glfwSetMousePosCallback(OnMousePos); glfwSetMouseWheelCallback(OnMouseWheel); glfwSetKeyCallback(OnKey); glfwSetCharCallback(OnChar); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Change the font size, and add a global message to the Help bar. TwDefine(" GLOBAL fontSize=3 help='This example illustrates the definition of custom structure type as well as many other features.' "); // Initialize the 3D scene Scene scene; scene.Init(true); // Create a tweak bar called 'Main' and change its refresh rate, position, size and transparency TwBar *mainBar = TwNewBar("Main"); TwDefine(" Main label='Main TweakBar' refresh=0.5 position='16 16' size='260 320' alpha=0"); // Add some variables to the Main tweak bar TwAddVarRW(mainBar, "Wireframe", TW_TYPE_BOOLCPP, &scene.Wireframe, " group='Display' key=w help='Toggle wireframe display mode.' "); // 'Wireframe' is put in the group 'Display' (which is then created) TwAddVarRW(mainBar, "BgTop", TW_TYPE_COLOR3F, &scene.BgColor1, " group='Background' help='Change the top background color.' "); // 'BgTop' and 'BgBottom' are put in the group 'Background' (which is then created) TwAddVarRW(mainBar, "BgBottom", TW_TYPE_COLOR3F, &scene.BgColor0, " group='Background' help='Change the bottom background color.' "); TwDefine(" Main/Background group='Display' "); // The group 'Background' of bar 'Main' is put in the group 'Display' TwAddVarCB(mainBar, "Subdiv", TW_TYPE_INT32, SetSubdivCB, GetSubdivCB, &scene, " group='Scene' label='Meshes subdivision' min=1 max=50 keyincr=s keyDecr=S help='Subdivide the meshes more or less (switch to wireframe to see the effect).' "); TwAddVarRW(mainBar, "Ambient", TW_TYPE_FLOAT, &scene.Ambient, " label='Ambient factor' group='Scene' min=0 max=1 step=0.001 keyIncr=a keyDecr=A help='Change scene ambient.' "); TwAddVarRW(mainBar, "Reflection", TW_TYPE_FLOAT, &scene.Reflection, " label='Reflection factor' group='Scene' min=0 max=1 step=0.001 keyIncr=r keyDecr=R help='Change ground reflection.' "); // Create a new TwType called rotationType associated with the Scene::RotMode enum, and use it TwEnumVal rotationEV[] = { { Scene::ROT_OFF, "Stopped"}, { Scene::ROT_CW, "Clockwise" }, { Scene::ROT_CCW, "Counter-clockwise" } }; TwType rotationType = TwDefineEnum( "Rotation Mode", rotationEV, 3 ); TwAddVarRW(mainBar, "Rotation", rotationType, &scene.Rotation, " group='Scene' keyIncr=Backspace keyDecr=SHIFT+Backspace help='Stop or change the rotation mode.' "); // Add a read-only float variable; its precision is 0 which means that the fractionnal part of the float value will not be displayed TwAddVarRO(mainBar, "RotYAngle", TW_TYPE_DOUBLE, &scene.RotYAngle, " group='Scene' label='Rot angle (degree)' precision=0 help='Animated rotation angle' "); // Initialize time double time = glfwGetTime(), dt = 0; // Current time and elapsed time double frameDTime = 0, frameCount = 0, fps = 0; // Framerate // Main loop (repeated while window is not closed) while( glfwGetWindowParam(GLFW_OPENED) ) { // Get elapsed time dt = glfwGetTime() - time; if (dt < 0) dt = 0; time += dt; // Rotate scene if( scene.Rotation==Scene::ROT_CW ) scene.RotYAngle -= 5.0*dt; else if( scene.Rotation==Scene::ROT_CCW ) scene.RotYAngle += 5.0*dt; // Move lights scene.Update(time); // Draw scene scene.Draw(); // Draw tweak bars TwDraw(); // Present frame buffer glfwSwapBuffers(); // Estimate framerate frameCount++; frameDTime += dt; if( frameDTime>1.0 ) { fps = frameCount/frameDTime; char newTitle[128]; _snprintf(newTitle, sizeof(newTitle), "%s (%.1f fps)", title, fps); //glfwSetWindowTitle(newTitle); // uncomment to display framerate frameCount = frameDTime = 0; } } // Terminate AntTweakBar and GLFW TwTerminate(); glfwTerminate(); return 0; }
int main(int argc, char *argv[]) { //Setup SDL video if (SDL_Init(SDL_INIT_VIDEO) < 0) { cerr << "SDL Initialization failed!" << endl; return -1; } //Setup SDL attributes and versions SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); //Attach renderer and context to window SDL_Window *window = SDL_CreateWindow("Object Loader", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 840, 840, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); SDL_Renderer * renderer = SDL_CreateRenderer( window, -1, 0 ); SDL_GLContext glcontext = SDL_GL_CreateContext( window ); //Setup glew glewExperimental = GL_TRUE; GLenum err = glewInit(); if( GLEW_OK != err ) { cerr<<"Glew Initializatoin failed!" << endl << glewGetErrorString(err) << endl; return -1; } //Enable OpenGL options glEnable(GL_TEXTURE_2D); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); //Log OpenGL information cout << "GLEW Version: " << glewGetString(GLEW_VERSION)<< endl; cout << "OpenGL Version: " << glGetString( GL_VERSION ) << endl; cout << "OpenGL Vendor: " << glGetString( GL_VENDOR ) << endl; cout << "OpenGL Renderer: " << glGetString( GL_RENDERER ) << endl; cout << "OpenGL Shading Language Version: " << glGetString( GL_SHADING_LANGUAGE_VERSION ) << endl; //Create vertex and fragment shaders Shader *shader = new Shader(); shader->SetFragmentShader("shaders/Fragment_Mapping.glsl"); shader->SetVertexShader("shaders/Vertex_Mapping.glsl"); shader->CompileData(); //Create scene and assign shader/model Scene *scene = new Scene(); scene->SetShader(shader); scene->Setup(); //Execute the game loop bool isPlaying = true; int lastTick = SDL_GetTicks(); while(isPlaying) { //Calculate delta time unsigned int currentTick = SDL_GetTicks(); float deltaTime = (float) (currentTick - lastTick) / 1000.0f; lastTick = currentTick; //Clear the frame buffer to black glClearColor(0.0f,0.0f,0.0f,0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Update and draw the current scene to window //Check whether update method returned false in which case end the game isPlaying = scene->Update(deltaTime); scene->Draw(); SDL_GL_SwapWindow(window); //Limit the fps if its running too high if(deltaTime < (1.0f/50.0f)) { SDL_Delay((unsigned int) (((1.0f/50.0f) - deltaTime)*1000.0f) ); } } //Cleanup and quit SDL SDL_GL_DeleteContext( glcontext ); SDL_DestroyWindow( window ); SDL_Quit(); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { //------------------Initate OpenGL --------------- //init glfw if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); return -1; } //Iniate OpenGL using glfw GLFWwindow* window; window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Lab2: Heirachy animation", NULL, NULL); if (window == NULL){ fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n"); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Initialize GLEW glewExperimental = true; // Needed in core profile //Initate glew if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } //--end of opengl Initation ------------------- //---initate scene-------------------------- //function to modify scene Initiate(); //--end of scene initation------------ //---OpenGL main Loop------------- // get start time for animation double start_time = glfwGetTime(); //main loop do{ //main double cur_time = glfwGetTime(); double elapse_time = cur_time - start_time; //update main scene --if animation is used Main_Scene.Update(elapse_time); //draw main scene Main_Scene.Draw(); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); //----end of main loop------------------ return 0; }