chore: extract graphics init to function
This commit is contained in:
parent
5d80d4a033
commit
37dbe741fa
|
@ -82,6 +82,38 @@ float getTime()
|
|||
#include <cmath>
|
||||
#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;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Calculate period of ISS orbit around the Earth
|
||||
|
@ -94,26 +126,10 @@ int main()
|
|||
glm::vec3 v(0.0, 1.0, 2.0);
|
||||
std::cout << "(" << v.x << ", " << v.y << ", " << v.z << ")" << std::endl;
|
||||
|
||||
// Set up GLFW, OpenGL and GLEW.
|
||||
if (!glfwInit())
|
||||
GLFWwindow* window = nullptr;
|
||||
if (initGraphics(&window) != 0)
|
||||
return -1;
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(640, 480, "Hello Astro", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
glewExperimental = GL_TRUE;
|
||||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
std::cerr << "Failed to initialize GLEW" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// VAO, VBO
|
||||
float vertices[] =
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue