newLISP Fan Club

Forum => newLISP Graphics & Sound => Topic started by: newdep on April 14, 2008, 02:46:58 AM

Title: OpenGL => GLFW context
Post by: newdep on April 14, 2008, 02:46:58 AM
More OpenGL..



GLFW 2.6 context added for OpenGL I/O handling =>

(load "//http://www.nodep.nl/downloads/newlisp/glfw.lsp")





GLFW is available for Windows, Mac OS X and Unix-like systems such as Linux, Solaris and FreeBSD.



More to come !
Title:
Post by: m35 on April 14, 2008, 10:52:09 AM
Thanks for putting this together. I've recently been working with OpenGL, so this  is interesting to see.



Have you tested the multi-threading abilities of the library with newlisp? I can't imagine how that would even work.
Title:
Post by: newdep on April 14, 2008, 12:57:36 PM
Yes glfw was missing and I like the setup of the code so i though lets

make a context of it..



It seems we can create the thread, but the return of the thread

just kills newlisp..There is probably a something that

cant be catched by newlisp and it "Segment Faults"  =>



;; example

(define (handler sig) (println "Signal => " sig) (exit))              

(for (s 1 32) (signal s 'handler))      



;; example

(load "glfw.lsp")

(glfw:Init)

(define (*hello*) (println "Hello "))

(set 'thread (glfw:CreateThread (address (*hello*)) NULL))

(glfw:WaitThread thread glfw:GLFW_WAIT)

(println "thread!")

(glfw:Terminate)





..After the CreateThread it goes wrong,

the (*hello*) is executed with success

and the Thread returns 1 and newlisp returns a "Seg Fault ;-)"



I cant figure it out but it seems newlisp and glfw dont like this togther..

If I figured it out ill drop a note here..
Title:
Post by: newdep on April 14, 2008, 02:43:26 PM
I think its not going to work..



the first "Hello" is returned because of (address ....) and not

because of the thread.. The Thread though is started and killed

but not as it should.. Mmmm "Out of resources" at the moment ;-)
Title:
Post by: cavva on May 03, 2009, 02:16:16 PM
hi newdep,



can you have some example code using glfw?



I'm using newlisp + glfw 2.6 + osx, i've made a little test to see the how "key listener callback" could work, but when i type sometingh the application crash... so i don't understand if i made some mistake ... here is the code:



(load "glfw.lsp" )
(load "gl.lsp" )

(define (reshape width height)
(println "reshape")
)

(define (keypress key action)
(println "keypress")
)

(glfw:Init)

(glfw:OpenWindow 640 400 0 0 0 0 16 0 glfw:GLFW_WINDOW)

(glfw:SetWindowTitle "Test Carlo")
(glfw:SetKeyCallback 'keypress )

(while (!= (glfw:GetKey glfw:GLFW_KEY_ESC) glfw:GL_TRUE)
(begin
(gl:Clear gl:GL_COLOR_BUFFER_BIT)
(glfw:SwapBuffers)
)
)

(glfw:Terminate)

(exit)
Title:
Post by: Lutz on May 03, 2009, 02:54:36 PM
Perhaps you are not using 'glfw:SetKeyCallback' correctly. newLISP has a function 'callback' which probably should be used here. Try this:


(glfw:SetKeyCallback (callback 1 'keypress))


here is example code using OpenGL and GLUT for registering callbacks:



http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt



it works well on Mac OS X (Intel processor required) with nothing additional to be installed and works with the GLUT Framework for handling input and window handling.



Using GLFW it will work in a similar fashion.
Title:
Post by: Ryon on May 03, 2009, 09:13:16 PM
If anyone has trouble running the above example under Ubuntu, check this bug report (//https). I solved the problem by removing xorg-driver-fglrx.
Title:
Post by: cavva on May 04, 2009, 01:56:09 PM
Lutz, with 'callback all works great !!


Quote from: "Lutz"


here is example code using OpenGL and GLUT for registering callbacks:



http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-lsp.txt



it works well on Mac OS X (Intel processor required) with nothing additional to be installed and works with the GLUT Framework for handling input and window handling.


I know that GLUT is on most platform, but reading some tutorials all says it's only for basic demos, so i've choosen another lib (without knowing if glut fame was real )...



the first was SDL, but on Mac osx the lib need to istantiate a NSAutoreleasePool obj, and i don't have the knowledge required for it



so my second try was GLFW, it's small, simple, portble and written in Carbon... it was love at first sight :)