Hi,

I think you're approaching this incorrectly. Factor's UI is not  
designed with the goal that simple demos should port directly.

In graft*, you can set up the GL context and do things such as create  
display lists, vertex arrays, and so on, however if you change the  
projection matrix in graft* it will be changed again before draw- 
gadget* is called.

Don't write your gadget assuming it can take over the GL context.  
Usually when writing a gadget, there is no reason to change  
projection or model view matrices at all. And you certainly don't  
need to call glViewport or glClear, the UI does that for you.

Slava

On 31-May-07, at 2:42 AM, Jeff Ervin wrote:

> Thanks for the quick response Slava. The following code is example 1-3
> from the OpenGL Programming Guide - a square that spins when the left
> mouse button is pressed. I am  setting the background color and shade
> model in graft* after  calling find-gl-context (I didn't find
> libs/canvas you mentioned in  Factor  .89 but  I did find this word in
> libs/gadgets/lib/lib.factor). These words don't have any effect. If
> however I uncomment out the calls to these words at the top of
> draw-gadget* it works fine. Am I doing something wrong here? Also I
> expected to find some sort of resize generic word for the gadget  
> where I
> could place the call to glViewport. Wasn't able to find anything that
> looked like what I wanted in the documentation - is there such a  
> thing?
>
> IN: red-book
> USE: modules
> "libs/gadgets/lib/lib" require
> USING: kernel gadgets opengl arrays timers math sequences  
> gadgets.lib ;
>
> : width ( gadget -- n )
>     rect-dim 0 swap nth ;
>
> : height ( gadget -- n )
>     rect-dim 1 swap nth ;
>
> TUPLE: example-1-3-gadget spin ;
>
> C: example-1-3-gadget ( -- gadget )
>     [ 0.0 swap set-example-1-3-gadget-spin ] keep
>     [ delegate>gadget ] keep ;
>
> M: example-1-3-gadget pref-dim* ( gadget -- dim )
>     drop { 250 250 } ;
>
> M: example-1-3-gadget draw-gadget* ( gadget -- )
>     #! 0.0 0.0 0.0 0.0 glClearColor
>     #! GL_FLAT glShadeModel ;
>     0 0 pick [ width ] keep height glViewport
>     GL_PROJECTION glMatrixMode
>     glLoadIdentity
>     -50.0 50.0 -50.0 50.0 -1.0 1.0 glOrtho
>     GL_MODELVIEW glMatrixMode
>     glLoadIdentity
>     GL_COLOR_BUFFER_BIT glClear
>     glPushMatrix
>     example-1-3-gadget-spin 0.0 0.0 1.0 glRotatef
>     1.0 1.0 1.0 glColor3f
>     -25.0 -25.0 25.0 25.0 glRectf
>     glPopMatrix ;
>
> M: example-1-3-gadget tick ( gadget -- )
>     dup    example-1-3-gadget-spin
>     2.0 + dup
>     360.0 > [ 360.0 - ] when
>     over set-example-1-3-gadget-spin
>     relayout-1 ;
>
> M: example-1-3-gadget graft* ( gadget -- )
>     find-gl-context
>     0.0 0.0 0.0 0.0 glClearColor
>     GL_FLAT glShadeModel ;
>
> example-1-3-gadget H{
>     { T{ button-down f f 1 } [ dup remove-timer 1 1 add-timer ] }
>     { T{ button-down f f 2 } [ remove-timer ] }
> } set-gestures
>
> : run-example-1-3 ( -- )
>     <example-1-3-gadget> "Example 1-3" open-window ;
>
>
> ---------------------------------------------------------------------- 
> ---
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to