c++ - glfw openGL c++ 窗口背景和标题

标签 c++ opengl glew glfw

这是我正在查看的关于 opengl 3+ 的一系列教程的源代码。

//#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 秒后标题变成了 Tutorial 01,因为它本来应该放在第一位,并且背景变成黑色,本应如此。

在我几年前做过的关于 opengl (2.x) 过剩的研究中,我没有遇到过这样的问题,有人能解释一下这里出了什么问题吗?

最佳答案

我在 ATI FirePro V5700 上得到了相同的行为(甚至在 IDE 之外运行发布 exe)。如果你真的被它困扰,download the GLFW source并更改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" );

关于c++ - glfw openGL c++ 窗口背景和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14246315/

相关文章:

c++ - 使用 GLEW 时,为什么我的系统支持 OpenGL 3.2 而我的 GPU 仅兼容 2.0?

c++ - 在C++中的赋值运算符重载方法中删除旧的动态分配内存

c++ - 枚举 C++ 按索引获取

c++ - 当多次链接 DLL 时,导出的全局变量会发生什么情况?

c++ - 在 visual studio 2010 和 c++ 中使用 OpenGL 绘制带有箭头的轴

opengl - 用阴影渲染行星周围的大气层

c++ - 对 glewInit()@0 的 undefined reference

c++ - 如何将 GLEW 与 MinGW 一起使用

c++ - 如何使用 OpenSSL 的 SHA256 函数

c++ - std::shared_ptr::reset() "invalidates"其他引用