Hello

sorry to ask my question a second time, but I really need to know if it is possible to do what I explained here. If not, I'll need to find another way to do it, perhaps with GTK.

Or perhaps should I post my question on a more "python-oriented" mailinglist/forum ?

Thanks in advance

Michka

2011/3/22 Michka Popoff <michkapopoff@gmail.com>
Okay, I made a simple test to show you the problem :

In main.py :

import example

example.main()
print "Closed 1"
example.main()

print "Closed 2"


In example.py :

import sys
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.
def DrawGLScene():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)    # Clear The Screen And The Depth Buffer
    glLoadIdentity()
   
    glColor3f(1.0, 1.0, 1.0)
    glBegin(GL_POLYGON)
    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)
    glEnd()
   
    # Double buffered, you need to swap the buffers to display what just got drawn.
    glutSwapBuffers()
   
def close():
    print "Window closed"
    # Don't know what to put in here ?
   
# Main function
def main():
    # OpenGL display
    glutInit(sys.argv)
   
    # When closing the window, we quit the mainloop

    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)
   
    # Select type of display mode: RGBA color, double buffer, depth buffer.
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
   
    # Get a window (sizes in pixels)
    glutInitWindowSize(800,600)
   
    # Position of the window on the screen ((0,0) = upper left) at start.
    glutInitWindowPosition(0,0)
   
    # Creates the window. We retain the window id to use when closing.
    window = glutCreateWindow("openGL")
   
    # Draw the scene by calling "DrawGLScene" defined above. 
    glutDisplayFunc(DrawGLScene)
   
    # Close callback
    glutCloseFunc(close)
   
    # Initialize our window.
    InitGL(800, 600)
   
    # Start Event Processing Engine   
    glutMainLoop()


So the first call to main() works, the window opens. If I close the window (with the X), I get the following message :

Window closed
Closed 1

freeglut  ERROR:  Function <glutSetOption> called without first calling 'glutInit'.

So 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 ?

Thank you in advance

Michka


2011/3/22 John Fay <johnffay@cybertron.com>
Michka,

    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".

        - John


On 3/21/2011 12:28 PM, Fay, John F Dr CTR USAF AFMC AAC/XRS wrote:
> Michka,
>
>       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
> confusing.
>
>       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
> 850-883-3496
>
>
> -----Original Message-----
> From: Michka Popoff [mailto:michkapopoff@gmail.com]
> Sent: Monday, March 21, 2011 11:58 AM
> To: freeglut-developer@lists.sourceforge.net
> Subject: [Freeglut-developer] glutCloseFunc and glutmainloop
>
> Hello
>
> 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 :
>
> glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
> GLUT_ACTION_GLUTMAINLOOP_RETURNS)
>
> 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
> 'glutInit'.
>
> 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 ?
>
>
> Michka
>
>
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> http://p.sf.net/sfu/internap-sfd2d
> _______________________________________________
> Freeglut-developer mailing list
> Freeglut-developer@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freeglut-developer
>
>
>

------------------------------------------------------------------------------
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
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Freeglut-developer mailing list
Freeglut-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freeglut-developer