C ++ code with OpenGL on OSX using CGL / NSOpenGL without XCode?

I want to use CGL or NSOpenGL to create an OpenGL window without using XCode (compile with gcc command line). I am developing something that is cross platform, and I would like the code divergence to be minimal if possible! My codebase is completely C ++ at the moment. Is it even possible? I'm new to OSX and I haven't touched on target C. I went through the developer docs and took some sample files. They all use xcode. I have successfully compiled the source and linked it with the correct structure, but the whole application, xib and info.plist seems to be a little higher.

+3


source to share


5 answers


Both fltk and SDL should have enough AGL / CGL code. I have built and ran cmdline GL applications on OS X using fltk-1.3.0. However, it uses the AGL subsystem which is deprecated. SDL uses CGL and NSOpenGL for its quartz video layer:./src/video/quartz



Use obj-c flags to the compiler if you need to build src.m

, and let native g ++, llvm-g ++, clang ++ or whatever take care of the binding. You may need to add -framework CGL -framework OpenGL

as well ApplicationServices

and Cocoa

. Many answers depend on what you mean by "code divergence".

+2


source


These are the bare bones that can be obtained:



// g++ glInfo.cpp -o glInfo.x -framework OpenGL 

#include <OpenGL/OpenGL.h>
#include <OpenGL/gl3.h>
#include <stdio.h>

int main(int argc, char **argv) 
{ 
    CGLContextObj     ctx; 
    CGLPixelFormatObj pix; 
    GLint             npix; 
    CGLPixelFormatAttribute attribs[] = { 
        (CGLPixelFormatAttribute) 0
    }; 

    CGLChoosePixelFormat( attribs, &pix, &npix ); 
    CGLCreateContext( pix, NULL, &ctx ); 
    CGLSetCurrentContext( ctx ); 

    printf("Vendor:   %s\n", glGetString(GL_VENDOR)                  ); 
    printf("Renderer: %s\n", glGetString(GL_RENDERER)                ); 
    printf("Version:  %s\n", glGetString(GL_VERSION)                 ); 
    printf("GLSL:     %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); 

   return 0; 
}

      

+5


source


You can build apps without using Xcode, but if you want users who are not sys admins to use them, you will need an app package (and therefore a .plist) and (if not a game) a UI outside of that offers OpenGL. You don't need to create .xib for your user interface. You can do all of this programmatically, although using .xibs is much easier for most things. Why don't you want to use tools to help you? I'm not saying they are the best, but they only use the command line interface. (If you have an Xcode project for your application, you can create it from the command line and even automate its creation.)

0


source


Well, you can do it "manually" (I did it in NeXTStep once), but it's a pain before it works the first time. Xcode uses makefiles under the hood. You can find and accept makefiles at

  /Developer/Makefiles

      

(pre XCode 4.3) or for XCode 4.3 in

 /Applications/Xcode.app/Contents/Developer/Makefiles

      

Good luck!

0


source


For a build system, I recommend CMake / CPack, which helps you keep cross platform and build application packages. It is possible to use Obj-C ++ for NSGL, but I don't have any code.

0


source







All Articles