Getting started with Mac OS X

Home / Support / Tutorials / Getting Started / Getting started with Mac OS X

Downloading XCode

Obtain XCode 4 from the Apple Developer website. This will require you to register an Apple ID. You can also use your existing Apple ID if you have one. After logging in you can download XCode 4 to your Mac device. The SDK comes with the XCode programming environment, Mac OS X headers and libraries, and iPhone headers and libraries in one package. When installing make sure that you have the Mac OS X SDK selected

Creating a sample project

Start XCode, and create a new project. Under Mac OS X, Application, select Cocoa Application and click next. Supply HelloWorld as the name, and nl.edgelib.samples as the company identifier. You can replace these for your own project.
Once you have the project created, remove the following files from the project: main.m (Appname)AppDelegate.h, (Appname)AppDelegate.m, and MainWindow.xib. Open (AppName)-Info.plist and clear the "Main nib file base name" property. Add a new file, select C++ File under the Mac OS X, C and C++ tab, click next, then save as Main. XCode will add a .h and .cpp file to the project.

Replace the contents of main.h and main.cpp with the following:

main.h (35 lines)
  1. //
  2. //  Main.h
  3. //  HelloWorld
  4. //  Created by Marcel Sondaar on 7/26/11.
  5. //
  6. // Copyright (c) 2017 Elements Interactive Mobile B.V.
  7. // http://www.edgelib.com
  8. //
  9.  
  10. #include "edge.h"
  11.  
  12. class ClassMain : public ClassEdge
  13. {
  14. public:
  15.     ClassMain(void);
  16.     ~ClassMain(void);
  17.     ERESULT OnFrameworkConfig(EFRAMEWORKCONFIG *config);
  18.     ERESULT OnDisplayConfig(EDISPLAYCONFIG *config);
  19.     ERESULT OnInit(ENATIVETYPE instance);
  20.     ERESULT OnMinimize(void);
  21.     ERESULT OnRestore(void);
  22.     ERESULT OnDisplayInit(ENATIVETYPE instance, ClassEDisplay *display);
  23.     void OnDisplayChange(ClassEDisplay *display);
  24.     ERESULT OnNextFrame(ClassEDisplay *display, unsigned long timedelta);
  25.     void OnExit(ENATIVETYPE instance);
  26.     void OnButtonDown(unsigned long bnr, EBUTTONLIST *blist);
  27.     void OnButtonUp(unsigned long bnr, EBUTTONLIST *blist);
  28.     void OnWheel(long direction);
  29.     void OnStylusUp(POINT pnt);
  30.     void OnStylusDown(POINT pnt);
  31.     void OnStylusDouble(POINT pnt);
  32.     void OnStylusMove(POINT pnt);
  33.     void OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer);
  34. };
  35. /
main.cpp (178 lines)
  1. //
  2. //  Main.cpp
  3. //  HelloWorld Sample
  4. //
  5. // Copyright (c) 2017 Elements Interactive Mobile B.V.
  6. // http://www.edgelib.com
  7. //
  8.  
  9. #include "Main.h"
  10.  
  11.  
  12. #include "edgemain.h"
  13.  
  14. /////////////////////////////////////////////////////////////////////
  15. // The program entry point                                         //
  16. /////////////////////////////////////////////////////////////////////
  17.  
  18. ClassEdge *EdgeMain(EDGESTARTUP *data){ return(new ClassMain); }
  19.  
  20.  
  21. /////////////////////////////////////////////////////////////////////
  22. // ClassMain: public                                               //
  23. /////////////////////////////////////////////////////////////////////
  24.  
  25. //ClassMain: constructor
  26. ClassMain::ClassMain(void)
  27. {
  28. }
  29.  
  30. //ClassMain: destructor
  31. ClassMain::~ClassMain(void)
  32. {
  33. }
  34.  
  35. //Configure framework
  36. ERESULT ClassMain::OnFrameworkConfig(EFRAMEWORKCONFIG *config)
  37. {
  38.     config->ffwdkey         = 'A';                //A key for fast forwarding (multiplies framerate by 2.5)
  39.     config->slomokey        = 'S';                //A key for slow motion     (halves framerate)
  40.     config->maxfps          = 60;                 //Limit the maximum frames per second by 60
  41.     config->flags           = 0;                  //No extra flag options
  42.     config->numconnections  = 1;                  //Keep 1 active network connection
  43. #if defined(DEVICE_GP2X)
  44.     config->smartfps    = false;              //GP2X: No smartfps needed
  45. #else
  46.     config->smartfps    = true;               //Other devices: Enable smart fps lock managing
  47. #endif
  48. #if defined(DEVICE_DESKTOP)
  49.     config->focusminimize = false;            //Desktop PC: Don't minimize the application when the focus is lost
  50. #else
  51.     config->focusminimize = true;             //Mobile devices: Minimize the application when the focus is lost
  52. #endif
  53.     config->jogtiltarrow    = true;               //Emulate the UIQ jog as left/right arrows
  54.     config->focussuspend    = true;               //Desktop PC: suspend the application when the window focus is lost
  55.     config->backlighton     = true;               //Keep backlight on
  56.     config->netlogging      = true;               //Enable logging of network events in the console
  57.     config->lockkeys        = true;               //Lock keys for use in this application
  58.     config->keysounds       = false;              //Disable key 'click' sounds for smartphones
  59.    
  60.     return(E_OK);
  61. }
  62.  
  63. //Configure display
  64. ERESULT ClassMain::OnDisplayConfig(EDISPLAYCONFIG *config)
  65. {
  66.     ClassEStd::StrCpy(config->caption, "Hello World!");
  67. #if defined(IDI_ICON1)
  68.     config->icon            = IDI_ICON1;           //Application icon
  69. #endif
  70.     config->menu            = 0;                  //Application contains no Windows Menu
  71.     config->dialogbox       = 0;                  //Don't start from dialogbox (Desktop only)
  72.     config->width           = 1024;                //Desktop PC: Custom display width
  73.     config->height          = 768;                //Desktop PC: Custom display height
  74.     config->videotype       = EDSP_DEFAULT;       //Choose the default display mode
  75.     config->emulvideotype   = EDSP_DEFAULT;       //No color depth emulation
  76.     config->orientation     = DOR_AUTO;           //Change orientation to match the settings of the device
  77.     config->openmethod      = DOM_DEFAULT;        //Take recommended (fastest) display open method
  78.     config->surfacedefault  = EST_SYSMEMORY;      //Create surfaces in system memory by default, don't use DirectDraw or Symbian bitmap surfaces
  79. #if defined(DEVICE_DESKTOP)
  80.     config->fullscreen  = false;              //Windowed application for Desktop
  81.     config->fullscreenmouse = true;           //Desktop PC: Enable the mouse cursor for fullscreen applications
  82. #else
  83.     config->fullscreen  = true;               //Fullscreen application for mobile devices
  84. #endif
  85.     config->dspnative       = true;               //If possible, try to use native blitters (like DirectDraw)
  86.     config->enginestatus    = true;               //Desktop PC: Enable the status bar and status information icon
  87.     config->engineconsole   = false;              //Desktop PC: Enable the edge console
  88.     config->surfprerotate   = true;               //Use pre-rotated surfaces to increase speed in other orientations
  89.     config->stencil      = false;          //Try to get a stencil buffer
  90.     config->emulatelowres   = 0;                  //The device is not to emulate an older device
  91.     config->supportedorientations = 0xF;//B;
  92.     return(E_OK);
  93. }
  94.  
  95. //Callback: Called before the display mode changes
  96. ERESULT ClassMain::OnInit(ENATIVETYPE instance)
  97. {
  98.     return(E_OK);
  99. }
  100.  
  101. //Callback: Called when the program minimizes
  102. ERESULT ClassMain::OnMinimize(void)
  103. {
  104.     return(E_OK);
  105. }
  106.  
  107. //Callback: Called when the program restores back from a minimized state
  108. ERESULT ClassMain::OnRestore(void)
  109. {
  110.     return(E_OK);
  111. }
  112.  
  113. //Callback: Called when the display mode has changed, use this to initialize your surfaces, etc.
  114. ERESULT ClassMain::OnDisplayInit(ENATIVETYPE instance, ClassEDisplay *display)
  115. {
  116.     return(E_OK);
  117. }
  118.  
  119. //Callback: Called when the display has been changed (because of a change in orientation)
  120. void ClassMain::OnDisplayChange(ClassEDisplay *display)
  121. {
  122. }
  123.  
  124. //Callback: Called every frame
  125. ERESULT ClassMain::OnNextFrame(ClassEDisplay *display, unsigned long timedelta)
  126. {   
  127.     display->buffer.DrawFont(2, 2, &display->fontinternal, "Hello World!");
  128.     display->buffer.DrawFont(2, display->GetHeight() - 2, &display->fontinternal, "Button/Stylus: Quit", EFX_COLORKEY | EFO_VBOTTOM);
  129.    
  130.     return(E_OK);
  131. }
  132.  
  133. //Callback: Called when the program exits
  134. void ClassMain::OnExit(ENATIVETYPE instance)
  135. {
  136. }
  137.  
  138. //Callback: Called when the user pressed a key or button
  139. void ClassMain::OnButtonDown(unsigned long bnr, EBUTTONLIST *blist)
  140. {
  141.     Quit();
  142. }
  143.  
  144. //Callback: Called when the user released a key or button
  145. void ClassMain::OnButtonUp(unsigned long bnr, EBUTTONLIST *blist)
  146. {
  147. }
  148.  
  149. //Callback: Called when the user scrolls a wheel device
  150. void ClassMain::OnWheel(long direction)
  151. {
  152. }
  153.  
  154. //Callback: Called when the user released the stylus or mouse button
  155. void ClassMain::OnStylusUp(POINT pnt)
  156. {
  157. }
  158.  
  159. //Callback: Called when the user points the stylus down or clicks the left mouse button
  160. void ClassMain::OnStylusDown(POINT pnt)
  161. {
  162.     Quit();
  163. }
  164.  
  165. //Callback: Called when the user points the stylus 2 times down quickly or double clicks the left mouse button
  166. void ClassMain::OnStylusDouble(POINT pnt)
  167. {
  168. }
  169.  
  170. //Callback: Called when the user moves the stylus while pressed down, or moves the mouse cursor
  171. void ClassMain::OnStylusMove(POINT pnt)
  172. {
  173. }
  174.  
  175. //Callback: Called when a network event occurs
  176. void ClassMain::OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer)
  177. {
  178. }

Next, we must tell XCode to build against EDGELIB. Select the project navigator on the left, click the HelloWorld label. In the main part, go to build settings, select all, and find the Header Search Paths option. Insert here the location of the edgelib header files (/path/to/edgelib/dist/include). Switch to the build phases tab, and expand the Link Binary box. Add libz.dylib, OpenGL.framework from the default list, and click Use Other to locate and add libedge.a and libedgerender.a, which can be found in the edgelib/dist/lib/macos/ folder.

Save all the changes using command+S for each edited file (modified files are shaded grey). You can then press the run button to build and start the application.

Getting started tutorials

Latest forum posts