diff --git a/CMakeLists.txt b/CMakeLists.txt index 5469139..5bcf3b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,4 +27,4 @@ link_directories(/usr/local/lib) add_executable(erc ${sources} src/main.c) # Graphics -target_link_libraries(erc ${opengl_library} glfw) +target_link_libraries(erc ${opengl_library} glfw GLEW) diff --git a/include/vm_screen.h b/include/vm_screen.h index 2a49e28..8ef7d29 100644 --- a/include/vm_screen.h +++ b/include/vm_screen.h @@ -1,9 +1,13 @@ #ifndef _VM_SCREEN_H_ #define _VM_SCREEN_H_ +#include #include #include +#define VM_SCREEN_DEFWIDTH 800 +#define VM_SCREEN_DEFHEIGHT 600 + /* * If you just want to plot a single pixel, you can use this macro to * abstract away the need to indicate the x/y dimensions (as those must diff --git a/src/vm_screen.c b/src/vm_screen.c index fb4736b..e222272 100644 --- a/src/vm_screen.c +++ b/src/vm_screen.c @@ -6,11 +6,25 @@ * program, which only knows to call the functions here. */ +#include #include #include "log.h" #include "vm_screen.h" +static bool init_glew = false; + +static void +glew_init() +{ + if (!init_glew) { + glewExperimental = GL_TRUE; + glewInit(); + + init_glew = true; + } +} + int vm_screen_init() { @@ -18,6 +32,13 @@ vm_screen_init() return ERR_GFXINIT; } + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + return OK; } @@ -48,7 +69,10 @@ vm_screen_create() int vm_screen_add_window(vm_screen *screen) { - screen->window = glfwCreateWindow(320, 240, "erc", NULL, NULL); + screen->window = glfwCreateWindow(VM_SCREEN_DEFWIDTH, + VM_SCREEN_DEFHEIGHT, + "erc", NULL, NULL); + if (screen->window == NULL) { log_critical("Could not create a window"); return ERR_GFXINIT; @@ -56,6 +80,10 @@ vm_screen_add_window(vm_screen *screen) glfwMakeContextCurrent(screen->window); + // glew can only be initialized _after_ the window is built; if you + // do so beforehand, you will be rudely presented with a segfault. + glew_init(); + return OK; }