Skip to content

Instantly share code, notes, and snippets.

@laxmanjangley
Created November 13, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laxmanjangley/9b28e01bb14e45397cabe5fe8be267db to your computer and use it in GitHub Desktop.
Save laxmanjangley/9b28e01bb14e45397cabe5fe8be267db to your computer and use it in GitHub Desktop.
#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