Re: FreeGlut Example Not Working

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...
--Wrapper 
public constant xglutInit = define_c_proc(glut,"+glutInit",{C_POINTER,C_POINTER}) 
 
public procedure glutInit(atom parg,sequence args) 
 atom str = allocate_string(args,1) 
 c_proc(xglutInit,{parg,str}) 
end procedure 
--Example 
glutInit(0,"") 

A note on wrapping this function: glutInit() expects a pointer to argc because it wants to mangle the value of argv and return back the new values in your pointers.

So you can't just pass it the raw value of argc, you have to allocate memory for an int value and then poke it and pass the pointer.

Now, since you're passing zero, the function reads this as a NULL pointer, so maybe it's okay?

But if you were to try and pass an actual value this way it would probably kick back an error or, more likely, just crash right out.

Here is how I wrapped glutInit():

public procedure glutInit( sequence argv=command_line() ) 
 
    -- glutInit expects C-style argv, so drop the first 
    -- argument if it's the same as the second, which 
    -- happens if we are running bound or translated. 
 
    if length( argv ) >= 2 and equal( argv[1], argv[2] ) then 
        argv = argv[2..$] 
    end if 
 
    atom pargc = allocate_data( sizeof(C_INT) ) 
    atom pargv = allocate_string_pointer_array( argv ) 
    poke4( pargc, length(argv) ) 
 
    c_proc( xglutInit, {pargc,pargv} ) 
 
    -- If you want to maintain the original functionality 
    -- of glutInit mangling the argv array, you should peek 
    -- back the strings here and return them to the user. 
 
    free_pointer_array( pargv ) 
    free( pargc ) 
 
end procedure 

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu