gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:50:41 25 4
gpt4 key购买 nike

这是我正在查看的关于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com