Re: OpenGL + NSTextView/NSTextContainer?

  • On Tue, 18 Nov 2008 12:26:04 -0800 (PST) Erik Buck wrote:

    > Open GL has no built-in capability for drawing text.  Open GL
    > provides lower level primitives like lines and curves and
    > meshes.  Open GL also provides texture compositing.
    >
    > There are some free and some open text drawing/font solutions
    > for Open GL.  You can use the GLUT library up to a point.
    >
    > On Mac OS X, the traditional way to mix Open GL and Cocoa
    > text is by rentering the text into a texture and then using
    > Open GL to composite the texture.
    >
    > The sample I think you want is
    > http://developer.apple.com/samplecode/CocoaGL/index.html
    >
    > See other samples at
    > http://developer.apple.com/samplecode/GraphicsImaging/idxOpenG
    > L-date.html
    >
    > For modern Mac OS X, you might do what you want with "layer
    > backed views" to use a Cocoa text view as an Open GL texture.
    > See also CATextLayer
    > http://developer.apple.com/samplecode/CALayerEssentials/index.html

    Hmmm... none of these are quite 100% what I'm looking for; I want the
    power of an NSTextView, but where it is mapped as a texture onto an
    OpenGL surface.  I suspect that that will take a LOT of work.  The
    ultra-hackish way I can think of is to have an invisible NSTextView, and
    a visible OpenGL capable view (like CAOpenGLLayer).  The text view is
    mapped into something (don't know what yet) that can be turned into a
    texture that is rendered on the surface of the OpenGL object, and I do
    hit testing on the OpenGL object to pass back where the mouse is to the
    invisible NSTextView.  By doing this, I hope to use NSTextView's power
    to do all the heavy lifting for text, but display it on an OpenGL
    surface.  Except for the fact that I'd need to be very careful to ensure
    that the OpenGL surface doesn't deform the rendered output from the
    NSTextView too much, does this sound like a reasonable approach.  Note
    that I'm NOT trying to make a released product here, just get a feel for
    an interface.

    Thanks,
    Cem Karan
  • Le 19 nov. 08 à 13:39, Karan, Cem (Civ, ARL/CISD) a écrit :

    > On Tue, 18 Nov 2008 12:26:04 -0800 (PST) Erik Buck wrote:
    >
    >> Open GL has no built-in capability for drawing text.  Open GL
    >> provides lower level primitives like lines and curves and
    >> meshes.  Open GL also provides texture compositing.
    >>
    >> There are some free and some open text drawing/font solutions
    >> for Open GL.  You can use the GLUT library up to a point.
    >>
    >> On Mac OS X, the traditional way to mix Open GL and Cocoa
    >> text is by rentering the text into a texture and then using
    >> Open GL to composite the texture.
    >>
    >> The sample I think you want is
    >> http://developer.apple.com/samplecode/CocoaGL/index.html
    >>
    >> See other samples at
    >> http://developer.apple.com/samplecode/GraphicsImaging/idxOpenG
    >> L-date.html
    >>
    >> For modern Mac OS X, you might do what you want with "layer
    >> backed views" to use a Cocoa text view as an Open GL texture.
    >> See also CATextLayer
    >> http://developer.apple.com/samplecode/CALayerEssentials/index.html
    >
    > Hmmm... none of these are quite 100% what I'm looking for; I want the
    > power of an NSTextView, but where it is mapped as a texture onto an
    > OpenGL surface.  I suspect that that will take a LOT of work.  The
    > ultra-hackish way I can think of is to have an invisible NSTextView,
    > and
    > a visible OpenGL capable view (like CAOpenGLLayer).  The text view is
    > mapped into something (don't know what yet) that can be turned into a
    > texture that is rendered on the surface of the OpenGL object, and I do
    > hit testing on the OpenGL object to pass back where the mouse is to
    > the
    > invisible NSTextView.  By doing this, I hope to use NSTextView's power
    > to do all the heavy lifting for text, but display it on an OpenGL
    > surface.  Except for the fact that I'd need to be very careful to
    > ensure
    > that the OpenGL surface doesn't deform the rendered output from the
    > NSTextView too much, does this sound like a reasonable approach.  Note
    > that I'm NOT trying to make a released product here, just get a feel
    > for
    > an interface.

    Do you need text editing capability, or just text drawing ?

    If this is text drawing, I don't see what NSTextView provide that is
    not possible with NSAttributedString, and so, with the GLString class
    that convert an attributed string into a texture (and that is include
    in the sample pointed in the previous post).

    Else, it's perfectly possible to use an NSTextView as an NSOpenGLView
    subview (it require some tricks, but it works).
  • On Wednesday, November 19, 2008 9:04 AM Jean-Daniel Dupas wrote:

    > Do you need text editing capability, or just text drawing ?
    >
    > If this is text drawing, I don't see what NSTextView provide
    > that is not possible with NSAttributedString, and so, with
    > the GLString class that convert an attributed string into a
    > texture (and that is include in the sample pointed in the
    > previous post).
    >
    > Else, it's perfectly possible to use an NSTextView as an
    > NSOpenGLView subview (it require some tricks, but it works).

    I'd like full text editing if at all possible.  Can you explain what you are suggesting about the subviews some more?  My only experiences with making views subviews of other views has lead me to believe that although they can be rotated and translated in 2D, they cannot be rotated or translated in 3D.  Am I wrong?  Is there some way of doing that?

    Thanks,
    Cem Karan
  • Le 19 nov. 08 à 17:16, Karan, Cem (Civ, ARL/CISD) a écrit :

    > On Wednesday, November 19, 2008 9:04 AM Jean-Daniel Dupas wrote:
    >
    >> Do you need text editing capability, or just text drawing ?
    >>
    >> If this is text drawing, I don't see what NSTextView provide
    >> that is not possible with NSAttributedString, and so, with
    >> the GLString class that convert an attributed string into a
    >> texture (and that is include in the sample pointed in the
    >> previous post).
    >>
    >> Else, it's perfectly possible to use an NSTextView as an
    >> NSOpenGLView subview (it require some tricks, but it works).
    >
    > I'd like full text editing if at all possible.  Can you explain what
    > you are suggesting about the subviews some more?  My only
    > experiences with making views subviews of other views has lead me to
    > believe that although they can be rotated and translated in 2D, they
    > cannot be rotated or translated in 3D.  Am I wrong?  Is there some
    > way of doing that?

    Sorry, I miss the 3D requirement. Full text editing on a view that
    evolve in a 3D space. I really don't have more idea about how to do
    this.