longlene / cl-raylib

Common Lisp binding of raylib
MIT License
145 stars 21 forks source link

Requesting example of how to load/draw a model #10

Open shelvick opened 3 years ago

shelvick commented 3 years ago

When I try to load and draw a simple model, such as in this example, I get pointer errors in (draw-model):

The value
  (1065353216 0 #.(SB-SYS:INT-SAP #X00000000)
   #.(SB-SYS:INT-SAP #X3F80000000000000)
   #.(SB-SYS:INT-SAP #X00000000) #.(SB-SYS:INT-SAP #X00000000)
   #.(SB-SYS:INT-SAP #X3F800000) #.(SB-SYS:INT-SAP #X00000000)
   #.(SB-SYS:INT-SAP #X3F80000000000000)
   #.(SB-SYS:INT-SAP #X10000001)
   #.(SB-SYS:INT-SAP #X7FAA9C405CF0)
   #.(SB-SYS:INT-SAP #X7FAA9C406E40)
   #.(SB-SYS:INT-SAP #X7FAA9C406FD0) 0
   #.(SB-SYS:INT-SAP #X00000000))

is not of type
  SB-SYS:SYSTEM-AREA-POINTER

This works in C so at least on some level I am using the library correctly. Do you have a working Lisp example? Am I doing something wrong or is this related to #3?

longlene commented 3 years ago

Sorry for that. As the raylib library use the struct and pointer to the struct at the same time, some APIs may not work as expected. Those APIs may be could be rewrote with Common Lisp. I'll try it when I have time.

kiran-kp commented 2 years ago

The issue here might just be that the bones and bind-pose members are declared as structs CL but they are pointers in the C struct. The code is likely just reading invalid memory.

;;
;;// Model, meshes, materials and animation data
;;typedef struct Model {
;;    Matrix transform;       // Local transform matrix
;;
;;    int meshCount;          // Number of meshes
;;    int materialCount;      // Number of materials
;;    Mesh *meshes;           // Meshes array
;;    Material *materials;    // Materials array
;;    int *meshMaterial;      // Mesh material number
;;
;;    // Animation data
;;    int boneCount;          // Number of bones
;;    BoneInfo *bones;        // Bones information (skeleton)
;;    Transform *bindPose;    // Bones base transformation (pose)
;;} Model;
(defcstruct (%model :class model-type)
 "Model type"
 (transform (:struct %matrix))
 (mesh-count :int)
 (material-count :int)
 (meshes (:pointer (:struct %mesh)))
 (materials (:pointer (:struct %material)))
 (mesh-material (:pointer :int))
 (bone-count :int)
 (bones (:struct %bone-info))
 (bind-pose (:struct %transform)))