From e3163ca8a315aeb3f9986cd3d181ada77954b6df Mon Sep 17 00:00:00 2001 From: outfrost Date: Tue, 22 Jan 2019 22:24:00 +0100 Subject: [PATCH] Add vsync via EXT_swap_control --- Makefile | 2 +- main.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9486be4..3dfa87d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ compileargs ::= -g -Wall -Wextra -Wpedantic linkargs ::= -libraries ::= -L/usr/local/lib -lGL -lglut -lassimp +libraries ::= -L/usr/local/lib -lGL -lGLEW -lglut -lassimp # Prefix all object file names with the compilation directory objects ::= $(addprefix out/, \ main.o debugutil.o glut_janitor.o render.o \ diff --git a/main.c b/main.c index 32f2c85..28b3c4d 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,6 @@ +#include #include +#include #include "debugutil.h" #include "glut_janitor.h" @@ -8,14 +10,40 @@ int main(int argc, char** argv) { glutInit(&argc, argv); + // glutInitContextVersion(4,5); TODO establish correct context glutInitWindowSize(800, 600); - glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutCreateWindow(NULL); glutSetWindowTitle(getGlInfoString()); + GLenum glewInitStatus = glewInit(); + if (glewInitStatus != GLEW_OK) { + fprintf(stderr, "GLEW init failed: %s\n", glewGetErrorString(glewInitStatus)); + return 1; + } + printf("GLEW %s\n", glewGetString(GLEW_VERSION)); + + if (GLXEW_EXT_swap_control) { + Display* display = glXGetCurrentDisplay(); + GLXDrawable drawable = glXGetCurrentDrawable(); + if (drawable) { + glXSwapIntervalEXT(display, drawable, 1); + } + else { + fprintf(stderr, "Drawable is not here\n"); + } + } + else if (GLXEW_MESA_swap_control) { + glXSwapIntervalMESA(1); + printf("Swap interval %d\n", glXGetSwapIntervalMESA()); + } + else { + fprintf(stderr, "Could not enable vsync\n"); + } + glutDisplayFunc(renderScene); glutReshapeFunc(resizeStage); //glutKeyboardFunc(key_pressed); -- 2.44.0