c++ - GLFW non-responsive fullscreen window -
i having issues glfw's window creation. wanting have program capable of toggling between windowed , fullscreen mode. in glfw 2.7.8 1 must first destroy active window, create new one. read version 3.0 has support multiple windows, still in development.
i have provided own function handle keyboard input. using initial 400 400 window, program functions expected; enter fullscreen on f or f, exit when escape key pressed, , complain when else pressed.
however, when fullscreen mode entered, window becomes unresponsive regards provided keyboard function. continue run through loop in main() , respond glfwgetkey(glfw_key_esc) test. regardless of if have mouse cursor enabled or not, cursor not appear.
again, fullscreen window created , keyboardcallback function returns main loop. wish understand why fullscreen window not working keyboard function, , why not displaying properly.
i not drawing window, trying experience various window abstraction libraries specifically. drawing simple triangle did nothing solve problem, , fullscreen window remains black.
my code follows:
#include <stdio.h> #include <stdlib.h> // glfw32 - 2.7.8 #include <gl\glfw.h> #pragma comment (lib, "glfw.lib") #pragma comment (lib, "opengl32.lib") using namespace std; // constants , globals const int window_width=400, window_height=400; static bool fullscreen=false; // function declarations void glfwcall keyboardcallback(int key, int action); void fatalerror(const char* msg) { fprintf(stderr, "error: failure in \"%s\"\n", msg); exit(1); } int main() { // ititialize glfw glfwinit(); glfwenable(glfw_mouse_cursor); glfwopenwindowhint(glfw_opengl_version_major, 3); glfwopenwindowhint(glfw_opengl_version_minor, 3); // initial window, 400x400 32-bit depth buffer in windowed mode glfwopenwindow(window_width, window_height, 0,0,0,0, 32, 0, glfw_window); glfwsetwindowtitle("simple title"); glfwsetwindowpos(0, 0); // set custom keyboard callback glfwsetkeycallback(keyboardcallback); while (true) { // loop until exit glclear(gl_color_buffer_bit); glfwswapbuffers(); // debug //printf("looping...\n"); if ( glfwgetkey(glfw_key_esc) ) {break;} } glfwterminate(); printf("\nhave nice day\n"); return 0; } void glfwcall keyboardcallback(int key, int action) { //printf("in keyboard function\n"); if (action) { // if key down, switch(key) { // something... case 'f': case 'f': { fullscreen = !fullscreen; printf("toggle fullscreen: %s\n", (fullscreen ? "on" : "off")); glfwclosewindow(); if (! glfwopenwindow(window_width, window_height, 0,0,0,0, 32, 0, fullscreen ? glfw_fullscreen : glfw_window)) { fatalerror("toggle fullscreen"); } glfwsetwindowtitle("new title"); break; } case glfw_key_esc: { printf("\ngoodbye cruel world...\n"); glfwterminate(); exit(0); } default: { printf("key not implemented: %c\n", key); break; } } } printf("exiting keyboard function\n"); } i tried james' approach here no effect. there glfw flags forgetting set?
edit------- 5/20
i had thought. perhaps callback being unregistered when window destroyed. turns out re-registering function when new window created made window responsive.
while solves original problem, face new one. cannot render new window properly. can insert glclear( gl_color_buffer_bit ); main loop, set background colour new window. reason not interact arrays , buffers draw image.
code attempted drawing
edit------- 5/21
i converted code glfw 3.0.0. window management cleaner (albeit more complex) , not have rendering issue. because explicitly have state current context use.
i still solve rendering issue, both out of curiosity , if/when return 2.7.
right event queue of glfw not pumped. must either set glfw_auto_poll_events option glfwswapbuffers pumps event queue, or call glfwpollevents @ start of main event loop iteration.
Comments
Post a Comment