GLUT - How to know when a window has been closed by a user?

Started by
3 comments, last by nprz 18 years, 11 months ago
I am using GLUT right now, and I can't switch just yet (but If I can't figure this out, I will have to switch). Is there a way to know if a user has clicked on the "X" on the window? If I don't receive a callback about this, when I try to draw to that window and find out it doesn't exist, I end up drawing on the current window (which is not good).
Advertisement
That's odd. Using the simple example in this series:

#include "glut.h"#include<gl/gl.h>void renderScene(void) {	glClear(GL_COLOR_BUFFER_BIT);	glBegin(GL_TRIANGLES);		glVertex3f(-0.5,-0.5,0.0);		glVertex3f(0.5,0.0,0.0);		glVertex3f(0.0,0.5,0.0);	glEnd();	glFlush();}void main(int argc, char **argv) {	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);	glutInitWindowPosition(100,100);	glutInitWindowSize(320,320);	glutCreateWindow("3D Tech- GLUT Tutorial");	glutDisplayFunc(renderScene);	glutMainLoop();}


The window closes when the X is pressed on the console and main program. What exactly are you doing? If you are interesed in having a callback function for the closure, you can take a look at this page for a modified version as well.
Quote:Original post by Drew_Benton
That's odd. Using the simple example in this series:

*** Source Snippet Removed ***

The window closes when the X is pressed on the console and main program. What exactly are you doing? If you are interesed in having a callback function for the closure, you can take a look at this page for a modified version as well.


Well, I removed the console part, so it is impossible to click the "X" on that.
Registering callbacks for when a window is closed would be great because I need them to "Leave" when they close the window. Otherwise the server will still think they are in the room and won't let them do anything else.

I can't rate you up anymore Drew, that needs to be fixed, need a +10,+20 on the ratings for you.
No problem! Does that version of that code on the second link work for what you need to do? (I mean did I understand what you are asking about correctly?) I downloaded the file to verify the link but have not tried it myself yet. I'll take a look at that.

I used to have another version of GLUT that I will see if I can find that added a few of needed updates to the library, such as wheel mouse support and a few other thing I think. Here's that version if anyone needs it, threads always pop up asking that [wink].

Ok tested out that other verison, and wow! Multiple windows! Not to mention that knowing of when the window is closing. I might have to mess around with this for a bit [smile] Anyone using glut should definity check out that different version of GLUT!
Quote:Original post by Drew_Benton
No problem! Does that version of that code on the second link work for what you need to do? (I mean did I understand what you are asking about correctly?) I downloaded the file to verify the link but have not tried it myself yet. I'll take a look at that.

I used to have another version of GLUT that I will see if I can find that added a few of needed updates to the library, such as wheel mouse support and a few other thing I think. Here's that version if anyone needs it, threads always pop up asking that [wink].

Ok tested out that other verison, and wow! Multiple windows! Not to mention that knowing of when the window is closing. I might have to mess around with this for a bit [smile] Anyone using glut should definity check out that different version of GLUT!


Multiple monitors would be neat to check out, but I don't have that so I'm not in a hurry. Regular glut has multiple window ability.

You did understand what my problem was and adding the window callback feature with that link you posted fixed it. It was something I had wanted for a while now and glad that people are still supporting this toolkit.

This topic is closed to new replies.

Advertisement