About Monkey 2 › Forums › Monkey 2 Development › Can't get stb-image to work (bug?)
This topic contains 5 replies, has 3 voices, and was last updated by 
 Danilo
 2 years, 1 month ago.
- 
		AuthorPosts
 - 
		
			
				
March 8, 2017 at 10:25 am #7412
I have been trying to use the stb-image module in Monkey2 but couldn’t get stbi_load nor stbi_load_from_memory to work.
With stbi_load_from_memory, I first load a DataBuffer and then pass its data to the function. Monkey2 parses the program correctly, but C++ gives the following error with the generated code:
error: invalid conversion from ‘bbInt* {aka int*}’ to ‘int’ [-fpermissive]
bbUByte* l_data=stbi_load_from_memory(f0.l_dataBuffer->m_Data(),l_pWidth,l_pHeight,((bbInt*)0),4);The Monkey2 line looks like this:
Local data:UByte Ptr = stb.image.stbi_load_from_memory(dataBuffer.Data, pWidth, pHeight, Null, 4)
Where pWidth and pHeight are Int Ptr.
If I use stbi_load, I use it like this:
Local data:UByte Ptr = stb.image.stbi_load(“asset::” + filename, pWidth, pHeight, Null, 4)
Which gives the following C++ error:
error: conversion from ‘bbString’ to ‘const char*’ is ambiguous
bbUByte* l_data=stbi_load((bbString(L”asset::”,7)+l_filename),l_pWidth,l_pHeight,((bbInt*)0),4);March 9, 2017 at 1:13 am #7426Ok, my bad, looks like there were some errors in the stb-image module externs. I have committed a new version of stb-image.monkey2 to the develop branch, here:
https://github.com/blitz-research/monkey2/blob/master/modules/stb-image/stb-image.monkey2
A few things to note:
- The stbi_load() filename param is an ‘OS’ filename, it can’t contain ‘asset::’ in path (std-image module is just a thin wrapper around the c lib). You can find the filesystem path of the assets dir with ‘AssetsDir’ function in std.filesystem, but note this will not work on targets that don’t store assets in the OS filesystem such as android.
 - You can also just use Pixmap.Load in std module. This will return a Pixmap with Width/Height/Data etc properties. This will also allow you to use ‘asset::’ in the path on all targets.
 
March 9, 2017 at 9:03 am #7429Thanks for your reply, Mark!
Yeah, I ended up simply using Pixmap.Load, which worked great. I have been following development of Monkey2 for a while, but I just decided to start playing with it and I am amazed! The docs are a bit lackluster, but thankfully, by looking at the samples or searching here I am finding the solution to my problems.
I am working on some 3D stuff that I have been doing on Monkey-X for a while. Nothing as fancy as your mx23d, but is progressing well. I’ll post some stuff soon.
I know that you haven’t made up your mind yet on whether to use gles2 o 3, but, could you add a gles3 module to the language? I would love to be able to have geometry instancing and multiple render targets on what I am doing.
Oh! And will you publish soon that tool you made to generate mx2 wrappers from C++ libraries? Having stb-truetype would be useful for my project.
Thanks!
March 9, 2017 at 10:03 am #7431@javicervera:
Please don’t use “mx23d”…“MX2-3D” / “M2-3D”/ “MX-3D” / “MonkeyX2 3D” / “Monkey 2 3D” / “MonkeyX 3D”
would be Okay.
“mx23d” looks weird… and it would be better to
have a name like “MX2-3D” / “MonkeyX2 3D” / “Monkey2 3D”.March 9, 2017 at 10:05 am #7432Hahaha I agree, but I used it because that’s the way I’ve seen Mark call it on Twitter.
March 9, 2017 at 10:09 am #7433 - 
		AuthorPosts
 
You must be logged in to reply to this topic.