Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: please post GLSL software rendering example



The resources pointed to by others are very valuable.  The bottom line is this is simply a renderer selection in your pixel format attribs.  You may want to also check the extensions string (a good habit to have).  These code snippets should be helpful.

CGL:

This is a simple GLSL init routine I use for tests...

int glInit (void)
{
    SInt32 osVersion = 0;
    int validEnvironment = 1;
    CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask,
           CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
           kCGLPFARendererID, kCGLRendererGenericFloatID, /* floating point software renderer */
           0 };
    CGLPixelFormatObj pixelFormat = NULL;
    long numPixelFormats = 0;

    CGLChoosePixelFormat (attribs, &pixelFormat, &numPixelFormats);
    if (pixelFormat) {
        CGLCreateContext(pixelFormat, NULL, &cglContext);
        CGLDestroyPixelFormat (pixelFormat);
        CGLSetCurrentContext (cglContext);
        /* must have these 4 extensions for GLSL support */
        if (!gluCheckExtension("GL_ARB_shader_objects", glGetString (GL_EXTENSIONS)) ||
            !gluCheckExtension("GL_ARB_vertex_shader", glGetString (GL_EXTENSIONS)) ||
            !gluCheckExtension("GL_ARB_fragment_shader", glGetString (GL_EXTENSIONS)) ||
            !gluCheckExtension("GL_ARB_shading_language_100", glGetString (GL_EXTENSIONS)))
            validEnvironment = 0;
    }
  
    if (Gestalt(gestaltSystemVersion, &osVersion) == noErr)
        printf ("system: Mac OS X v10.%ld.%ld\n", (osVersion - 0x1000) / 0x10, (osVersion - 0x1000) % 0x10);
    return validEnvironment;
}

void glDispose (void)
{
    CGLDestroyContext (cglContext);
}


Cocoa:

You need a pixel format for the float renderer:

// pixel format definition
+ (NSOpenGLPixelFormat*) floatPixelFormat
{
    NSOpenGLPixelFormatAttribute attributes [] = {
        NSOpenGLPFAWindow,
        NSOpenGLPFADoubleBuffer,    // double buffered
        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)32, // 32 bit depth buffer
        NSOpenGLPFARendererID, kCGLRendererGenericFloatID, // software renderer
        (NSOpenGLPixelFormatAttribute)nil
    };
    return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
}

and a context:

[[NSOpenGLContext alloc] initWithFormat: [GLSLView floatPixelFormat] shareContext:nil]


Carbon:  (something like...)

GLint attrib[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 32,
                   AGL_RENDERER_ID, AGL_RENDERER_GENERIC_FLOAT_ID, AGL_NONE };
aglPixFmt = aglChoosePixelFormat(NULL, 0, attrib);
if (aglPixFmt)
    aglContext = aglCreateContext(aglPixFmt, NULL);
if (aglContext) {
    aglSetDrawable(aglContext, GetWindowPort (window));
    aglSetCurrentContext(pContextInfo->aglContext);
}


Geoff Stahl
3D Software Engineer
Apple

On May 17, 2005, at 4:02 PM, email@hidden wrote:

Fellow Mac developers,

I understand it's possible to use the floating-point
software renderer to run GLSL projects. For the purpose
of learning GLSL, that's probably good enough. It seems
that the only way to create a windowed drawable area for
GLSL is by using AGL. Unfortunately, I don't know AGL and
the documentation in the ADC Reference Library is no good
as a tutorial. I couldn't find any tutorials on the Internet
either. Could somebody please post source code snippets, or
a packaged Xcode project, demonstrating the creation of a
GLSL-capable OpenGL context and drawable area.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden

References: 
 >please post GLSL software rendering example (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.