//Overloaded version of inherited method that I added void MyGL::resizeGL() { //This code sets the concatenated view and perspective projection matrices used for //our scene's camera view. // vvv Like this. ---YKV--- //Create Camera glm::mat4 viewproj = camera.createViewProjMatrix(); // Upload the view-projection matrix to our shaders (i.e. onto the graphics card) QMatrix4x4 qviewproj = la::to_qmat(viewproj); prog_lambert.prog.bind(); prog_lambert.prog.setUniformValue(prog_lambert.unifViewProj, qviewproj); prog_wire.prog.bind(); prog_wire.prog.setUniformValue(prog_wire.unifViewProj, qviewproj); prog_mesh.prog.bind(); prog_mesh.prog.setUniformValue(prog_mesh.unifViewProj, qviewproj); prog_selection.prog.bind(); prog_selection.prog.setUniformValue(prog_selection.unifViewProj, qviewproj); printGLErrorLog(); }
void MyGL::resizeGL(int w, int h) { gl_camera = Camera(w, h); glm::mat4 viewproj = gl_camera.getViewProj(); // Upload the projection matrix prog_lambert.setViewProjMatrix(viewproj); prog_flat.setViewProjMatrix(viewproj); printGLErrorLog(); }
void Character::initializeGL() { // Create an OpenGL context initializeOpenGLFunctions(); // Print out some information about the current OpenGL context debugContextVersion(); // Set a few settings/modes in OpenGL rendering glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); // Set the size with which points should be rendered glPointSize(5); // Set the color with which the screen is filled at the start of each render call. glClearColor(0.5, 0.5, 0.5, 1); printGLErrorLog(); // Create a Vertex Attribute Object vao.create(); //Create the body objects torso.create(); head.create(); rightUpperArm.create(); rightLowerArm.create(); leftUpperArm.create(); leftLowerArm.create(); rightUpperLeg.create(); rightLowerLeg.create(); leftUpperLeg.create(); leftLowerLeg.create(); // Create and set up the diffuse shader prog_lambert.create(":/glsl/lambert.vert.glsl", ":/glsl/lambert.frag.glsl"); // Create and set up the wireframe shader prog_wire.create(":/glsl/wire.vert.glsl", ":/glsl/wire.frag.glsl"); // We have to have a VAO bound in OpenGL 3.2 Core. But if we're not // using multiple VAOs, we can just bind one once. vao.bind(); }
void MyGL::initializeGL() { // Create an OpenGL context initializeOpenGLFunctions(); // Print out some information about the current OpenGL context debugContextVersion(); // Set a few settings/modes in OpenGL rendering glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); // Set the size with which points should be rendered glPointSize(5); // Set the color with which the screen is filled at the start of each render call. glClearColor(0.5, 0.5, 0.5, 1); printGLErrorLog(); // Create a Vertex Attribute Object vao.create(); //Create the example sphere (you should delete this when you add your own code elsewhere) geom_sphere.setColor(glm::vec4(0,1,0,1)); geom_sphere.create(); //Create Sphere geom_cube.setColor(glm::vec4(0,1,1,1)); geom_cube.create(); //Create Cube geom_cone.create(); //Create Cone geom_pipe.create(); //Create Pipe geom_cylinder.create(); // Create and set up the diffuse shader prog_lambert.create(":/glsl/lambert.vert.glsl",":/glsl/lambert.frag.glsl"); // Create and set up the wireframe shader prog_wire.create(":/glsl/wire.vert.glsl",":/glsl/wire.frag.glsl"); //Create and set up the mesh shader prog_mesh.create(":/glsl/mesh.vert.glsl",":/glsl/mesh.frag.glsl"); //Create and setup the selection shader prog_selection.create(":/glsl/mesh.vert.glsl",":/glsl/wire.frag.glsl"); // We have to have a VAO bound in OpenGL 3.2 Core. But if we're not // using multiple VAOs, we can just bind one once. vao.bind(); }
void MyGL::initializeGL() { // Create an OpenGL context initializeOpenGLFunctions(); // Print out some information about the current OpenGL context debugContextVersion(); // Set a few settings/modes in OpenGL rendering glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); // Set the size with which points should be rendered glPointSize(5); // Set the color with which the screen is filled at the start of each render call. glClearColor(0.5, 0.5, 0.5, 1); printGLErrorLog(); // Create a Vertex Attribute Object vao.create(); // Create and set up the diffuse shader prog_lambert.create(":/glsl/lambert.vert.glsl", ":/glsl/lambert.frag.glsl"); // Create and set up the flat-color shader prog_flat.create(":/glsl/flat.vert.glsl", ":/glsl/flat.frag.glsl"); // We have to have a VAO bound in OpenGL 3.2 Core. But if we're not // using multiple VAOs, we can just bind one once. vao.bind(); //Test scene data initialization scene.CreateTestScene(); integrator.scene = &scene; integrator.intersection_engine = &intersection_engine; intersection_engine.scene = &scene; ResizeToSceneCamera(); //create new tree with this new set of geometry! this->intersection_engine.BVHrootNode = new BVHnode(); this->intersection_engine.BVHrootNode = createBVHtree(this->intersection_engine.BVHrootNode, this->scene.objects, 0); update(); }
void Character::resizeGL(int w, int h) { //This code sets the concatenated view and perspective projection matrices used for //our scene's camera view. // vvv TODO REPLACE THIS CODE IN HW2 glm::vec4 c1(1.1933f, 0, 1.1933f, 0); glm::vec4 c2(0.9856f, 1.9712f, -0.9856f, 0); glm::vec4 c3(0.5785f, -0.5785f, -0.5785f, 11.9484f); glm::vec4 c4(0.5774f, -0.5774f, -0.5774f, 12.1244f); glm::mat4 viewproj(c1, c2, c3, c4); viewproj = glm::transpose(viewproj); // ^^^ TODO REPLACE THIS CODE IN HW2 // Upload the view-projection matrix to our shaders (i.e. onto the graphics card) QMatrix4x4 qviewproj = la::to_qmat(viewproj); prog_lambert.prog.bind(); prog_lambert.prog.setUniformValue(prog_lambert.unifViewProj, qviewproj); prog_wire.prog.bind(); prog_wire.prog.setUniformValue(prog_wire.unifViewProj, qviewproj); printGLErrorLog(); }
int main(int argc, char** argv) { if(argc < 2) { std::cerr << "usage: " << argv[0] << " " << "config\n"; return EXIT_FAILURE; } if(!glfwInit()) exit(EXIT_FAILURE); GLFWwindow* window = glfwCreateWindow(xSize, ySize, "Scene Graph", NULL, NULL); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwMakeContextCurrent(window); glewInit(); // Set the color which clears the screen between frames glClearColor(0, 0, 0, 1); // Enable and clear the depth buffer glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // initialize the scene std::ifstream in(argv[1]); if(!in) { std::cout << "couldn't open config " << argv[1] << "\n"; return EXIT_FAILURE; } Config sceneConf(in); scene = new Scene(sceneConf); in.close(); // get the render order nodeList = scene->nodeList(); if(nodeList.size() > 0) { std::string sel = nodeList.front(); scene->bindShader(sel, "contour"); } glfwSetWindowSizeCallback(window, resize); glfwSetKeyCallback(window, keypress); glfwSetCursorPosCallback(window, mousepos); glfwSetScrollCallback(window, scroll); int nbFrames = 0; double lastTime = glfwGetTime(); while(!glfwWindowShouldClose(window)) { // Clear the screen so that we only see newly drawn images glfwSetCursorPos(window, xSize/2, ySize/2); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); scene->draw("diffuse"); scene->draw("contour"); // Move the rendering we just made onto the screen glfwSwapBuffers(window); glfwPollEvents(); double currentTime = glfwGetTime(); nbFrames++; if (currentTime - lastTime >= 1.0){ printf("%f ms/frame\n", 1000.0/double(nbFrames)); nbFrames = 0; lastTime += 1.0; } // Check for any GL errors that have happened recently printGLErrorLog(); } glfwDestroyWindow(window); glfwTerminate(); delete scene; return EXIT_SUCCESS; }