Re: FreeGlut Example Not Working
- Posted by Icy_Viking Feb 05, 2021
- 1032 views
ghaberek said...
Icy_Viking said...
Thanks for the tips. I tried a more simple idea, but it still isn't working.
atom y = routine_id("Render") call_proc(y,{}) glutDisplayFunc(y)
That needs to be call_back() not call_proc(). They have very similar names but very different purposes. And you need to pass the result of call_back() (not the result of routine_id()) to glutDisplayFunc.
integer Render_id = routine_id( "Render" ) atom Render_cb = call_back( Render_id ) glutDisplayFunc( Render_cb )
A few notes about the Euphoria internals:
- routine_id() returns an integer that counts from one, which is the index to an internal routine list that then contains another index to somewhere in the internal symbol table.
- call_func() and call_proc() take that index value from routine_id() and simply make normal internal routine call to the value at that index in the routine list, the same way you would if you called the routine directly by name.
- call_back() takes an index value from routine_id() and sets up a small C function in memory and returns an atom that contains the new memory address. You then take that memory address value and give it to some external system so that the system can make a call back into your Euphoria application from the outside.
-Greg
Thanks Greg. So I tried making some more changes and I still can't get the window to appear.
--Wrapper code public constant xglutInit = define_c_proc(glut,"+glutInit",{C_POINTER,C_POINTER}) public procedure glutInit(sequence args = command_line()) if length(args) >= 2 and equal(args[1],args[2]) then args = args[2..$] end if atom pargc = allocate_data(sizeof(C_INT)) atom pargv = allocate_string_pointer_array(args) c_proc(xglutInit,{pargc,pargv}) free_pointer_array(pargv) free(pargc) end procedure
--Example without warning include EuFreeGlut.ew include std/machine.e include std/math.e include std/dll.e include flags.e glutInit("") glutInitDisplayMode(or_all({GLUT_DEPTH,GLUT_DOUBLE,GLUT_RGBA})) glutInitWindowPosition(100,100) glutInitWindowSize(640,480) atom x = glutCreateWindow("My Window") procedure Render() glutSwapBuffers() end procedure integer id = routine_id("Render") atom id_cb = call_back(id) glutDisplayFunc(id_cb) glutMainLoop()