void Renderer::render(const render::Scene& scene, const Camera& camera) { ProfileNodeCall call("forward::Renderer::render"); GL::Context& context = getContext(); context.setCurrentSharedProgramState(state); const Recti& viewportArea = context.getViewportArea(); state->setViewportSize(float(viewportArea.size.x), float(viewportArea.size.y)); state->setProjectionMatrix(camera.getProjectionMatrix()); state->setViewMatrix(camera.getViewTransform()); if (camera.isPerspective()) { state->setCameraProperties(camera.getTransform().position, camera.getFOV(), camera.getAspectRatio(), camera.getNearZ(), camera.getFarZ()); } renderOperations(scene.getOpaqueQueue()); renderOperations(scene.getBlendedQueue()); context.setCurrentSharedProgramState(NULL); releaseObjects(); }
VBoxDDRAWFrameBuffer::VBoxDDRAWFrameBuffer (VBoxConsoleView *aView) : VBoxFrameBuffer (aView), mDDRAW (NULL), mClipper (NULL), mSurface (NULL), mPrimarySurface (NULL), mPixelFormat (FramebufferPixelFormat_FOURCC_RGB), mUsesGuestVRAM (false), mWndX (0), mWndY (0), mSynchronousUpdates (true) { memset (&mSurfaceDesc, 0, sizeof (mSurfaceDesc)); LOGDDRAW (("DDRAW: Creating\n")); /* Release all created objects if something will go wrong. */ BOOL bReleaseObjects = TRUE; mDDRAW = getDDRAW (); if (mDDRAW) { mClipper = createClipper (mDDRAW, mView->viewport()->winId()); if (mClipper) { mPrimarySurface = createPrimarySurface (mDDRAW); if (mPrimarySurface) { mPrimarySurface->SetClipper (mClipper); VBoxResizeEvent *re = new VBoxResizeEvent (FramebufferPixelFormat_Opaque, NULL, 0, 0, 640, 480); if (re) { resizeEvent (re); delete re; if (mSurface) { /* Everything was initialized. */ bReleaseObjects = FALSE; } } } } } if (bReleaseObjects) { releaseObjects(); } }
int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // OpenGL 3.3, Mac OS X is reported to have some problem. However I don't have Mac to test glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // For Mac OS X glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); int width = 1366; int height = 768; window = glfwCreateWindow(width, height, "Simple Example", NULL, NULL); if (!window) { glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); // This line MUST put below glfwMakeContextCurrent glewExperimental = GL_TRUE; glewInit(); // Enable vsync glfwSwapInterval(1); // Setup input callback glfwSetKeyCallback(window, key_callback); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); // load shader program - default is flat loadShader("Shader/flat_vertexShader.vs","Shader/flat_fragmentShader.frag"); // Enable blend mode for billboard //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); float last, start; last = start = glfwGetTime(); int fps=0; //objects[sun].model = glm::scale(glm::mat4(1.0f), glm::vec3(0.85f)); std::cout<<"You can press the Key 1~4 to control the shader mode!"<<std::endl; std::cout<<"1 for flat"<<std::endl; std::cout<<"2 for Gouraud"<<std::endl; std::cout<<"3 for Phong"<<std::endl; std::cout<<"4 for Blinn-Phong"<<std::endl; while (!glfwWindowShouldClose(window)) {//program will keep draw here until you close the window float delta = glfwGetTime() - start; // Require for the rotation of sun render(); glfwSwapBuffers(window); glfwPollEvents(); fps++; glm::vec3 camera = glm::vec3( 30.0f , 30.0f , 30.0f); // set matrix //glm::mat4 proj = glm::perspective(glm::radians(20.0f), 640.0f / 480, 1.0f, 100.f)*glm::lookAt(glm::vec3(25.0f), glm::vec3(), glm::vec3(0, 1, 0)) * glm::mat4(1.0f); glm::mat4 proj = glm::perspective(glm::radians(20.0f), 640.0f / 480, 1.0f, 100.f); glm::mat4 view = glm::mat4(1.0f)*glm::lookAt(camera, glm::vec3(), glm::vec3(0, 1, 0)) * glm::mat4(1.0f); glm::mat4 model = glm::scale(glm::mat4(1.0f), glm::vec3(0.85f))*glm::rotate(glm::mat4(), (GLfloat)glfwGetTime() * 0.1f, glm::vec3(0.0f, 1.0f, 0.0f)); // Light Position glm::vec3 LightPos(5.0f,15.0f,5.0f); setColorAttr(program , LightPos , camera); // Set program setVS(program,proj,view,model); if(glfwGetTime() - last > 1.0) { // Every second // std::cout<<(double)fps/(glfwGetTime()-last)<<std::endl; fps = 0; last = glfwGetTime(); } } releaseObjects(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; }
ObjectsController::ObjectsController( Record::Server& server, ObjectsComponent& component ) : server( server ) , component( component ) , view( new ObjectsView( server ) ) , objectReleasing( new QAction( QIcon( ":/icons/trash.png" ) , "&Release", this ) ) , objectRenaming ( new QAction( QIcon( ":/icons/pencil.png" ), "Rena&me" , this ) ) , editorDetaching( new QAction( QIcon( ":/icons/pin.png" ) , "&Detach", this ) ) , pointCreation ( new QAction( "Create &Point", this ) ) , pointerCreation( new QAction( "Create Pointe&r", this ) ) , polylineImport ( new QAction( "Import Poly&line", this ) ) , tempPointCreation( new QAction( "Create Temporary Seed", this ) ) , editorContainer( new QFrame() ) , currentObjectEditor( nullptr ) { editorContainer->setLayout( new QVBoxLayout() ); editorContainer->setContentsMargins( 0, 0, 0, 0 ); editorContainer->setMinimumWidth( 200 ); editorContainer->hide(); QToolBar* const toolBar = new QToolBar(); toolBar->setIconSize( QSize( 24, 24 ) ); toolBar->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); QToolButton* acquireButton = new QToolButton( toolBar ); QMenu* acquireMenu = new QMenu( acquireButton ); acquireButton->setMenu( acquireMenu ); acquireButton->setPopupMode( QToolButton::InstantPopup ); acquireButton->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); acquireButton->setText( "Cre&ate" ); acquireButton->setIcon( QIcon( ":/icons/add.png" ) ); acquireMenu->addAction( pointCreation ); acquireMenu->addAction( pointerCreation ); acquireMenu->addSeparator(); acquireMenu->addAction( tempPointCreation ); acquireMenu->addSeparator(); acquireMenu->addAction( polylineImport ); toolBar->addWidget( acquireButton ); toolBar->addAction( objectReleasing ); toolBar->addAction( objectRenaming ); toolBar->addSeparator(); toolBar->addAction( editorDetaching ); connect( pointCreation, SIGNAL( triggered() ), this, SLOT( createPoint3D() ) ); connect( polylineImport, SIGNAL( triggered() ), this, SLOT( importPolyline() ) ); connect( tempPointCreation, SIGNAL( triggered() ), this, SLOT( createTempPoint1() ) ); #ifndef NO_CRA connect( pointerCreation, SIGNAL( triggered() ), this, SLOT( createPointer3D() ) ); #endif this->setMinimumWidth( toolBar->sizeHint().width() ); this->setLayout( new QVBoxLayout() ); this->layout()->addWidget( view ); this->layout()->addWidget( toolBar ); this->layout()->addWidget( editorContainer ); connect( objectReleasing, SIGNAL( triggered() ), this, SLOT( releaseObjects() ) ); connect( objectRenaming , SIGNAL( triggered() ), this, SLOT( renameObject() ) ); connect( editorDetaching, SIGNAL( triggered() ), this, SLOT( detachEditor() ) ); editorDetaching->setEnabled( false ); connect( view, SIGNAL( selectionChanged() ), this, SLOT( objectsSelectionChanged() ) ); connect( view, SIGNAL( objectDoubleClicked( Carna::base::model::Object3D& ) ), this, SLOT( renameObject( Carna::base::model::Object3D& ) ) ); objectsSelectionChanged(); }
VBoxDDRAWFrameBuffer::~VBoxDDRAWFrameBuffer() { releaseObjects(); }
int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // OpenGL 3.3, Mac OS X is reported to have some problem. However I don't have Mac to test glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // For Mac OS X glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(1280, 960, "Mesh Smoothing Demo", NULL, NULL); if (!window) { glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); // This line MUST put below glfwMakeContextCurrent glewExperimental = GL_TRUE; glewInit(); // Enable vsync glfwSwapInterval(1); // Setup input callback glfwSetKeyCallback(window, key_callback); glfwSetMouseButtonCallback(window, mouse_callback); setup_gui_texture(); setup_gui_render_obj(); filenames[0] = "smoothing"; filenames[1] = "/ori/"; filenames[2] = "/lap/"; filenames[3] = "/tau/"; // load shader program shaders[0] = setup_shader(readfile("shaders/vs.txt").c_str(), readfile("shaders/fs.txt").c_str()); gui_shader = setup_shader(readfile("shaders/guivs.txt").c_str(), readfile("shaders/guifs.txt").c_str()); shaders[1] = setup_shader(readfile("shaders/nvs.txt").c_str(), readfile("shaders/nfs.txt").c_str()); shaders[2] = setup_shader(readfile("shaders/fvs.txt").c_str(), readfile("shaders/ffs.txt").c_str()); printf("we have:%d, %d, %d\n", shaders[0], shaders[1], shaders[2]); program1 = shaders[0]; show_obj = add_obj("smoothing/ori/bunny.obj"); glm::vec3 light_pos(0.0f, 0.0f, 0.0f); camera_location = glm::vec4(0.0f, 0.0f, 2.0f, 1.0f); up_direction = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glm::vec3 camera_location_xyz = glm::vec3(camera_location.x, camera_location.y, camera_location.z); glm::vec3 up_direction_xyz = glm::vec3(up_direction.x, up_direction.y, up_direction.z); setUniformMat4(shaders[0], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[0], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); setUniformMat4(shaders[1], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[1], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); setUniformMat4(shaders[2], "p", glm::perspective(glm::radians(45.0f), 640.0f/480, 0.1f, 100.f) *glm::mat4(1.0f)); setUniformMat4(shaders[2], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), glm::vec3(0, 1, 0))*glm::mat4(1.0f)); glm::mat4 rot; glm::mat4 rev; float last, start; last = start = glfwGetTime(); float fps = 0; while (!glfwWindowShouldClose(window)) { rotate(); zoom(); camera_location_xyz = glm::vec3(camera_location.x, camera_location.y, camera_location.z); up_direction_xyz = glm::vec3(up_direction.x, up_direction.y, up_direction.z); setUniformMat4(shaders[0], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); setUniformMat4(shaders[1], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); setUniformMat4(shaders[2], "v", glm::lookAt(camera_location_xyz, glm::vec3(0.0f), up_direction_xyz)*glm::mat4(1.0f)); render(); glfwSwapBuffers(window); glfwPollEvents(); fps++; if(glfwGetTime() - last > 1.0) { std::cout<<(double)fps/(glfwGetTime()-last)<<std::endl; fps = 0; last = glfwGetTime(); } } releaseObjects(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); // OpenGL 3.3, Mac OS X is reported to have some problem. However I don't have Mac to test glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //set hint to glfwCreateWindow, (target, hintValue) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //hint--> window not resizable, explicit use core-profile, opengl version 3.3 // For Mac OS X glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(800, 600, "Simple Example", NULL, NULL); if (!window) { glfwTerminate(); return EXIT_FAILURE; } glfwMakeContextCurrent(window); //set current window as main window to focus // This line MUST put below glfwMakeContextCurrent glewExperimental = GL_TRUE; //tell glew to use more modern technique for managing OpenGL functionality glewInit(); // Enable vsync glfwSwapInterval(1); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); // Setup input callback glfwSetKeyCallback(window, key_callback); //set key event handler // load shader program program = setup_shader(readfile("flat_vs.txt").c_str(), readfile("flat_fs.txt").c_str()); program1 = setup_shader(readfile("gourand_vs.txt").c_str(), readfile("gourand_fs.txt").c_str()); program2 = setup_shader(readfile("phong_vs.txt").c_str(), readfile("phong_fs.txt").c_str()); program3 = setup_shader(readfile("blin_vs.txt").c_str(), readfile("blin_fs.txt").c_str()); int sun = add_obj(program, "sun.obj","sun.bmp"); int sun1 = add_obj(program1, "sun.obj", "sun.bmp"); int sun2 = add_obj(program2, "sun.obj", "sun.bmp"); int sun3 = add_obj(program3, "sun.obj", "sun.bmp"); glEnable(GL_DEPTH_TEST); // prevent faces rendering to the front while they're behind other faces. glCullFace(GL_BACK); // discard back-facing trangle // Enable blend mode for billboard //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //-----------------------------------------------------------setting view point----------------------------------// set_vp(program); set_vp(program1); set_vp(program2); set_vp(program3); //-----------------------------------------------------------end of setting--------------------------------------// //------------------------------------------------------setting viewing position---------------------------------// set_viewPosition(program); set_viewPosition(program1); set_viewPosition(program2); set_viewPosition(program3); //------------------------------------------------------end of setting-------------------------------------------// float last, start; last = start = glfwGetTime(); int fps=0; while (!glfwWindowShouldClose(window)) {//program will keep draw here until you close the window float delta = glfwGetTime() - start; render(); glfwSwapBuffers(window); //swap the color buffer and show it as output to the screen. glfwPollEvents(); //check if there is any event being triggered fps++; if(glfwGetTime() - last > 1.0) { std::cout<<(double)fps/(glfwGetTime()-last)<<std::endl; fps = 0; last = glfwGetTime(); } } releaseObjects(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; }