• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1vgamemaster  Members

103
Like
0Likes
Like

Posted 09 December 2012 - 10:11 PM

Hey guys,

I've been working all day to try and get an object loader working. I've been using this file as a reference.

http://openglsamples.sourceforge.net/files/glut_obj.cpp

Can anyone see whats wrong with this? I am just getting a blank screen.

Thanks

### #2BitMaster  Members

8647
Like
0Likes
Like

Posted 10 December 2012 - 01:47 AM

The most common mistake when loading Wavefront Obj files is being off by one in the indices because Wavefront indices are one-based while practically every renderer (including OpenGL) expect zero-based indices.

That said, have you tried stepping through the code with a debugger and having a look at how the loaded mesh data looks?

If neither of that helps, we will be needing more information (and actually used code). "using this file as a reference" can mean too many things to give any sensible advise.

### #3vgamemaster  Members

103
Like
0Likes
Like

Posted 10 December 2012 - 11:41 AM

Sorry, I worded that poorly. I believe I have copied everything exactly from that file. I do think it accounts for the off by one in Model_OBJ::Load. In the middle of the method there is:

vertexNumber[0] -= 1; // OBJ file starts counting from 1
vertexNumber[1] -= 1; // OBJ file starts counting from 1
vertexNumber[2] -= 1; // OBJ file starts counting from 1

Still stumped

### #4MarkS  Members

2981
Like
0Likes
Like

Posted 10 December 2012 - 01:22 PM

When I wrote my OBJ loader, I was having the same issues. What I found to be the best method of debugging the loader is to create a print function that prints the contents of the loaded OBJ to the console in OBJ format. This way you can open the OBJ file in a text editor and compare it with the console side by side. Once you see what parts of the file are not loading correctly, it becomes much easier to debug the loader.

And would suggest that you make plans to dump the OBJ format at some point and stick with binary file formats, even if that means creating your own. As you've seen, writing a loader for a human readable format SUCKS!

Also, looking at your code, this "vertexBuffer = (float*) malloc (fileSize);" needs to be "vertexBuffer = (float*) malloc (fileSize*sizeof(float));". You are allocating an array of fileSize bytes as written, not an array of fileSize floats.

To that end, skip malloc all together. Use new/delete.


vertexBuffer = new float[fileSize];

.

.

.

detete [] vertexBuffer;



Edited by MarkS, 10 December 2012 - 02:02 PM.

### #5i_luv_cplusplus  Members

250
Like
2Likes
Like

Posted 10 December 2012 - 04:38 PM

To that end, skip malloc all together. Use new/delete.

vertexBuffer = new float[fileSize];
.
.
.
detete [] vertexBuffer;


Or even better:
std::vector<float> vertexBuffer(fileSize);


OpenGL fanboy.

### #6MarkS  Members

2981
Like
0Likes
Like

Posted 10 December 2012 - 05:00 PM

Or even better:

std::vector<float> vertexBuffer(fileSize);


I use vectors in my OBJ loader. I was going to mention it, but didn't want to complicate the issues. And I have a cold and am typing through a fog...