sharpgl icon indicating copy to clipboard operation
sharpgl copied to clipboard

Loading .obj files with textures does not work?

Open Kermalis opened this issue 4 years ago • 2 comments

I'm trying to follow your samples but it seems basic functionality is not working.

When you do either SerializationEngine.Instance.LoadScene(path) or new ObjFileFormat().LoadData(path), there's a crash. This is because LoadData() makes a brand new Scene with no gl context, meaning the Scene's gl context is null. Then when loading textures, it crashes because it calls Texture.Create() with a null gl context.

Am I missing something? I feel like everyone in the planet would be making this issue if it was actually broken. There's no way for me to pass in a gl context. Also, I can't downgrade to 2.4.4 (before this crash would've existed) because your Serialization nuget package does not go before 3.1.0

Kermalis avatar Jul 11 '21 13:07 Kermalis

I ran into this issue too as I was trying to port the library and samples to .net 6. I got the "WinForms Sample/DuckySample" to load by modifying the ObjFileFormat to include a property to provide the GlContext, assigning it when creating the ObjFileFormat, and calling scene.CreateInContext(..) before loading the format.

I don't think it was just you. This seems a pretty clear bug, possibly a design issue by the mandate that the GL context be initialized before being able to utilize the load model data (which was more what I was looking for - something that could parse and open Wavefront OBJ files, rather than a full OpenGL engine.)

trenttobler avatar Apr 17 '22 16:04 trenttobler

This got me as well, spent quite a few minutes investigating file paths, formats and whatnot, and finally found the faulty place: https://github.com/dwmkerr/sharpgl/blob/9a18e2624f488635ee87d4ee5a75aa2e6df09cdd/source/SharpGL/Core/SharpGL.Serialization/Wavefront/ObjFileFormat.cs#L254

Fortunately, it was pretty easy to create a custom ObjFileFormat with context.

progmars avatar Oct 16 '23 21:10 progmars