Main Page | Report this Page
 
   
Computers Forum Index  »  Computer - Graphics - API (Opengl)  »  GLUT & QT Together
Page 1 of 1    
Author Message
Adam Hartshorne
Posted: Sun Apr 24, 2005 5:02 pm
Guest
Hi All,

I have been given a 3D application written in c++ using OpenGL and
wrapped with GLUT. I need to add some controls for a set of variables
and thought the best way would be to create a nice GUI using QT. I know
QT can create a window that can display OpenGL based things, but if I
can help it I want to keep the application I have been given unchanged.

Therefore my question is, is it possible to create an application that
contains both QT and GLUT created and controlled windows? Anf if so how,
because both at the end of the main method pass control over to their
respective controllers.

Adam
Wolfgang Draxinger
Posted: Sun Apr 24, 2005 5:02 pm
Guest
Adam Hartshorne wrote:

Quote:
Therefore my question is, is it possible to create an
application that contains both QT and GLUT created and
controlled windows? Anf if so how, because both at the end of
the main method pass control over to their respective
controllers.

You could write a wrapper around Qt that looks like GLUT to the
outside. GLUT by itself has only a very limited function set, so
this should be a easy job.

Wolfgang Draxinger
--
Adam Hartshorne
Posted: Sun Apr 24, 2005 5:02 pm
Guest
Wolfgang Draxinger wrote:

Quote:
Adam Hartshorne wrote:


Therefore my question is, is it possible to create an
application that contains both QT and GLUT created and
controlled windows? Anf if so how, because both at the end of
the main method pass control over to their respective
controllers.


You could write a wrapper around Qt that looks like GLUT to the
outside. GLUT by itself has only a very limited function set, so
this should be a easy job.

Wolfgang Draxinger

Well I actually want to know if I can get anyway with doing no
alterations! Because if writing wrappers etc is the only way, I will
just pull apart the program and port it to QT, GLUT isn't doing that
much at the moment. But at the moment I have a window that works as
requires with the OpenGL by somebody else, and as they say if it aint
broke don't fix it! And now I want another 'window' with a control panel
for some settings!

Adam
Wolfgang Draxinger
Posted: Sun Apr 24, 2005 9:02 pm
Guest
Rolf Magnus wrote:

Quote:
Do you need to use Qt for it? Mixing GLUT and Qt is
problematic, because you'd have to somehow merge the event
loops. Btw: There are libraries that implement their own GUI
within OpenGL, e.g. glui. See http://glui.sourceforge.net/

Or have a look at FLTK. Obviously it can't compete with Qt, but
it's great if you need to hack a GUI for an GLUT application,
since FLTK already has a GLUT compatibility layer.

http://www.fltk.org

Wolfgang Draxinger
--
Rolf Magnus
Posted: Sun Apr 24, 2005 9:02 pm
Guest
Adam Hartshorne wrote:

Quote:
Wolfgang Draxinger wrote:

Adam Hartshorne wrote:


Therefore my question is, is it possible to create an
application that contains both QT and GLUT created and
controlled windows? Anf if so how, because both at the end of
the main method pass control over to their respective
controllers.


You could write a wrapper around Qt that looks like GLUT to the
outside. GLUT by itself has only a very limited function set, so
this should be a easy job.

Wolfgang Draxinger

Well I actually want to know if I can get anyway with doing no
alterations!

That should work if you do what Wolfgang wrote. You just write your own
version of the GLUT functions that emulate their regular behavior using
QGL. That should be possible without altering any of the existing code.

Quote:
Because if writing wrappers etc is the only way, I will
just pull apart the program and port it to QT, GLUT isn't doing that
much at the moment.

GLUT isn't capable of doing much ;-)

Quote:
But at the moment I have a window that works as requires with the OpenGL
by somebody else, and as they say if it aint broke don't fix it! And now I
want another 'window' with a control panel for some settings!

Do you need to use Qt for it? Mixing GLUT and Qt is problematic, because
you'd have to somehow merge the event loops.
Btw: There are libraries that implement their own GUI within OpenGL, e.g.
glui. See http://glui.sourceforge.net/
Wolfgang Draxinger
Posted: Sun Apr 24, 2005 11:02 pm
Guest
Adam Hartshorne wrote:

Quote:
As for writing a wrapper I wouldn't even know where to start to
be honest, hence asking the question with the hope there was
something like that already out there.

What's the problem? You just have to implement the functions
glutInit(), glutInitDisplayMode(), glutCreateWindow etc. (about
20 in count). Each of them could then do a
QtGLUT::pCurrentWindow -> $FUNCTION where QtGLUT is the windows
class, QtGLUT::pCurrentWindow is a static member of the type
QtGLUT* that holds the pointer to the currently active Window.
Also maintain a static member std::map<int, QtGLUT*>
QtGLUT::pWindows so that you cann enumerate them.

I'd estimate the needed time to do this about 3 hours work.

Wolfgang Draxinger
--
Adam Hartshorne
Posted: Sun Apr 24, 2005 11:02 pm
Guest
Wolfgang Draxinger wrote:

Quote:
Rolf Magnus wrote:


Do you need to use Qt for it? Mixing GLUT and Qt is
problematic, because you'd have to somehow merge the event
loops. Btw: There are libraries that implement their own GUI
within OpenGL, e.g. glui. See http://glui.sourceforge.net/


Or have a look at FLTK. Obviously it can't compete with Qt, but
it's great if you need to hack a GUI for an GLUT application,
since FLTK already has a GLUT compatibility layer.

http://www.fltk.org

Wolfgang Draxinger
I really actually want QT, as I have a full copy of the library and

seems incredibly powerful yet simple, which is ideal for what i need.

As for writing a wrapper I wouldn't even know where to start to be
honest, hence asking the question with the hope there was something like
that already out there.

Adam
Adam Hartshorne
Posted: Mon Apr 25, 2005 1:02 am
Guest
Mikkel Gjøl wrote:

Quote:
Adam Hartshorne wrote:

I have been given a 3D application written in c++ using OpenGL and
wrapped with GLUT. I need to add some controls for a set of variables

snip

...are you sure GLUI is not what you're looking for?

http://www.cs.unc.edu/~rademach/glui/
http://sourceforge.net/projects/glui/


I've tried a GLUT/QT combo - also one using SDL/QT. I did finally
succeed, but I wouldn't recommend it due to the amount of "wierd"-bugs I
experienced.


Kind regards,
\\Mikkel Gjoel

That looks interesting! However, as far as I know QT is the
professionals choice of GUI builder and I have a very good book
explaining how to do all the things I want, hence I was hoping very
little extra learning would be required.

Adam
Adam Hartshorne
Posted: Mon Apr 25, 2005 1:02 am
Guest
Wolfgang Draxinger wrote:

Quote:
Adam Hartshorne wrote:


As for writing a wrapper I wouldn't even know where to start to
be honest, hence asking the question with the hope there was
something like that already out there.


What's the problem? You just have to implement the functions
glutInit(), glutInitDisplayMode(), glutCreateWindow etc. (about
20 in count). Each of them could then do a
QtGLUT::pCurrentWindow -> $FUNCTION where QtGLUT is the windows
class, QtGLUT::pCurrentWindow is a static member of the type
QtGLUT* that holds the pointer to the currently active Window.
Also maintain a static member std::map<int, QtGLUT*
QtGLUT::pWindows so that you cann enumerate them.

I'd estimate the needed time to do this about 3 hours work.

Wolfgang Draxinger
I don't see how you deal with the control issue, both GLUT and QT must

end with a call to pass control over to the appropriate handlers to deal
with mouse click etc

Adam
Mikkel Gjøl
Posted: Mon Apr 25, 2005 1:02 am
Guest
Adam Hartshorne wrote:
Quote:
I have been given a 3D application written in c++ using OpenGL and
wrapped with GLUT. I need to add some controls for a set of variables
snip


....are you sure GLUI is not what you're looking for?

http://www.cs.unc.edu/~rademach/glui/
http://sourceforge.net/projects/glui/


I've tried a GLUT/QT combo - also one using SDL/QT. I did finally
succeed, but I wouldn't recommend it due to the amount of "wierd"-bugs I
experienced.


Kind regards,
\\Mikkel Gjoel
Adam Hartshorne
Posted: Mon Apr 25, 2005 1:02 am
Guest
Mikkel Gjøl wrote:

Quote:
Adam Hartshorne wrote:

I have been given a 3D application written in c++ using OpenGL and
wrapped with GLUT. I need to add some controls for a set of variables

snip

...are you sure GLUI is not what you're looking for?

http://www.cs.unc.edu/~rademach/glui/
http://sourceforge.net/projects/glui/


I've tried a GLUT/QT combo - also one using SDL/QT. I did finally
succeed, but I wouldn't recommend it due to the amount of "wierd"-bugs I
experienced.


Kind regards,
\\Mikkel Gjoel

A further point is that GLUT appears to be no longer in development,
where as QT is most definitely been developed at a good rate. The things
I am working on will stretch and build up over a period of 4 years,
hence I definitely don't want to find problems in a couple of years time
with compatibility etc.

Adam
Wolfgang Draxinger
Posted: Mon Apr 25, 2005 9:02 am
Guest
Adam Hartshorne wrote:

Quote:
I don't see how you deal with the control issue, both GLUT and
QT must end with a call to pass control over to the appropriate
handlers to deal with mouse click etc

That's easy when doing it with a wrapper.All you have to do is
implementing the right slots in the QtGLUT wrapper class. Those
slots then in turn call the function pointers, that have been
set using glutDisplayFunc etc.

Shall I write it for you?

Wolfgang Draxinger
--
Adam Hartshorne
Posted: Mon Apr 25, 2005 11:02 am
Guest
Rolf Magnus wrote:
Quote:
Adam Hartshorne wrote:


I don't see how you deal with the control issue, both GLUT and QT must
end with a call to pass control over to the appropriate handlers to deal
with mouse click etc


I think you still didn't get it. You don't use GLUT at all. You just write
an emulation of all GLUT functions that the program needs on top of Qt. You
write your own glutMainLoop() function that calls qapp->exec(). The
glutInit() function would create the QApplication object.

Basically, you derive from QGLWidget. It has all the functions you need,
like e.g.:

virtual void resizeGL ( int width, int height )

that is called whenever the window needs to be resized

virtual void paintGL ()

whenever you need to repaint the window contents.

virtual void keyPressEvent ( QKeyEvent * e )
virtual void keyReleseEvent ( QKeyEvent * e )

whenever the user presses or releases a key.
You simply override those functions and within them, you call the callbacks
that were set with glutReshapeFunc(), glutDisplayFunc() and
glutKeyboardFunc(). You write those three glut functions yourself, and any
other that the program needs, in conjunction with overriding the
corresponding QGLWidget member functions.

That should all be quite simple. However, I still think it would even be
simpler to replace the GLUT stuff completely with a QGLWidget derived
class.

I get it now! Have already replaced GLUT with QT and QTGlib!

Adam
Rolf Magnus
Posted: Mon Apr 25, 2005 11:02 am
Guest
Adam Hartshorne wrote:

Quote:
I don't see how you deal with the control issue, both GLUT and QT must
end with a call to pass control over to the appropriate handlers to deal
with mouse click etc

I think you still didn't get it. You don't use GLUT at all. You just write
an emulation of all GLUT functions that the program needs on top of Qt. You
write your own glutMainLoop() function that calls qapp->exec(). The
glutInit() function would create the QApplication object.

Basically, you derive from QGLWidget. It has all the functions you need,
like e.g.:

virtual void resizeGL ( int width, int height )

that is called whenever the window needs to be resized

virtual void paintGL ()

whenever you need to repaint the window contents.

virtual void keyPressEvent ( QKeyEvent * e )
virtual void keyReleseEvent ( QKeyEvent * e )

whenever the user presses or releases a key.
You simply override those functions and within them, you call the callbacks
that were set with glutReshapeFunc(), glutDisplayFunc() and
glutKeyboardFunc(). You write those three glut functions yourself, and any
other that the program needs, in conjunction with overriding the
corresponding QGLWidget member functions.

That should all be quite simple. However, I still think it would even be
simpler to replace the GLUT stuff completely with a QGLWidget derived
class.
Mikkel Gjøl
Posted: Mon Apr 25, 2005 3:02 pm
Guest
Adam Hartshorne wrote:
Quote:
A further point is that GLUT appears to be no longer in development

- "freeglut" is though (SDL too in case you wanted to check out all the
options).

Is it a requirement that the application is compatible cross-platform?
If not, you might want to consider platform-specific choices.


Quote:
However, as far as I know QT is the professionals choice of GUI
builder

Where did you read that? On trolltech's homepage? :D


Quote:
and I have a very good book explaining how to do all the things I
want

Ah, that settles it then :)



Kind Regards,
\\Mikkel Gjoel
 
Page 1 of 1       All times are GMT
The time now is Tue Jan 06, 2009 12:46 pm