Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Back On The Object Loader Again

This thread is locked; no one can reply to it. rss feed Print
Back On The Object Loader Again
Scooter
Member #16,799
January 2018

Hi all:

I had some time to waste so I thought I would try getting an

object loader to work again. I found Nate Robins object loader

library so I thought I would give it a try. Had some real good

luck except for one small detail. I can load and render every

model if it contains just the .obj and .mtl files. If they contain

the texture file I fall short. The library contains code to load

the texture but I can't get them to load and render, Every time

I get the message: Unable to load texture. The texture is there

it just want load for some reason. I was wondering if anyone had

any experience with this library, maybe they might know how to fix

this problem.

Thanks for your time

DanielH
Member #934
January 2001
avatar

do you have the directory information correct? What are you using to load the texture?

Scooter
Member #16,799
January 2018

Hi Daniel:

Thanks for the reply!

Embedded in the library is a function called glmLoadTexture(). This

function looks for jpg, png or PPM files for the texture. At one

point I had it to load a PPM file but it did not load right. There

is some mention of using SOIL to load textures but it didn't work

either. All I am getting is just the .mtl file with no texture. I

now have 4 different files and they all do the same thing: no textures.

The reason I have 4 different ones is other people have made improvements

to this library so I tried all of them but I guess they didn't work in

this area. It is a great library using just straight C. This is what

I prefer to work with. Again, thanks for the reply. If you come up

with something, please let me know. Have a great day!

amarillion
Member #940
January 2001
avatar

I think you need to provide more details before we can help you. Can you share a minimal project (sources + data files) that demonstrates the problem?

Also, why do you format your posts like a poem? :P

--
Martijn van Iersel | My Blog | Sin & Cos | Food Chain Farm | Support TINS

Dizzy Egg
Member #10,824
March 2009
avatar

I'd imagine there's going to be some Allegro specific bits you'll need to modify (if you're using Allegro). Even with glut there's probably some code you need to add.

You'll need to ensure that the texture described in the mtl file is being put where it should be for the texture loader to work, ans also ensure it's being properly mapped to the object. I'm guessing all of that should be handled by the object loader library but that's a big guess.

As amarillion said, we'd need to see some code first!

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Scooter
Member #16,799
January 2018

Hi all:

I tried to send a zip file of the library. Hope I did it right.

Thanks for your time. See above. I am using Linux.

Dizzy Egg
Member #10,824
March 2009
avatar

I'm guessing you're seeing this line:

__glmWarning("glmLoadTexture() failed: Unable to load texture from %s!", filename);

Which should include the path that it's trying to load from; what is the full error you see when running it...

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Scooter
Member #16,799
January 2018

Hi Dizzy:

That is exactly what I am receiving. It loads the .mtl file fine.

The texture file is in the same directory as the .mtl file. Some lines

in one file had been greyed out. Thought I had found the problem. I still

believe that is what is wrong. When I fixed that more problems showed up.

The path I had is correct or the .mtl file would not have been loaded.

Dizzy Egg
Member #10,824
March 2009
avatar

I don't think you're going to be able to load textures with that version of the object loader. The most you can do is load an object with multiple materials (I've attached one that I got working).

But as for actual textures (jpeg/png etc) that version of the object loader doesn't seem to work properly. There is an updated version HERE that works with .sgi textures, but it's not complete.

I think you'd need to upgrade to a newer (possible C++) version, or add the required code yourself.

EDIT:

Good news! I spent a few hours more on it, and managed to get it working with .jpg textures. I had to link libjpeg, and had to define #HAVE_LIBJPEG in a few files.

This video HERE shows me moving the model on the left, and the .jpg texture on the right.

I also had to manually edit the filename, seems there's some confusion when to use "\\" and when to use "/", not sure why.

I've got to stop for now, but I'll tidy it up tomorrow and try to get .png working as well, I've got a model with .jpg and .png textures so it will be cool to try and get that working. I'll try and show you what I changed to get it working!

EDIT 2:

I should go to bed really, but I was determined to get the PNG working. This new video shows a model loaded with JPG and PNG (the PNG is the image on the right):

VIDEO

The JPG images it loads are used for environment reflections (multipassing etc) so although they're not used for rendering they do load ok. There's 7 materials/textures loaded in total.

Again, I had to link libpng, and add some #define HAVE_LIBPNG to the source code.

EDIT 3:

Getting the hang of it now; you CANNOT have spaces in the file name (causes all sorts of issues), and certain things make it fail, like bump maps etc. I may wrap it up into a more simple loader, just for my own use in 2D games (would be cool to have some spinning 3D elements etc) but it needs A LOT of work to become a fully functioning object loader. Worth a few more nights tinkering though!

{"name":"612830","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/7\/e76f5ca3a2da44a52a3dba3e6ae85a2e.png","w":602,"h":632,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/7\/e76f5ca3a2da44a52a3dba3e6ae85a2e"}612830

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Scooter
Member #16,799
January 2018

Hi Dizzy:

That is great news! Glad you got it figured out. I posted another

program to display obj files that may be better for your games. It is

really fast and is only one file. It needs much work to be able to do

it all. I expect you could fix that without much trouble. I watched

your video. Great job! Have a great day!!!!!!!!!!

Go to: