11"""
2- This shows how to use the CFFI dynamic (ABI) binding. Note that is slower and more likely to run into silent errors.
2+ This shows how to use the CFFI dynamic (ABI) binding. Note that is slower and more likely to run into silent errors and segfaults .
33But it doesnt require any C compiler to build.
44"""
5- import pathlib
6- MODULE = pathlib .Path (__file__ ).parent
7-
85from raylib .dynamic import ffi , raylib as rl
96from raylib .colors import *
107
11- rl .InitWindow (800 ,450 ,b"Raylib dynamic binding test" )
8+ rl .InitWindow (800 , 450 , b"Raylib dynamic binding test" )
129rl .SetTargetFPS (60 )
1310
14- camera = ffi .new ("struct Camera3D *" , [[ 18.0 , 16.0 , 18.0 ], [ 0.0 , 0.0 , 0.0 ], [ 0.0 , 1.0 , 0.0 ], 45.0 , 0 ])
15-
16- imageFile = str (MODULE / "examples/models/resources/heightmap.png" ).encode ('utf-8' )
17- image = rl .LoadImage (imageFile )
11+ camera = ffi .new ("struct Camera3D *" , [[18.0 , 16.0 , 18.0 ], [0.0 , 0.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], 45.0 , 0 ])
12+ image = rl .LoadImage (b"examples/models/resources/heightmap.png" )
1813texture = rl .LoadTextureFromImage (image )
19- mesh = rl .GenMeshHeightmap (image , [ 16 , 8 , 16 ])
14+ mesh = rl .GenMeshHeightmap (image , [16 , 8 , 16 ])
2015model = rl .LoadModelFromMesh (mesh )
21- print (model .materials ) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ?
22-
16+ print (model .materials ) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ?
2317model .materials .maps [rl .MAP_DIFFUSE ].texture = texture
24- mapPosition = ( - 8.0 , 0.0 , - 8.0 )
2518
2619rl .UnloadImage (image )
27-
2820rl .SetCameraMode (camera [0 ], rl .CAMERA_ORBITAL )
2921
30-
3122while not rl .WindowShouldClose ():
3223 rl .UpdateCamera (camera )
3324 rl .BeginDrawing ()
3425 rl .ClearBackground (RAYWHITE )
3526 rl .BeginMode3D (camera [0 ])
36- rl .DrawModel (model , mapPosition , 1.0 , RED )
27+ rl .DrawModel (model , ( - 8.0 , 0.0 , - 8.0 ) , 1.0 , RED )
3728 rl .DrawGrid (20 , 1.0 )
3829 rl .EndMode3D ()
3930 rl .DrawText (b"This mesh should be textured" , 190 , 200 , 20 , VIOLET )
4031 rl .EndDrawing ()
4132rl .CloseWindow ()
4233
43-
4434"""
4535Previously this failed to work in the same place the ctypes binding fails, accessing
4636materials of a model. I though it was because Python can't dynamically tell the difference between a pointer and an array.
47- """
37+ """
0 commit comments