Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 command line gcc). I am developing something that is cross platform, and I'd like to keep the code divergence to a minimum if I can! My codebase is fully C++ at the moment. Is this at all possible? I am new to OSX and I haven't touched objective C. I looked through the developer docs and grabbed some example files. They are all using xcode. I successfully compiled the source and linked with the right framework, but the whole app bundle, xib, and info.plist thing seems a bit over the top.

like image 302
mightcouldb1 Avatar asked Oct 17 '25 07:10

mightcouldb1


1 Answers

This is bare-bones as one can get:

// 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; 
}
like image 198
Michaelangel007 Avatar answered Oct 18 '25 22:10

Michaelangel007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!