// the program starts here void AppMain() { // initialise GLFW glfwSetErrorCallback(OnError); if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); gWindow = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y, "OpenGL Tutorial", NULL, NULL); if(!gWindow) throw std::runtime_error("glfwCreateWindow failed. Can your hardware handle OpenGL 3.2?"); // GLFW settings glfwMakeContextCurrent(gWindow); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); // OpenGL settings glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // load vertex and fragment shaders into opengl LoadShaders(); // load the texture LoadTexture(); // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open while(!glfwWindowShouldClose(gWindow)){ // process pending events glfwPollEvents(); // draw one frame Render(); } // clean up and exit glfwTerminate(); }
void AppMain() { if(!glfwInit()) throw std::runtime_error("glfwInit failed"); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE); if(!glfwOpenWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW)) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); glfwDisable(GLFW_MOUSE_CURSOR); glfwSetMousePos(0,0); glfwSetMouseWheel(0); LoadShaders(); LoadTriangle(); //intialise the Camera position gCamera.setPosition(glm::vec3(0,0,4)); gCamera.setViewportAspectRatio(SCREEN_SIZE.x / SCREEN_SIZE.y); gCamera.setNearAndFarPlanes(0.5, 100.0f); Axis = glm::vec3(0,1,0); //intialise the Light attribute gLight.position = glm::vec3(0.0f,0.1f,-0.1f); gLight.intensities = glm::vec3(0.8,0.78,1); // white light gLight.attenuation = 0.2f; gLight.ambientCoefficient = 0.005f; double lastTime = glfwGetTime(); while(glfwGetWindowParam(GLFW_OPENED)){ double thisTime = glfwGetTime(); Update(thisTime - lastTime); lastTime = thisTime; Render(); } glfwTerminate(); }
// the program starts here void MainAppFunc() { // initialise GLFW if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); MainWindow = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y,"Draw Basic Shapes",NULL,NULL); if(!MainWindow) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 4.2?"); // GLFW settings glfwMakeContextCurrent(MainWindow); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_4_2) throw std::runtime_error("OpenGL 4.2 API is not available."); // load vertex and fragment shaders into opengl //LoadShaders(); if(!createShaderProgram()) { std::cerr << "Could not create the shaders"; } // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open while(!glfwWindowShouldClose(MainWindow)){ // process pending events glfwPollEvents(); // draw one frame Render(MainWindow); } // clean up and exit glfwTerminate(); }
// the program starts here void AppMain() { // initialise GLFW if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); if(!glfwOpenWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW)) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?"); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_3_2) throw std::runtime_error("OpenGL 3.2 API is not available."); // OpenGL settings glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // load vertex and fragment shaders into opengl LoadShaders(); // load the texture LoadTexture(); // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open while(glfwGetWindowParam(GLFW_OPENED)){ // draw one frame Render(); } // clean up and exit glfwTerminate(); }
Asset::Asset(Shape s, Texture* tex, Program* prog) { program = prog; texture = tex; shape = s; switch(shape){ case Triangle: LoadTriangle(); break; case Cube: LoadCube(); break; } }
int main(int argc, char **argv) { Initialize(argc, argv); InitializeUI(); glutReshapeFunc(ResizeFunction); glutDisplayFunc(RenderFunction); glutIdleFunc(RenderFunction); glewInit(); programID = LoadShaders("shader.vert", "shader.frag"); LoadTriangle(); CreateGeometry(); glutMainLoop(); TwTerminate(); }
// the program starts here void MainApplication() { // initialise GLFW if(!glfwInit()) throw std::runtime_error("glfwInit failed"); // open a window with GLFW glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); MainWindow = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y,"Rotation",NULL,NULL); if(!MainWindow) throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 4.2?"); glfwSetWindowSizeCallback(MainWindow,handleResize); //callback function of GLFW to handle window resize glfwSetKeyCallback(MainWindow,handleKeypress); //callback function to handle keypress glfwMakeContextCurrent(MainWindow); // initialise GLEW glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/ if(glewInit() != GLEW_OK) throw std::runtime_error("glewInit failed"); // print out some info about the graphics drivers std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl; std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; // make sure OpenGL version 3.2 API is available if(!GLEW_VERSION_4_2) throw std::runtime_error("OpenGL 4.2 API is not available."); // load vertex and fragment shaders into opengl LoadShaders(); // create buffer and fill it with the points of the triangle LoadTriangle(); // run while the window is open double lastTime = glfwGetTime(); while(!glfwWindowShouldClose(MainWindow)){ // update the scene based on the time elapsed since last update double thisTime = glfwGetTime(); Update(thisTime - lastTime); lastTime = thisTime; // process pending events glfwPollEvents(); // draw one frame Render(MainWindow); // check for errors GLenum error = glGetError(); if(error != GL_NO_ERROR) std::cerr << "OpenGL Error " << error /*<< ": " << (const GLubyte)gluErrorString(error)*/ << std::endl; } // clean up and exit glfwTerminate(); }