PDA

View Full Version : TITLE problem about the application created using glut




ccjimmy
Apr 27, 2011, 10:09 PM
hi, all
When my application switched between fullscreeen/windowed, looks like the title will disappeared.
This problem occured only on MAC and it works will on Windows.

I've write a sample code below, it will works both on MAC and Windows, i don't know why the title dissappeared on MAC but works well on Windows

USING number-key "1" to switch between windows/fullscreen.

#include <stdio.h>
#include "GLUT.h"
#include <stdlib.h>
static int fullScr = 0;
static bool windowed = true;

void Update(int para)
{
glutPostRedisplay();
glutTimerFunc(17,Update,0);
}

void exitfunc(int para)
{
exit(0);
}
void key_process(unsigned char key,int x,int y)
{

if(key == '\033')
{
exit(0);
}
if(key == 49/*num key 1*/)
{
windowed = windowed?false:true;
}
if(!windowed)
{
glutFullScreen();
}
else
{
glutReshapeWindow(1024,768);
glutPositionWindow(100,100);
}
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}

int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
if(!fullScr)
{
windowed = true;
glutInitWindowSize(1024,768);
}
glutCreateWindow("Xcode Glut Demo");
glutTimerFunc(17, Update,0);
glutDisplayFunc(display);
glutKeyboardFunc(key_process);
if(fullScr)
{
windowed = false;
glutFullScreen();
}

glutMainLoop();
}



lloyddean
Apr 27, 2011, 10:52 PM
What you describe is correct behavior on Mac OS.

Actually the title is set it's just that in full-screen mode window decorations such as the title bar are not drawn.

Perhaps I misunderstand the question being asked?

ccjimmy
Apr 28, 2011, 12:56 AM
In Windows XP, when I create a windows using this code, the titile of the window shows "Xcode Glut Demo",I switch the window mode to FULLSCREEN, and then switch back to WINDOWED mode, the title always there.

but In MAC OS, I create the window and it shows the window-title "Xcode Glut Demo", then I switch to FULLSCREEN mode, after that, I switch th FULLSCREEN mode back tu WINDOWED mode, the Title disappeared....


My English is poor, I wish I could express myself clearly to you...

thanks so much!

jiminaus
Apr 28, 2011, 01:37 AM
It seems that GLUT creates a new window when you exit full-screen and you need to reset the window title. But more so, you need let Mac OS X process the window creation events before you do this otherwise there is no actual window for glutSetWindowTitle to operate on.

I was able to fix your code with this:

void reset_window_title(int para)
{
glutSetWindowTitle("XCode Glut Demo");
}

void key_process(unsigned char key,int x,int y)
{

if(key == '\033')
{
exit(0);
}
if(key == 49/*num key 1*/)
{
windowed = windowed?false:true;
if(!windowed)
{
glutFullScreen();
}
else
{
glutReshapeWindow(1024,768);
glutPositionWindow(100,100);
glutTimerFunc(0, reset_window_title, 0);
}
}
}


Using a 0 millisecond timer, the timer fires immediately. But all that does is append an event to the event queue. The important thing is that the event is appended after the window creation events.

ccjimmy
Apr 28, 2011, 02:40 AM
jiminaus
thanks
it really works!
Thank u Very much!!