// To compile on Windows // Install GLFW 3.3.8 // https://www.glfw.org/download.html // Install GLEW 2.2.0 // https://github.com/nigels-com/glew/releases/tag/glew-2.2.0 // // extract the downloaded .zip files to "C:/libs"; this is currently expected // by our CMakeLists.txt. // Install CMake // https://cmake.org/download // Add to PATH for all users // from project root: // mkdir build // cd build // cmake .. // cmake --build . // The last step compiles the executable - this can also be done from Visual // Studio // To run in VS // Set startup project in Solution Explorer // Press F5 to run // To run in VSCode // https://code.visualstudio.com/docs/cpp/config-mingw // To compile on Arch Linux // // Install dependencies // sudo pacman -S glfw mesa glew // // Build // cmake .. // cmake --build . #include #include #include #include #include #include #include "io.hpp" #include "triangle.hpp" GLuint compileShader(const std::string& shaderPath, GLenum shaderType) { GLuint shader; GLint success; std::string shaderSource = readFile(shaderPath); const char* source = shaderSource.c_str(); shader = glCreateShader(shaderType); glShaderSource(shader, 1, &source, NULL); glCompileShader(shader); glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { GLchar infoLog[512]; glGetShaderInfoLog(shader, 512, NULL, infoLog); std::cerr << "shader compilation failed" << std::endl << infoLog << std::endl; } return shader; } std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now(); float getTime() { std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); std::chrono::duration timeSpan = std::chrono::duration_cast>(now - startTime); return timeSpan.count(); } #include #include "astro/twoBodyMethods.hpp" // Initialize GLFW, OpenGL and GLEW, open a window and make it the current context. // Returns 0 for success, and -1 for any failure. // Failures are printed to STDERR. int initGraphics(GLFWwindow** window) { // Set up GLFW, OpenGL and GLEW. if (!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return -1; } *window = glfwCreateWindow(640, 480, "Hello Astro", NULL, NULL); if (!window) { glfwTerminate(); std::cerr << "Failed to open window with GLFW" << std::endl; return -1; } glfwMakeContextCurrent(*window); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { std::cerr << "Failed to initialize GLEW" << std::endl; return -1; } return 0; } GLuint getShaderProgram() { GLuint vertShader = compileShader("./vert.glsl", GL_VERTEX_SHADER); GLuint fragShader = compileShader("./frag.glsl", GL_FRAGMENT_SHADER); GLuint shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertShader); glAttachShader(shaderProgram, fragShader); glLinkProgram(shaderProgram); GLint success; GLchar infoLog[512]; glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog); std::cerr << "shader linking failed" << std::endl << infoLog << std::endl; } // We no longer need the individual shaders glDeleteShader(vertShader); glDeleteShader(fragShader); return shaderProgram; } int main() { // Calculate period of ISS orbit around the Earth const float semiMajorAxis = 6738000; const float gravitationalParameter = 3.986e14; float period = astro::computeKeplerOrbitalPeriod(semiMajorAxis, gravitationalParameter); period /= 60.0; std::cout << period << std::endl; glm::vec3 v(0.0, 1.0, 2.0); std::cout << "(" << v.x << ", " << v.y << ", " << v.z << ")" << std::endl; GLFWwindow* window = nullptr; if (initGraphics(&window) != 0) return -1; Triangle triangle(getShaderProgram()); // Main loop while (!glfwWindowShouldClose(window)) { glClearColor(0.2, 0.3, 0.3, 1.0); glClear(GL_COLOR_BUFFER_BIT); triangle.render(getTime()); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; }