I have not tried FreeImage (is it difficult to build using Emscripten?) but I don't see any warnings "RENDER WARNING: there is no texture bound to the unit 0" in log within a small test in OCCT sample. What is your browser and configuration?
Archived image: external image
#include <Graphic3d_Texture2Dmanual.hxx>
static Handle(Image_PixMap) myDefaultTexture;
extern "C" void onFileDataRead (void* theOpaque, void* theBuffer, int theDataLen) {
const TCollection_AsciiString aName (theOpaque != NULL ? (const char* )theOpaque : "");
Standard_ArrayStreamBuffer aStreamBuffer ((const char* )theBuffer, theDataLen);
std::istream aStream (&aStreamBuffer);
TopoDS_Shape aShape; BRep_Builder aBuilder; BRepTools::Read (aShape, aStream, aBuilder);
Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape);
aShapePrs->SetMaterial (Graphic3d_NOM_SILVER);
if (!myDefaultTexture.IsNull()) {
const Handle(Graphic3d_AspectFillArea3d)& anAspects = aShapePrs->Attributes()->ShadingAspect()->Aspect();
anAspects->SetTextureMap (new Graphic3d_Texture2Dmanual (myDefaultTexture));
anAspects->SetTextureMapOn (true);
}
aViewer.Context()->Display (aShapePrs, AIS_Shaded, 0, false);
aViewer.View()->FitAll (0.01, false);
aViewer.View()->Redraw();
Message::DefaultMessenger()->Send (TCollection_AsciiString("Loaded file ") + aName, Message_Info);
}
//! File read error event.
static void onFileReadFailed (void* theOpaque) {
const char* aName = (const char* )theOpaque;
Message::DefaultMessenger()->Send (TCollection_AsciiString("Error: unable to load file ") + aName, Message_Fail);
}
//! Image file read event.
extern "C" void onImageRead (const char* theFilePath) {
int aSizeX = 0, aSizeY = 0;
char* anImgData = emscripten_get_preloaded_image_data (theFilePath, &aSizeX, &aSizeY);
if (anImgData == nullptr) {
Message::DefaultMessenger()->Send (TCollection_AsciiString("Error: invalid image ") + theFilePath, Message_Fail);
}
Message::DefaultMessenger()->Send (TCollection_AsciiString("Loaded image ") + theFilePath + "@" + aSizeX + "x" + aSizeY, Message_Info);
/// TODO memleak: free(anImgData) should be added somehow, by subclassing Image_PixMap etc.
Handle(Image_PixMap) anImage = new Image_PixMap();
anImage->InitWrapper (Image_Format_RGBA, (Standard_Byte* )anImgData, aSizeX, aSizeY);
myDefaultTexture = anImage;
}
extern "C" void onImageReadFailed (const char* theFilePath) {
Message::DefaultMessenger()->Send (TCollection_AsciiString("Error: unable to load image ") + theFilePath, Message_Fail);
}
int main() {
Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
Handle(Message_PrinterSystemLog) aJSConsolePrinter = new Message_PrinterSystemLog ("webgl-sample", Message_Trace);
Message::DefaultMessenger()->AddPrinter (aJSConsolePrinter); // open JavaScript console within the Browser to see this output
Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
emscripten_set_main_loop (onMainLoop, -1, 0);
aViewer.run();
emscripten_async_wget_data ("samples/Ball.brep", (void* )"samples/Ball.brep", onFileDataRead, onFileReadFailed);
emscripten_async_wget("OCC_logo.png", "/emulated/OCC_logo.png", onImageRead, onImageReadFailed);
return 0;
}
p, li { white-space: pre-wrap; }