Okay, I made a simple test to show you the problem :
In main.py :
print "Closed 1"
print "Closed 2"
In example.py :
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
# General OpenGL initialization function which sets all of the initial parameters. (called right after window creation)
def InitGL(width, height):
glClearColor(0.0, 0.0, 0.0, 0.0)
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
# The main drawing function.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear The Screen And The Depth Buffer
glColor3f(1.0, 1.0, 1.0)
glVertex3f(0.25, 0.25, 0.0)
glVertex3f(0.75, 0.25, 0.0)
glVertex3f(0.75, 0.75, 0.0)
glVertex3f(0.25, 0.75, 0.0)
# Double buffered, you need to swap the buffers to display what just got drawn.
print "Window closed"
# Don't know what to put in here ?
# Main function
# OpenGL display
# When closing the window, we quit the mainloop# Select type of display mode: RGBA color, double buffer, depth buffer.
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
# Get a window (sizes in pixels)
# Position of the window on the screen ((0,0) = upper left) at start.
# Creates the window. We retain the window id to use when closing.
window = glutCreateWindow("openGL")
# Draw the scene by calling "DrawGLScene" defined above.
# Close callback
# Initialize our window.
# Start Event Processing Engine
So the first call to main() works, the window opens. If I close the window (with the X), I get the following message :
Closed 1So the callback to the close function works, but I don't know what to write in there. And glutInit should be called ... but it's not. Why ?
freeglut ERROR: Function <glutSetOption> called without first calling 'glutInit'.
Thank you in advance
Michka2011/3/22 John Fay <email@example.com>
I've checked the "freeglut" source code and have found that it does
indeed deinitialize. In "freeglut_main.c" on line 1565, the function
"glutMainLoop" calls "fgDeinitialize" before returning control to the
calling program. You will need to call "glutInit" again before doing
anything else with "freeglut".
On 3/21/2011 12:28 PM, Fay, John F Dr CTR USAF AFMC AAC/XRS wrote:
> Hello and welcome to the "freeglut" community. I wish you a
> good and productive time here.
> I'm a little confused about the order in which you do things.
> You should need to call "glutSetOption" only once, before you open the
> window for the first time. Calling it again shouldn't hurt, but it
> shouldn't be necessary. That the library gives you the error is a bit
> You'll have to check the source code to make sure, but it is
> possible that when you close the "freeglut" window the library
> de-initializes itself. If that happens, you'll have to call "glutInit"
> again. The documentation on GLUT says that "glutInit" should only be
> called once, but it didn't consider execution continuing when the last
> window was closed.
> John F. Fay
> Technical Fellow, Modeling and Simulation
> Jacobs Technology / TEAS Group
> P.O. Box 1935, Eglin AFB, FL 32542-5000
> -----Original Message-----
> From: Michka Popoff [mailto:firstname.lastname@example.org]
> Sent: Monday, March 21, 2011 11:58 AM
> To: email@example.com
> Subject: [Freeglut-developer] glutCloseFunc and glutmainloop
> I need some help for implementing a Freeglut Window in my application.
> My application is written in Python, with a GUI built with GTK, under
> Ubuntu 10.10. (The application also works on Mac OS X)
> I have a button which launches an OpenGL window, drawn with GLUT
> (freeglut 2.6.0). If I close the window, I don't want the main program
> to quit.
> So I followed the different advises I found on the internet :
> I used :
> This worked, the window closes and the main program doesn't exit. But if
> I click a second time on the button (to reopen a new window), I get this
> error :
> freeglut ERROR: Function<glutSetOption> called without first calling
> And the program exits.
> I added the glutCloseFunc callback, but I don't know what to add in the
> callback to close down the freeglut Window properly. Everybody says you
> should use this callback, but nobody explains how to use it. I tried to
> put a glutDestroyWindow or a glutLeaveMainLoop in it but this didn't
> worked either ...
> I think I don't properly close the Freeglut Window, and this is the
> cause of the errors when I try to open a new one. (glutInit should be
> only called one, or not ?)
> So perhaps somebody could help me out with a working tutorial or some
> more advises ?
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> Freeglut-developer mailing list
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
Freeglut-developer mailing list