Created
November 13, 2016 15:16
-
-
Save laxmanjangley/9b28e01bb14e45397cabe5fe8be267db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "PCUtils.h" | |
GLFWwindow* window; | |
double oldTime = glfwGetTime(); | |
int frames = 0; | |
void setupWindowAndGLContext(){ | |
srand(time(NULL)); | |
if( !glfwInit() ) | |
{ | |
fprintf( stderr, "Failed to initialize GLFW\n" ); | |
return ; | |
} | |
glfwWindowHint(GLFW_SAMPLES, 4); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
window = glfwCreateWindow( 1366, 768, "Fluid Simmulator", glfwGetPrimaryMonitor(), NULL); | |
glfwMakeContextCurrent(window); | |
glewExperimental = true; | |
if (glewInit() != GLEW_OK) { | |
fprintf(stderr, "Failed to initialize GLEW\n"); | |
return ; | |
} | |
glfwSwapInterval(1); | |
glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, 1); | |
glfwSetInputMode(window, GLFW_STICKY_KEYS, 1); | |
} | |
void SwapBuffer(){ | |
glfwSwapBuffers(window); | |
frames++; | |
double now = glfwGetTime (); | |
if(now - oldTime > 1.0){ | |
cout<<frames<<endl; | |
frames = 0; | |
oldTime = now; | |
} | |
} | |
bool PollForESC(){ | |
glfwPollEvents(); | |
if(glfwGetKey(window, GLFW_KEY_ESCAPE ) == GLFW_PRESS || glfwWindowShouldClose(window)){ | |
glfwDestroyWindow(window); | |
glfwTerminate(); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment