glfw openglc++窗口背景和标题
glfw openGL c++ window background and title
这是我的一系列教程的源代码,我正在看一下关于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 GLFWn" );
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 windown" );
glfwTerminate();
return -1;
}
else
{
glfwSetWindowTitle( "Tutorial 01" );
}
// Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEWn");
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窗口",但在1-2秒后,标题变成了教程01,因为它应该在第一时间,背景变成了黑色,因为它应该也。
在我几年前对opengl (2.x)的研究中,我没有遇到这样的问题,有人能解释一下这里出了什么问题吗?
我在ATI FirePro V5700上得到相同的行为(甚至在IDE之外运行发布exe)。如果您真的对此感到困扰,请下载GLFW源代码并更改carbon_window.c的第764行、win32_window.c的第1210行和x11_window.c的第962行。
lib 碳 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" );
我没有遇到你描述的任何问题。我复制和粘贴,编译,然后运行你的代码,因为你张贴它(注释掉引用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)。
窗口的背景颜色是通过调用openGL函数glClearColor()来配置的,并使用glClear()函数来刷新。
更改窗口标题的延迟可能与创建opengl3有关。它需要创建一个标准的OpenGL上下文(版本1)。x或2.x),然后让你的应用程序选择使用opengl3。x上下文。1-2秒的延迟似乎很多。
这似乎与IDE有关,如果你运行实际的。exe,它会按预期工作,没有任何延迟。
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 使用窗口中的QSlider更改背景音量
- 对于C++,方括号中的标题必须总是在引号中的标题之上吗
- 库标题在标题中不可见,但在 cmake build 下.cpp文件中完全可见.为什么?
- 为什么我不应该把所有东西都放在标题中?
- SDL2 透明背景
- WinAPI 检查窗口是否具有常规标题栏
- 如何更改窗体上所有控件的标题?[C++生成器]
- 提升用于解析标题列的精神语法
- 所以我正在为我的学校作业练习继承,但我无法正确实施标题保护
- 如何删除已输入的书以及如何使标题,语言和名称在上面放置空格不会出错?
- 使用类 ?C++ 和 SFML 以及标题中的 15 个字符
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 我将如何在 cpp 中生成一个随机且独特的标题
- 如何在QT中获取背景应用程序窗口标题
- 窗口背景,如窗口 7 的标题栏
- 标题名称不显示,背景颜色不改变
- 如何改变从标题(水平/垂直)QTableWidget在Qt的背景颜色
- glfw openglc++窗口背景和标题