Orange Part Two – Load the OBJ

So in Part One we got our OpenGL app up and running (with no OpenGL, wait for it..) and some basic drag and drop of a single file. I’m not going to get into multiple files but later on it might be cool to be able to drop on an .obj and .png and have the whole thing kapow with the model right there… But not yet.

Most of this tutorial series is taken from the OpenGLAppExample provided with the Introjucer, I’m pretty much learning this stuff as I go through it – I don’t yet actually know any OpenGL, but I also don’t expect anyone to read this.

On to business

JUCE doesn’t itself include an .obj loader but the OpenGLAppExample does, so I’m going to be using that. You can find it in the source for that example – WavefrontObjParser.h – we’ll need to include that header in MainComponent.cpp and stick a private variable in there.

// private member variables
String debugMessage;
WavefrontObjFile mesh;

Loading this file is very simple, mesh has a load method which takes a File which is created from an absolute path like the ones we get from filesDropped. I’m really starting to like this.

void filesDropped(const StringArray& files, int x, int y) override
File file(files[0]);

if (mesh.load(file).wasOk())
debugMessage.append(files[0], files[0].length());
debugMessage.append("loaded \n", 1);
debugMessage.append(files[0], files[0].length());
debugMessage.append("failed to load \n", 1);


Note my debug messages changed slightly to support multi-lines, this was a simple change in the paint method.

g.drawMultiLineText(debugMessage, 20, 20, getWidth());

Seems to have worked, now to dig around in the example and draw something on screen.

Brief interlude….

10 mins..

20 mins..

I need to learn some OpenGL. =(


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s