C++ glfw openglc++;窗口背景和标题
这是我从一系列教程中获得的源代码,我正在研究OpenGL3+C++ glfw openglc++;窗口背景和标题,c++,opengl,glew,glfw,C++,Opengl,Glew,Glfw,这是我从一系列教程中获得的源代码,我正在研究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
//#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;
}
/#包括
//#包括
#包括
#包括
#包括
使用名称空间glm;
#包括
使用名称空间std;
int main()
{
如果(!glfwInit())
{
fprintf(stderr,“未能初始化GLFW\n”);
返回-1;
}
glfwOpenWindowHint(GLFW_FSAA_示例,4);//4x抗锯齿
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR,3);//我们想要OPENGL 3.3
glfwOpenWindowHint(GLFW_OPENGL_版本_小调,2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);//我们不想要旧的OPENGL
//打开窗口并创建其OpenGL上下文
如果(!glfwOpenWindow(1024768,0,0,0,0,32,0,GLFWU窗口))
{
fprintf(stderr,“无法打开GLFW窗口\n”);
glfwTerminate();
返回-1;
}
其他的
{
glfwSetWindowTitle(“教程01”);
}
//初始化GLEW
glewExperimental=true;//核心配置文件中需要
如果(glewInit()!=GLEW\u确定){
fprintf(stderr,“未能初始化GLEW\n”);
返回-1;
}
glfwEnable(GLFW_粘滞_键);
做{
//什么也不画,见教程2!
//交换缓冲区
glfwSwapBuffers();
}//检查是否按下ESC键或窗口是否关闭
while(glfwGetKey(GLFW_KEY_ESC)!=GLFW_按&&
glfwGetWindowParam(GLFW_打开));
返回0;
}
一切都很好,只是当窗口初始化时,背景颜色为白色,标题为“GLFW window”,但在1-2秒后,标题变为教程01,因为它应该放在第一位,背景也应该变为黑色
在几年前我对带有glut的opengl(2.x)的先前研究中,我没有类似的问题。有人能解释一下这里出了什么问题吗?窗口的背景颜色是通过调用opengl函数配置的,并使用函数刷新
更改窗口标题的延迟可能与以下事实有关:要创建openGL 3.x,需要创建标准openGL上下文(版本1.x或2.x),然后让应用程序选择使用openGL 3.x上下文。1-2秒的延迟似乎很大。通过调用openGL函数来配置窗口的背景色,并使用函数刷新
更改窗口标题的延迟可能与以下事实有关:要创建openGL 3.x,需要创建标准openGL上下文(版本1.x或2.x),然后让应用程序选择使用openGL 3.x上下文。不过,1-2秒的延迟似乎很多。我没有遇到您描述的任何问题。我复制、粘贴、编译,然后在发布代码时运行代码(注释对GLM的引用,因为我没有安装该库)。标题对我来说是瞬间变化的——我甚至从来没有看到窗口的标题是“GLFW窗口”,图形区域的颜色立即变为黑色。可能是因为你的电脑速度不是很快吗 如果您执行以下操作,会发生什么情况
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)。我没有遇到您描述的任何问题。我复制、粘贴、编译,然后在发布代码时运行代码(注释对GLM的引用,因为我没有安装该库)。标题对我来说是瞬间变化的——我甚至从来没有看到窗口的标题是“GLFW窗口”,图形区域的颜色立即变为黑色。可能是因为你的电脑速度不是很快吗 如果您执行以下操作,会发生什么情况
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)。它似乎与IDE有关,如果您运行实际的.exe,它将按预期工作,并且不会延迟。它似乎与IDE有关,如果您运行实际的.exe,它将按预期工作,并且不会有任何延迟。我在ATI FirePro V5700上获得相同的行为(即使在IDE之外运行版本exe)。如果您真的对此感到困扰,请更改carbon_window.c的第764行、win32_window.c的第1210行和x11_window.c的第962行 .\lib\carbon\carbon\u window.c
(void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) );
.\lib\win32\win32\u 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\u window.c
_glfwPlatformSetWindowTitle( "GLFW Window" );
我在ATI FirePro V5700上也有同样的行为(甚至在IDE之外运行release exe)。如果您真的对此感到困扰,请更改carbon_window.c的第764行、win32_window.c的第1210行和x11_window.c的第962行
.\lib\carbon\carbon\u window.c
(void)SetWindowTitleWithCFString( _glfwWin.window, CFSTR( "GLFW Window" ) );
.\lib\win32\win32\u 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\u window.c
_glfwPlatformSetWindowTitle( "GLFW Window" );
GLFW_窗口
表示“创建一个窗口`而不是GLFW_全屏
。它实际上并没有设置窗口标题本身。else块不会创建新窗口,它只是设置当前窗口的窗口标题。谢谢,我应该更加小心。是的,Victor是正确的,但我无法理解延迟可能是因为我使用的是microsoft visual studio 2012 express?GLFW_window
means“创建一个窗口`而不是GLFW_全屏
。它实际上并没有设置窗口标题本身。另一个块不创建新窗口,它只是设置当前窗口的窗口标题。谢谢,我应该更小心。是的,维克托是正确的,但是我不能理解延迟是因为我使用微软Visual Studio 2012 Express?同样的事情,没有忘记,我提到MV C++ C++ Studio 2012 Express,也许这与此有关?看起来您正在遵循此教程:。我自己也学过这个教程,但是在Linux上,从来没有遇到过像您描述的任何问题。这很可能不是代码的问题,但可能是e的问题