2017-08-25 69 views
1

OpenGLウィンドウのサイズを変更すると、ウィンドウのサイズを変更している間は描画されません。ウィンドウのサイズ変更が完了したら、ウィンドウの新しく露出した部分が描画されます。自分のアプリケーションのためのコードである。ここウィンドウのサイズ変更時に描画する方法

image

:あなたは下の画像の中で自分自身のためにそれを見ることができます。 Visual StudioでWindows 10を実行しています。

#include <glad/glad.h> 
#include <GLFW/glfw3.h> 
#include <iostream> 

void framebuffer_size_callback(GLFWwindow* window, int width, int height); 
void processInput(GLFWwindow *window); 
void get_resolution(int* window_width, int* window_height); 
void initGlfwSettings(); 
GLFWwindow* initGlfwWindow(); 
void initGlad(); 

// settings 
const unsigned int SCR_WIDTH = 800; 
const unsigned int SCR_HEIGHT = 600; 

int main() 
{ 
    initGlfwSettings(); 

    GLFWwindow* window = initGlfwWindow(); 

    initGlad(); 

    // glad: load all OpenGL function pointers 
    // --------------------------------------- 


    // render loop 
    // ----------- 
    while (!glfwWindowShouldClose(window)) 
    { 
     int width, height; 
     glfwGetWindowSize(window, &width, &height); 


     glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 
     glClear(GL_COLOR_BUFFER_BIT); 

     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 
     // input 
     // ----- 
     processInput(window); 

     // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) 
     // ------------------------------------------------------------------------------- 
     glfwSwapBuffers(window); 
     glfwPollEvents(); 
    } 

    // glfw: terminate, clearing all previously allocated GLFW resources. 
    // ------------------------------------------------------------------ 
    glfwTerminate(); 
    return 0; 
} 

// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly 
// --------------------------------------------------------------------------------------------------------- 
void processInput(GLFWwindow *window) 
{ 
    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) 
     glfwSetWindowShouldClose(window, true); 
} 

// glfw: whenever the window size changed (by OS or user resize) this callback function executes 
// --------------------------------------------------------------------------------------------- 
void framebuffer_size_callback(GLFWwindow* window, int width, int height) 
{ 
    // make sure the viewport matches the new window dimensions; note that width and 
    // height will be significantly larger than specified on retina displays. 
    glViewport(0, 0, width, height); 
} 

void get_resolution(int* window_width, int* window_height) { 
    const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 

    *window_width = mode->width; 
    *window_height = mode->height; 
} 

void initGlfwSettings() 
{ 
    // glfw: initialize and configure 
    // ------------------------------ 
    glfwInit(); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 


    #ifdef __APPLE__ 
     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X 
    #endif 
} 

GLFWwindow* initGlfwWindow() 
{ 
    /*GLFWmonitor* monitor = glfwGetPrimaryMonitor(); 
    int width; 
    int height; 

    get_resolution(&width, &height);*/ 



    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "learning opengl", NULL, NULL); 
    if (window == NULL) 
    { 
     std::cout << "Failed to create GLFW window" << std::endl; 
     glfwTerminate(); 
     exit(1); 
    } 

    glfwMakeContextCurrent(window); 
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 
    glfwSwapInterval(1); 

    return window; 
} 

void initGlad() 
{ 
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) 
    { 
     std::cout << "Failed to initialize GLAD" << std::endl; 
     exit(1); 
    } 
} 

この問題の解決方法を説明してください。

答えて

0

メインスレッドに制御を戻していないのは、Windowsイベントハンドラです。そのウィンドウの仕組みとそれを変更することはできません。

ただし、すべてのレンダリングコマンドとglfwコマンドを別のスレッドに移動することはできますが、これはウィンドウで停止することはありません。

+0

通常は、ウィンドウのサイズと同じフレームバッファを使用することが多いため、サイズ変更が完了したときにのみコントロールが返されることは良いことです。これらは、サイズ変更が完了したときに一度だけサイズを変更する必要があります。 – dari

+0

私が構築したすべてのものを更新し続けたいだけでした。実行中のビデオやライブデータのようなものは、最小限のキャプチャでは、ストールを避けるために独自のスレッドが必要です。 –

+0

@JonathanOlsonあなたはこのことをどうやって具体化しますか?私はそれを自分で実装しようと2回試してみましたが、すべてが表示されても読み込みカーソルは常に表示されます。私の2回目には黒い画面が表示されます。 –

関連する問題