Hey all -
I'm currently trying to compile a repository of using different features of the SDK in a vacuum. I've done some with Lua, and right now I'm trying to create C examples.
In my basic example to load and display an image, I'm getting an error, "src/main.c:45 Couldn't load image moosadee-logo.png: wrong file type: no header" -- I've tried loading in my own image and images from the Sprite Game in the SDK's C_API example folder, and it still gives me the same error.
Any ideas what causes this? My project files are here:
Thanks for the guidance!
You can't load a PNG directly.
Compile your images with your source code (it should happen with zero effort if your files are organised correctly) and refer to them by filename without extension.
Take a look at the C examples and Inside Playdate with C https://sdk.play.date/1.9.1/Inside%20Playdate%20with%20C.html
To elaborate on what matt said -- from what I can tell, .png files are automatically converted into 1-bit ".pdi" images at build time. If you actually list the contents of your assets directory (or however your project is structured) at runtime, then you'll see the contents are
.pdi images, not
I've been using a Makefile, refering to the example in the Sprite Game example in the C_API folder from the SDK folder.
When I run "make simulator" from the "C_API/Examples/Sprite Game/" I don't see any .pdi files generated (and same when I build my own project), so I'm not sure if I'm supposed to be running something to compile the images into pdi files.
By checking the assets directory at runtime, should I be writing code to access the local filesystem when the program is running, or is there a way to view local files from the simulator?
I've been referencing the SDK documentation and the example code to build out my Lua and C examples but I'm not finding the information I need for the C stuff.
I'm using CMake so I can't really help with Make specific things, but in my experience images are converted by the pdc executable, which is run after your C code is compiled. The Makefile should be running pdc automatically, so you generally shouldn't have to worry about it. I think by default pdc is run on your Source folder, which means all of your images and assets should be located in this folder so they can be converted and compiled into the pdx file.
As for accessing them in your code, I believe it uses a relative path from the root folder of your pdx (a pdx is really just a folder, although in Linux it might not appear as a folder). For example, if you have a bullet image located at "Source/images/bullet.png", then after compiling with pdc it would be located at
Game.pdx/images/bulet.pdi, and it would be loaded in C with
Thanks timhei. After I renamed my "src" folder to "Source" and updated the path in the makefile it generated the .pdx folder and the .pdi file within it, so it works now!! I'm so happy.
Renaming src to Source might be a bad idea, assuming src is where your C files are located. You want to keep all of your C related stuff outside of the Source folder. Source is only for assets and Lua code. When compiling a C project, it will first compile your C code into a library, and then automatically add the binary to your Source folder. It will then use pdc on the Source folder to compile the Lua, compiled C library, and assets into the pdx.
AH OK. I updated this so that I'm using "make pdc" instead of "make simulator" and that seems to be what fixed the issue with the image not being compiled.
The only thing I would add is that the Sprite Game example is structured correctly, so any changes made to how that works would likely have been a mistake.
If you want to build of that example, your own c/h files go in the Sprite Game folder, lua in the Source folder, images in the Source/images folder.