88 lines
2.0 KiB
C++
88 lines
2.0 KiB
C++
// 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 <GL/glew.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include "gfx.hpp"
|
|
#include "icosphere.hpp"
|
|
#include "orbit.hpp"
|
|
|
|
int main()
|
|
{
|
|
GLFWwindow* window = nullptr;
|
|
if (initGraphics(&window, "Hello Astro") != 0)
|
|
return -1;
|
|
|
|
GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
|
|
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
|
|
|
|
Icosphere planet(0.2, 3, litProgram);
|
|
Icosphere orbiter(0.07, 2, litProgram);
|
|
Orbit orbit(100);
|
|
|
|
// Main loop
|
|
while (!glfwWindowShouldClose(window))
|
|
{
|
|
glClearColor(0.2, 0.3, 0.3, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
float time = glfwGetTime();
|
|
|
|
glm::vec3 pos = orbit.getPosition(time);
|
|
orbiter.setPosition(pos);
|
|
|
|
// Render lit objects
|
|
glUseProgram(litProgram);
|
|
updateModelViewProjectionMatrix(litProgram, time);
|
|
|
|
planet.render();
|
|
orbiter.render();
|
|
|
|
// Render unlit objects
|
|
glUseProgram(unlitProgram);
|
|
updateModelViewProjectionMatrix(unlitProgram, time);
|
|
orbit.render();
|
|
|
|
glfwSwapBuffers(window);
|
|
glfwPollEvents();
|
|
}
|
|
|
|
glfwTerminate();
|
|
return 0;
|
|
}
|