Newbie Q: Is it possible to draw functional "Cocoa Controls" in an OpenGL context?
-
Hello,
I've been trying to figure this out for a while but am having a
little trouble, being new to Cocoa, and OO programming in general.
Here goes: Is it possible to draw Interface Builder controls such as
buttons, sliders, etc. in an OpenGL view? I've figured out how to
capture bitmap representations of controls and render those in OpenGL
space. What I'd like to do is create 2D representations of these
controls in a 3D OpenGL context, while retaining the ability to
respond to user inputs using the interface elements built in event
handling, action, and output functionality . From my reading so far
OpenGL seems like a suitable candidate for the 3D rendering
environment. However I can't figure out if there is built-in Cocoa
functionality to accomplish this, or, if I'd have to build it myself.
Thanks for any suggestions you may be able to offer.
Matt
This e-mail and any attachments may contain
confidential and privileged information. If you are
not the intended recipient, please notify the sender
immediately by return e-mail, delete this e-mail
and destroy any copies. Any dissemination or use
of this information by a person other than the
intended recipient is unauthorized and may be
illegal. Unless otherwise stated, opinions expressed
in this e-mail are those of the author and are not
endorsed by the author's employer.
--
Le présent message, ainsi que tout fichier qui y est
joint, est envoyé à l'intention exclusive de son ou
de ses destinataires; il est de nature confidentielle
et peut constituer une information privilégiée. Nous
avertissons toute personne autre que le
destinataire prévu que tout examen,
réacheminement, impression, copie, distribution ou
autre utilisation de ce message et de tout fichier
qui y est joint est strictement interdit.
Si vous n'êtes pas le destinataire prévu, veuillez en
aviser immédiatement l'expéditeur par retour de
courriel et supprimer ce message et tout document
joint de votre système. Sauf indication contraire,
les opinions exprimées dans le présent message
sont celles de l’auteur et ne sont pas avalisées par
l’employeur de l’auteur. -
Matt,
NSOpenGLView doesn't allow subviews but you could certainly put an
NSView on top of your OpenGL view and put buttons in there. You
could subclass that view to pass mouse clicks that weren't handled by
buttons in the top view down to the OpenGL view.
================================================
Daniel E Steward
Owner, lead developer
DoodleBytes LLC
http://www.doodlebytes.com
<consulting...>
================================================
On Feb 14, 2007, at Wednesday2:33 PM, Matt Trinneer wrote:
> Hello,
>
> I've been trying to figure this out for a while but am having a
> little trouble, being new to Cocoa, and OO programming in general.
> Here goes: Is it possible to draw Interface Builder controls such
> as buttons, sliders, etc. in an OpenGL view? I've figured out how
> to capture bitmap representations of controls and render those in
> OpenGL space. What I'd like to do is create 2D representations of
> these controls in a 3D OpenGL context, while retaining the ability
> to respond to user inputs using the interface elements built in
> event handling, action, and output functionality . From my reading
> so far OpenGL seems like a suitable candidate for the 3D rendering
> environment. However I can't figure out if there is built-in Cocoa
> functionality to accomplish this, or, if I'd have to build it myself.
>
> Thanks for any suggestions you may be able to offer.
>
> Matt
> This e-mail and any attachments may contain
> confidential and privileged information. If you are
> not the intended recipient, please notify the sender
> immediately by return e-mail, delete this e-mail
> and destroy any copies. Any dissemination or use
> of this information by a person other than the
> intended recipient is unauthorized and may be
> illegal. Unless otherwise stated, opinions expressed
> in this e-mail are those of the author and are not
> endorsed by the author's employer.
> --
>
> Le présent message, ainsi que tout fichier qui y estjoint, est
> envoyé à l'intention exclusive de son oude ses destinataires; il
> est de nature confidentielleet peut constituer une information
> privilégiée. Nousavertissons toute personne autre que
> ledestinataire prévu que tout examen,réacheminement, impression,
> copie, distribution ouautre utilisation de ce message et de tout
> fichierqui y est joint est strictement interdit.
> Si vous n'êtes pas le destinataire prévu, veuillez enaviser
> immédiatement l'expéditeur par retour decourriel et supprimer ce
> message et tout documentjoint de votre système. Sauf indication
> contraire,les opinions exprimées dans le présent messagesont celles
> de l’auteur et ne sont pas avalisées parl’employeur de l’auteur.
-
On Feb 14, 2007, at 5:52 PM, Daniel Steward wrote:
> NSOpenGLView doesn't allow subviews but you could certainly put an
> NSView on top of your OpenGL view and put buttons in there. You
> could subclass that view to pass mouse clicks that weren't handled
> by buttons in the top view down to the OpenGL view.
We recommend against overlaying views like this in the documentation.
Right now the best solution is using an invisible floating window
with the controls that overlaps the OpenGL window. I think there is
an example of this on developer.apple.com -
OK - now I'm curious. Not having used NSOpenGLView myself I'm just
throwing things out. How would it work to build a composite subclass
of NSView which includes an NSOpenGLView as a subview along with
buttons above it. Creating a separate window seems like a hard way
to do this because it seems like you would have to write some sort of
glue (literally) code to tie the two together spatially.
I suppose the other question is why can't other things draw on top of
the OpenGL view? Is there something about the glContext that makes
this a problem? I could see where maybe if the glContext renders
asynchronously it could draw over buttons that were on top.
On Feb 14, 2007, at Wednesday4:00 PM, Scott Anguish wrote:
>
> On Feb 14, 2007, at 5:52 PM, Daniel Steward wrote:
>
>> NSOpenGLView doesn't allow subviews but you could certainly put an
>> NSView on top of your OpenGL view and put buttons in there. You
>> could subclass that view to pass mouse clicks that weren't handled
>> by buttons in the top view down to the OpenGL view.
>
>
> We recommend against overlaying views like this in the documentation.
>
> Right now the best solution is using an invisible floating window
> with the controls that overlaps the OpenGL window. I think there
> is an example of this on developer.apple.com
>
>
-
On 14 Feb 2007, at 23:21, Daniel Steward wrote:
> OK - now I'm curious. Not having used NSOpenGLView myself I'm just
> throwing things out. How would it work to build a composite
> subclass of NSView which includes an NSOpenGLView as a subview
> along with buttons above it.
Like Scott said, you can't do that at the moment; you aren't supposed
to overlap views (and you'd very likely have trouble anyway with an
NSOpenGLView because it's a hardware accelerated surface), and you
can't have subviews of NSOpenGLView.
> Creating a separate window seems like a hard way to do this
> because it seems like you would have to write some sort of glue
> (literally) code to tie the two together spatially.
I don't think you need any code for that :-)
Take a look at NSWindow's -addChildWindow:ordered:.
> I suppose the other question is why can't other things draw on top
> of the OpenGL view? Is there something about the glContext that
> makes this a problem?
Yes, it's hardware accelerated. The memory backing it may be
organised differently than normal, and it will be updated by the 3D
engine on the video card as and when necessary.
Kind regards,
Alastair
--
http://alastairs-place.net -
On 2007-02-14 16:33, Matt Trinneer said:
> I've been trying to figure this out for a while but am having a
> little trouble, being new to Cocoa, and OO programming in general.
> Here goes: Is it possible to draw Interface Builder controls such as
> buttons, sliders, etc. in an OpenGL view? I've figured out how to
> capture bitmap representations of controls and render those in OpenGL
> space. What I'd like to do is create 2D representations of these
> controls in a 3D OpenGL context, while retaining the ability to
> respond to user inputs using the interface elements built in event
> handling, action, and output functionality . From my reading so far
> OpenGL seems like a suitable candidate for the 3D rendering
> environment. However I can't figure out if there is built-in Cocoa
> functionality to accomplish this, or, if I'd have to build it myself.
I have investigated this recently. As others have said, overlapping
views are in general not advised. You'll want to look at the
"UnderlaySurface" example. It is installed with Xcode here:
/Developer/Examples/OpenGL/Cocoa/UnderlaySurface/
Note that the example, pathetically, does not even work. The problem is
that NSPrincipleClass in UnderlaySurface-Info.plist should be "App" not
"NSApplication"- an easy fix at least.
Also the example code calls:
[[self window] setAlphaValue:.999f]
in viewDidMoveToWindow. This seems to be completely unnecessary.
Lastly, I suggest you search the list archives (all lists) for these key
words "underlay opengl cocoa".
> Thanks for any suggestions you may be able to offer.
Your signature is _longer_ than your message, I suggest you shorten it. :)
--
____________________________________________________________
Sean McBride, B. Eng <sean...>
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada



