More than likely, this is way too advanced for moi, but I spent about an
hour rummaging through the Lumiere code for Pharo and just couldn't grok how the OpenGL rendering is directed to a morph instead of to raw coordinates on the main window. Is there some special property of Pharo that allows this kind of thing, or is there some relatively simple way in Squeak to direct OGL drawing to a morphic surface/canvas/thingie so it renders inside the boundaries of the morph when moved? Or does my question even make sense? Thanks. Lawson |
"is there some relatively simple way in Squeak to direct OGL drawing to a morphic surface/canvas/thingie so it renders inside the boundaries of the morph when moved?"
Download OpenCobalt. Take the code below and load it into that image to create the class. Then go to CobaltWorldIntro>>initialize and add:
yum := TOglTestTriangle new.
space addChild: yum. When you go to CobaltWorldIntro (which isn't the default) you'll wander around and see a triangle. That OpenGL code is straight out of an OpenGL book. The window will be easy to pick up and move around the greater Squeak World. I don't think it uses Morphic, but a fusion of MVC and Morphic called Tweak.
Chris TFrame subclass: #TOglTestTriangle instanceVariableNames: ''
classVariableNames: '' poolDictionaries: '' category: 'OpenCobalt-OpenGL-Test'!
!TOglTestTriangle methodsFor: 'render' stamp: 'jrd 3/13/2010 17:33'! render: ogl ogl glBegin(GLTriangles). ogl glVertex3f(2.0, 2.5, -1.0).
ogl glVertex3f(-3.5, -2.5, -1.0). ogl glVertex3f(2.0, -4.0, -1.0). ogl glEnd(). ! ! |
In reply to this post by LawsonEnglish
On 3/25/2010 8:25 AM, Lawson English wrote:
> More than likely, this is way too advanced for moi, but I spent about an > hour rummaging through the Lumiere code for Pharo and just couldn't grok > how the OpenGL rendering is directed to a morph instead of to raw > coordinates on the main window. Is there some special property of Pharo > that allows this kind of thing, or is there some relatively simple way > in Squeak to direct OGL drawing to a morphic surface/canvas/thingie so > it renders inside the boundaries of the morph when moved? There is absolutely nothing to it. All you need is something like here: MyMorph>>drawOn: aCanvas "--- initialize opengl ---" ogl ifNil:[ ogl := OpenGL newIn: self bounds. ogl ifNil:[^super drawOn: aCanvas]. ] ifNotNil:[ ogl bufferRect: self bounds. ]. "--- when not rendering to Display, draw last captured frame ---" aCanvas form == Display ifFalse:[ ^aCanvas drawImage: ogl screenShot at: bounds origin. ]. "--- otherwise do normal scene rendering ---" ^self renderScene: ogl. Cheers, - Andreas |
Andreas Raab wrote:
> On 3/25/2010 8:25 AM, Lawson English wrote: >> More than likely, this is way too advanced for moi, but I spent about an >> hour rummaging through the Lumiere code for Pharo and just couldn't grok >> how the OpenGL rendering is directed to a morph instead of to raw >> coordinates on the main window. Is there some special property of Pharo >> that allows this kind of thing, or is there some relatively simple way >> in Squeak to direct OGL drawing to a morphic surface/canvas/thingie so >> it renders inside the boundaries of the morph when moved? > > There is absolutely nothing to it. All you need is something like here: > > MyMorph>>drawOn: aCanvas > That WAS easy. Is there a simple way to implement the c-like syntax you did for Cobalt? I'm working on recreating the HE tutorial series and many people will balk at the with:with:with:with: syntax, I'm afraid Lawson |
On 4/1/2010 4:19 PM, Lawson English wrote:
> Andreas Raab wrote: >> On 3/25/2010 8:25 AM, Lawson English wrote: >>> More than likely, this is way too advanced for moi, but I spent about an >>> hour rummaging through the Lumiere code for Pharo and just couldn't grok >>> how the OpenGL rendering is directed to a morph instead of to raw >>> coordinates on the main window. Is there some special property of Pharo >>> that allows this kind of thing, or is there some relatively simple way >>> in Squeak to direct OGL drawing to a morphic surface/canvas/thingie so >>> it renders inside the boundaries of the morph when moved? >> >> There is absolutely nothing to it. All you need is something like here: >> >> MyMorph>>drawOn: aCanvas >> > [...] > > That WAS easy. Is there a simple way to implement the c-like syntax you > did for Cobalt? I'm working on recreating the HE tutorial series and > many people will balk at the with:with:with:with: syntax, I'm afraid There is no easy way to recreate that syntax. If you really want it you'll have to go back to an old Croquet or Cobalt image. But I very much doubt that anyone will really care. Since you're not going to make OpenGL calls all the time, you can't avoid introducing keyword syntax. As soon as you introduce keyword AND non-keyword syntax you're making it harder for new users (which I assume is your audience). They'll be confused when they can use keyword and when they can use non-keyword syntax, whether that will make any difference (Python 'named' arguments are optional) etc. They won't find that ever discussed in any book on Smalltalk they might look at, they won't understand if that is Smalltalk or some DSL and so on. Simple consistency is best. Explain the mapping and trust in the smarts of people - as long as they understand the rules they'll be able to follow them. Cheers, - Andreas |
Free forum by Nabble | Edit this page |