Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created December 5, 2016 17:17
Show Gist options
  • Save Mikulas/00ff3e804e9ac7b3cdb735bae7de621a to your computer and use it in GitHub Desktop.
Save Mikulas/00ff3e804e9ac7b3cdb735bae7de621a to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#include <GL/glew.h>
#define GLEW_STATIC
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>
using namespace glm;
void error_callback(int error, const char *message) {
fprintf(stderr, "GLFW error: %s\n", message);
glfwTerminate();
exit(EXIT_FAILURE);
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {}
void character_callback(GLFWwindow* window, unsigned int codepoint) {}
void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods) {}
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {}
void cursor_enter_callback(GLFWwindow* window, int entered) {}
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {}
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {}
void joystick_callback(int joy, int event) {}
void drop_callback(GLFWwindow* window, int count, const char** paths) {}
int main() {
/* Create a window */
glfwSetErrorCallback(error_callback);
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow *window = glfwCreateWindow(
1024,
1024,
"test", nullptr, nullptr
);
glfwSetWindowPos(window, 0, 0);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
/* Initialize OpenGL */
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
printf("Failed to initialize GLEW.\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// force highest FPS possible
glfwSwapInterval(0);
GLfloat delta = 0.0f;
GLfloat lastFrame = 0.0f;
int fps = 0;
GLfloat cycleSum = 0;
GLfloat lastFpsFrame = 0.0f;
glfwPollEvents();
GLuint fbo;
glGenFramebuffers(1, &fbo);
while (!glfwWindowShouldClose(window)) {
GLfloat currentFrame = glfwGetTime();
delta = currentFrame - lastFrame;
lastFrame = currentFrame;
if (currentFrame - lastFpsFrame > 1.0) {
printf("%6.2f\n", cycleSum * 1000.f / fps);
cycleSum = 0;
fps = 0;
lastFpsFrame = currentFrame;
}
cycleSum += delta;
fps++;
#if TRUE
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#else
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
#endif
glfwSwapBuffers(window);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment