0

これは、opengl3+に関して調べている一連のチュートリアルのソースコードです。

//#include <stdio.h>
//#include <stdlib.h>

#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>
using namespace glm;

#include <iostream>
using namespace std;



int main()
{

    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.3
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
    {
        fprintf( stderr, "Failed to open GLFW window\n" );
        glfwTerminate();
        return -1;
    }
    else
    {
        glfwSetWindowTitle( "Tutorial 01" );
    }

    // Initialize GLEW
    glewExperimental=true; // Needed in core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }



    glfwEnable( GLFW_STICKY_KEYS );

    do{
        // Draw nothing, see you in tutorial 2 !

        // Swap buffers
        glfwSwapBuffers();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
    glfwGetWindowParam( GLFW_OPENED ) );

    return 0;
}

ウィンドウが初期化されると、背景色が白でタイトルが「GLFW WINDOW」になることを除いて、すべてがうまく機能しますが、1〜2秒後に、タイトルが最初の場所にあるはずのチュートリアル01に変わり、背景が黒になります。 、そうあるべきだったので。

私が数年前に行った過剰なopengl(2.x)の以前の研究では、誰かがここで何が悪いのか説明できるような問題はありませんでしたか?

4

4 に答える 4

2

ATI FirePro V5700 でも同じ動作 (IDE の外部でリリース exe を実行しても) が発生します。どうしても気になる場合は、GLFW のソースをダウンロードして、carbon_window.c の 764 行目、win32_window.c の 1210 行目、x11_window.c の 962 行目を変更してください。

.\lib\carbon\carbon_window.c

(void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) );

.\lib\win32\win32_window.c

_glfwWin.window = CreateWindowEx( _glfwWin.dwExStyle,    // Extended style
                                  _GLFW_WNDCLASSNAME,    // Class name
                                  "GLFW Window",         // Window title
                                  _glfwWin.dwStyle,      // Defined window style
                                  wa.left, wa.top,       // Window position
                                  fullWidth,             // Decorated window width
                                  fullHeight,            // Decorated window height
                                  NULL,                  // No parent window
                                  NULL,                  // No menu
                                  _glfwLibrary.instance, // Instance
                                  NULL );                // Nothing to WM_CREATE

.\lib\x11\x11_window.c

_glfwPlatformSetWindowTitle( "GLFW Window" );
于 2013-01-10T08:00:50.137 に答える
1

あなたが説明した問題は発生していません。コードをコピーして貼り付け、コンパイルし、投稿したとおりに実行しました(そのライブラリがインストールされていないため、GLMへの参照をコメントアウトしています)。タイトルが瞬時に変わります。「GLFW WINDOW」というタイトルのウィンドウすら見たことがなく、グラフィック領域の色がすぐに黒くなります。お使いのコンピュータがあまり高速ではない可能性がありますか?

以下を実行するとどうなりますか?

do{
    // Draw nothing, see you in tutorial 2 !
    glClear(GL_COLOR_BUFFER_BIT);
    // Swap buffers
    glfwSwapBuffers();
    glfwSleep(0.016);
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) );

編集:私の GPU は Nvidia GTX 580 (少なくとも OpenGL 4.3 に対応) です。

于 2013-01-09T21:19:30.493 に答える
0

IDEに関係しているようですが、実際の.exeを実行すると、意図したとおりに動作し、遅延はまったく発生しません。

于 2013-01-09T21:47:20.743 に答える
0

ウィンドウの背景色は、openGL 関数glClearColor()の呼び出しによって構成され、 glClear()関数で更新されます。

ウィンドウのタイトルの変更が遅れているのは、openGL 3.x を作成するには、標準の OpenGL コンテキスト (バージョン 1.x または 2.x) を作成してから取得する必要があるという事実に関係している可能性があります。アプリケーションで OpenGL 3.x コンテキストの使用をオプトインします。ただし、1〜2秒の遅延はかなりのようです。

于 2013-01-09T21:07:40.353 に答える