[Tutorial] Getting started on Mac OS X

A forum to store posts deemed exceptionally wise and useful
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Try to start it from the command line, and check what the console prints. I guess the paths are wrong.
Fareusel
Posts: 5
Joined: Mon Apr 20, 2009 12:48 pm

Post by Fareusel »

Well, it's getting quite more confusing:


It really seems to be a problem of finding the resource-files.
I tested three ways of starting the program:

--------------------------------------------------------------------------------------------
1st way: Terminal
The terminal says, that it cannot load the mesh (../Resources/sydney.md2) because the file could not be opend and leave me with a blank window.
--------------------------------------------------------------------------------------------
2nd way: Xcode
Starting the program with "Build&Run" out of Xcode, there is no terminal window (printf's are simply ignored?), the mesh loads up and is displayed but without any texture (white).
--------------------------------------------------------------------------------------------
3rd way: Double-click on the app in the Finder
Like the terminal method it gives a blank Irrlicht-window to me, but without the error messages in the terminal window.
--------------------------------------------------------------------------------------------

The most confusing fact at this problem is following:
As my app-file is a normal OS X Application, it is a package. If I open this package in the finder, I get the following file structur:

Code: Select all

Irrlicht-Konfigurationstest.app                  <Mac OS X Application File>
|
|__+ Contents                                    <Folder>
     |
     |___ Info.plist                             <Property List>
     |
     |__+ MacOS                                  <Folder>
     |     |
     |     |__ Irrlicht-Konfigurationstest       <Executable>
     |
     |__PkgInfo                                  <Plain Text>
     |
     |__+ Resources                              <Folder>
          |
          |__ sydney.md2                         <MD2 Mesh>
          |
          |__ sydney.bmp                         <Windows/OS2 Bitmap>
          |
          |__ ... (other resources)              <some other files>
So "Irrlicht-Konfigurationstest.app" is my OS X appication, and therein "Irrlicht-Konfigurationstest" (in the MacOS folder) is the actual runable programfile. That's also the one I have to run in the terminal.

As you can see, the path "../Resources/sydney.md2" should be quite correct, reffering to my executable file in "MacOS".

I really don't understand what is wrong with it? Can anyone tell me what I am doing wrong? And why are there two ways of behaviour? If i start the program by clicking the build&run button in Xcode, the mesh is loaded correctly but without texture. If I start the program in the terminal or finder, nothing is loaded at all!?

:/ quite confusing!
Fareusel
Posts: 5
Joined: Mon Apr 20, 2009 12:48 pm

Post by Fareusel »

Hi,

ok, well, I've got a solution for loading files out of the application bundle, but the mesh is still white!

I took some Mac OS X-specific code (CFBundle) and loaded my resources from the bundle. My Sourcecode is now the following:

Code: Select all

#include <OpenGL/OpenGL.h>
#include <Carbon/Carbon.h>
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFString.h>
#include <irrlicht.h>
#include <iostream>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "libIrrlicht.a")

// function provides some Mac OS X specific source code to load files from the resources of the application bundle.
char * resPath(char **argv, char* name, char* type ) 
{
	char resource[1024];
	
	CFURLRef cfBundleURL = CFBundleCopyResourceURL( CFBundleGetMainBundle(),	 
												   CFStringCreateWithCString(kCFAllocatorDefault,
																			 name, 
																			 kCFStringEncodingISOLatin1), 
												   CFStringCreateWithCString(kCFAllocatorDefault, 
																			 type, 
																			 kCFStringEncodingISOLatin1), 
												   NULL );
	
	
	CFStringGetCString( CFURLCopyPath(cfBundleURL),
					   resource,
					   1023,
					   kCFStringEncodingISOLatin1);
	
	return resource;
}

int main(int argc, char** argv)
{
	IrrlichtDevice *device = createDevice(EDT_OPENGL, 
										  dimension2d<s32>(512, 384), 
										  16,
										  false, 
										  false, 
										  false, 
										  0);
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
	
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	
	IAnimatedMesh* mesh = smgr->getMesh( resPath(argv, "sydney", "md2") );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
	
	if (node) 
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setFrameLoop(0, 310);
		
		// -- PROBLEM -- Irrlicht still displays just a white mesh without texture!
		node->setMaterialTexture( 0, driver->getTexture( resPath(argv, "sydney", "bmp") ));
	}
	
	smgr->addCameraSceneNode(0, 
							 vector3df(0,30,-40), 
							 vector3df(0,5,0));
	
	while(device->run()) 
	{
		driver->beginScene(true, 
						   true, 
						   SColor(255,100,101,140));
		smgr->drawAll();
		driver->endScene();
	}
	
	device->drop();
	return 0;
}
The Terminal says "Mesh loaded" and "Texture Loaded". The only problem is, that there is not texture loaded! -.-

still a white mesh.

what should I do?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If the console tells you the texture was loaded it's ok. Maybe it's a problem with the OpenGL driver, problematic/broken support of NPOT?
Fareusel
Posts: 5
Joined: Mon Apr 20, 2009 12:48 pm

Post by Fareusel »

Cool, that was the point: My ATI Radeon X1600 doesn't support NPOT =)
thank you very much, resizing the texture file works! yeah!
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Fareusel, do you have a copy of Zathras' tutorial? The link posted here:
http://www.ruthless.zathras.de/facts/ap ... on-mac.php
seems to be dead. I'm really interested in checking how he setup things to compile a new project.

I've also added everything as described here but without any success, so any extra info will come in handy ;)

regards,
Alvaro

ps. If anyone else has got a copy of this tutorial, please post it here :D
Image
Ven
Posts: 1
Joined: Thu Dec 31, 2009 12:12 pm
Location: Athens

Post by Ven »

at first sorry for bumping this old topic.
i followed the tutorial, with some necessary changes and my project is compiling, giving me a static grey screen and freezing my mouse cursor till i fquit the app., instead of displaying the obj. i was expecting.
anyone experience the same problem - has a possible solution?
forgot to add, i am running xcode 3.2.1 on snow leopard.
thanks a lot
ecsos
Posts: 30
Joined: Mon Feb 04, 2008 8:02 am

Post by ecsos »

If you just drag jpeg into your project, it ends up in the Resources folder once you build and run. Hence why the Resources folder should be included in the default folder archives. Bitplane was supposed to have added this already. You shouldn't need a special function resPath or have to specify a path to the resources folder.
zevarito
Posts: 1
Joined: Sun Jun 17, 2007 10:05 pm

I cannot run the examples on OSX

Post by zevarito »

Hi,

I am trying to get the examples work without success, I can compile the lib and the examples but when try to run it nothing happen, the shell don't log nothing so I have not idea of what is happening, I am new on Xcode so may be I am missing something, any help?

OSX 10.6.4 Xcode 3.2.2

thanks!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The problem is usually that the console does not start for the examples when run from within XCode. You need to start the apps fromt he console manually, or change the driver choice to return OpenGL without interaction.
jokoon
Posts: 17
Joined: Sun Aug 30, 2009 9:17 am

Post by jokoon »

I'm really begging for someone to redo this short howto, Xcode has changed a lot of its interface, and irrlicht has changed also...
jpenguin
Posts: 10
Joined: Mon Feb 16, 2009 7:48 pm

Post by jpenguin »

I'm still trying to get it to work, bu I found one-

http://karlkirch.com/blog/2010/03/10/irrlicht-xcode/
JamesMoon
Posts: 6
Joined: Fri Aug 26, 2011 4:23 am

Re: [Tutorial] Getting started on Mac OS X

Post by JamesMoon »

Hello.. osxus3r

Are you still in this forum?..

It's been several years since you have posted this thread.

I hope you to write again for iPad app in Xcode 4 or Xcode 3.2.6 ..

There are quite much needs for simple and fast 3d engine in iOS programming.

Regards
Carnafex
Posts: 15
Joined: Wed Sep 05, 2007 1:32 am
Location: Sydney, Australia

Re: [Tutorial] Getting started on Mac OS X

Post by Carnafex »

Heya everyone,

Thought I would just post the steps I used to get a new project up in XCode 4.1, seeing how its substantially different from the older version!
Note that I had to compile irrlicht myself to get the static library first before I could do this. (I managed to compile it from 1.7.2 base, check out http://irrlicht.sourceforge.net/forum/v ... =1&t=44736

Anyway to start:
  1. Create a new empty project.
  2. Add a target. (You can do this by left clicking the project file in the tree menu on the left, then look for a circle with a plus at the bottom of the window)
    • Select Max OS X > Application > Cocoa Application
  3. Now delete the *AppDelegate.m, *AppDelegate.h and *.xib file, you wont need these.
  4. Now create a new file
    • I usually select Mac OS X > C and C++ > C++ File. I also usually fill it with the Example 1 tutorial to get the app compiling with some output to start.
  5. Now click on the project in the left tree menu again
  6. In the central part of the screen, click "Build Settings", and change the following settings:
    1. Base SDK: Standard (32/64 bit intel)
    2. Base SDK: Latest Mac OS X
    3. Compiler for C/C++/Objective-C: LLVM GCC 4.2
    4. Header Search Paths: /Path/To/Your/Irrlicht/Folder/include
  7. Now select "Build Phases"
    1. Under "Link Binary With Libraries, click the plus and add Cocoa, Carbon, IOKit, OpenGL, and the libIrrlicht.a file.
    2. under "Compile Sources", select the 'main.m' and then delete the main.m file
  8. Compile!
Hopefully this will help some people get started!
champialex
Posts: 1
Joined: Mon Feb 11, 2013 11:05 am

Re: [Tutorial] Getting started on Mac OS X

Post by champialex »

Hi, I have been struggling for a a little while to find out the right command to compile an irrlicht file from command line once installed using the tutorial [1]. So I figured I would share it :

Code: Select all

 
g++ -o MyApp.app/Contents/MacOS/MyApp myfile.cpp -fvisibility=hidden -lirrlicht -framework Foundation -framework OpenGL -framework Cocoa -framework Carbon -framework AppKit -framework IOKit
 
Packaging it as a MacOS app avoid trouble with catching keyboard input.
You must of course have created the folder MyApp.app/Contents/MacOS beforehand

Hope it helps some people.
I think I would be nice to have this on the front page.


[1] http://irrlicht3d.org/wiki/index.php?n= ... uildMacOSX
Post Reply