Re: FreeGlut Example Not Working

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...

Thanks Greg. So I tried making some more changes and I still can't get the window to appear.

procedure Render() 
 
glutSwapBuffers() 
	 
end procedure 
 
integer id = routine_id("Render") 
 
atom id_cb = call_back(id) 
 
glutDisplayFunc(id_cb) 

Call backs must be functions, not procedures:

docs said...

You can set up as many call-back functions as you like, but they must all be Euphoria functions (or types) with 0 to 9 arguments. If your routine has nothing to return (it should really be a procedure), just return 0 (say), and the calling C routine can ignore the result.

When I run your code I get this output, which clearly describes the problem. Like I said, make sure you're testing with eui.exe on the command line, so you see errors like this.

C:\Euphoria\include\std\dll.e:552 in function call_back() 
call-back routine must be a function or type 
 
... called from C:\Users\Greg\Projects\ghaberek\freeglut\demo.ex:16 
 
--> See ex.err 

Also, I realized that the FreeGLUT library on Windows is using __declspec() calling convention, so you need to add a '+' to your call_back(). It works as-is because the render function accepts and returns no parameters, but as soon as you add parameters, it will crash because they are passed differently depending on the calling convention. (And really this is only a problem if you're using 32-bit because 64-bit uses the same calling convention regardless of platform.)

include std/dll.e -- for NULL and call_back() 
include std/math.e -- for or_all() 
include GL/freeglut.e 
 
function Render() 
 
    glutSwapBuffers() 
 
    return NULL 
end function 
 
constant Render_id = routine_id( "Render" ) 
constant Render_cb = call_back( '+' & Render_id ) 
 
procedure main() 
 
    glutInit( "" ) 
 
    glutInitDisplayMode( or_all({GLUT_DEPTH,GLUT_DOUBLE,GLUT_RGBA}) ) 
 
    glutInitWindowPosition( 100, 100 ) 
 
    glutInitWindowSize( 640, 480 ) 
 
    atom x = glutCreateWindow( "My Window" ) 
 
    glutDisplayFunc( Render_cb ) 
 
    glutMainLoop() 
 
end procedure 
 
main() 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu