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