Reputation: 3269
This is my source code from a series of tutorials I'm taking a look regarding 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;
}
Everything works great except that when the window initializes it has a background color of white and the title 'GLFW WINDOW' and but after 1-2 secs the title changes to Tutorial 01 as it should have been in the first place and the background becomes black, as it should have been also.
In previous studies of opengl (2.x) with glut that I did a couple of years back I didnt have issues like that could someone explain what is wrong here?
Upvotes: 0
Views: 8604
Reputation: 4412
I get the same behaviour (even running a release exe outside of the IDE) on an ATI FirePro V5700. If you're really bothered by it, download the GLFW source and change line 764 of carbon_window.c, line 1210 of win32_window.c, and line 962 of x11_window.c.
.\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" );
Upvotes: 2
Reputation: 3269
Well as it seems it has to do with the IDE, if you run the actual .exe it works as intended and with no delay at all.
Upvotes: 0
Reputation: 3180
I'm not experiencing any problems that you describe. I copied and pasted, compiled, then ran your code as you posted it (commenting out references to GLM as I don't have that library installed). The title changes instantaneously for me -- I never even see the window having the title "GLFW WINDOW", and the color of the graphics area is immediately black. Could it be that your computer simply isn't very fast?
What happens if you do the following?
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 ) );
Edit: My GPU is an Nvidia GTX 580 (capable of at least OpenGL 4.3).
Upvotes: 1
Reputation: 510
The background color of the window is configured by the call to the openGL function glClearColor() and refreshed with the glClear() function.
The delay in the changing of the title of the window may perhaps have something to do with the fact that to create a openGL 3.x it is required to create a standard OpenGL context (version 1.x or 2.x) and then get your application to opt-in to using an OpenGL 3.x context. A 1-2 sec delay though seems a lot.
Upvotes: 0