split project into static and dynamic modules

This commit is contained in:
Richard Smith 2019-05-24 04:31:48 +01:00
parent 55dca44b4a
commit b6b9054d0d
28 changed files with 188 additions and 161 deletions

View file

@ -1,42 +1,31 @@
"""
This is an attempt at a CFFI dynamic (ABI) binding. However, it fails to work in the same place the ctypes binding fails, accessing
materials of a model, because Python can't dynamically tell the difference between a pointer and an array. There's probably
some way to specify this (e.g. in raylib_modified.h) but it's difficult to be sure we fixed them all, and the errors
are often completely silent.
This shows how to use the CFFI dynamic (ABI) binding. Note that is slower and more likely to run into silent errors.
But it doesnt require any C compiler to build.
"""
import pathlib
MODULE = pathlib.Path(__file__).parent
print(MODULE)
from raylib.dynamic_binding import ffi, raylib as rl
from raylib.dynamic import ffi, raylib as rl
from raylib.colors import *
rl.InitWindow(800,450,b"foo")
rl.InitWindow(800,450,b"Raylib dynamic binding test")
rl.SetTargetFPS(60)
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 ])
imageFile = str(MODULE / "examples/models/resources/heightmap.png").encode('utf-8')
image = rl.LoadImage(imageFile) # Load heightmap image (RAM)
print(image)
texture = rl.LoadTextureFromImage(image) # Convert image to texture (VRAM)
image = rl.LoadImage(imageFile)
texture = rl.LoadTextureFromImage(image)
mesh = rl.GenMeshHeightmap(image, [ 16, 8, 16 ])
model = rl.LoadModelFromMesh(mesh)
print(model.materials) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ?
mesh = rl.GenMeshHeightmap(image, [ 16, 8, 16 ]) # Generate heightmap mesh (RAM and VRAM)
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
mapPosition = ( -8.0, 0.0, -8.0 )
print(mesh)
rl.UnloadImage(image)
model = rl.LoadModelFromMesh(mesh) # Load model from generated mesh
print(model.materials) # SHOULD BE A pointer to a 'struct Material' but instead is NULL pointer to 'Material'
#model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture # Set map diffuse texture
mapPosition = ( -8.0, 0.0, -8.0 ) # Define model position
rl.UnloadImage(image) # Unload heightmap image from RAM, already uploaded to VRAM
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) # Set an orbital camera mode
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL)
while not rl.WindowShouldClose():
@ -47,6 +36,12 @@ while not rl.WindowShouldClose():
rl.DrawModel(model, mapPosition, 1.0, RED)
rl.DrawGrid(20, 1.0)
rl.EndMode3D()
rl.DrawText(b"sdfsdf", 190, 200, 20, BLACK)
rl.DrawText(b"This mesh should be textured", 190, 200, 20, VIOLET)
rl.EndDrawing()
rl.CloseWindow()
rl.CloseWindow()
"""
Previously this failed to work in the same place the ctypes binding fails, accessing
materials of a model. I though it was because Python can't dynamically tell the difference between a pointer and an array.
"""