Recursos NSOpenglContext, procesamiento incorrecto

I'm having trouble to get NSOpenGLContext working. I have a static object (3D engine) that handle all the opengl stuff, resources , vbos etc..

For the cocoa version, i create a NSOpenGLContext like this :

- (BOOL) CreateContext
{
    [NSOpenGLContext clearCurrentContext];

    NSOpenGLPixelFormatAttribute attributes [] =
    {
    NSOpenGLPFAWindow,
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFAAccelerated,         // If present, this attribute indicates that only hardware-accelerated renderers are considered.
    NSOpenGLPFAPixelBuffer,         // If present, this attribute indicates that rendering to a pixel buffer is enabled.
    NSOpenGLPFAColorSize, 32,
    NSOpenGLPFADepthSize, 24,
    NSOpenGLPFAStencilSize, 8,
    (NSOpenGLPixelFormatAttribute)nil
    };

    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    NSOpenGLContext* pContext =  [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext:nil];

    if (pContext)
    {
        [pContext makeCurrentContext];
        m_pOGLContext = pContext;

        // Vertical Sync
        GLint vblSynch = 0; // disable vsync
        [pContext setValues:&vblSynch forParameter:NSOpenGLCPSwapInterval];

        glFrontFace(GL_CW);

        // Set the clear Color
        glClearColor(0, 0, 0, 0);

        [pixelFormat release];
        return true;
    }

    [pixelFormat release];

    return false;
}

After the engine initialization, I create an NSView. After the NSView creation, in the prepareOpenGL func, i just set the NSOpenGLContext member to the current NSOpenGLContext from the engine :

- (void) prepareOpenGL
{
    m_pOGLContext = [NSOpenGLContext currentContext];
    return;
}

Then, in the function lockFocus of the NSView i set the view for the context :

- (void)lockFocus
{   
    [super lockFocus];

    if ([m_pOGLContext view] != self)
    {
        [m_pOGLContext setView:self];
    }

    [m_pOGLContext makeCurrentContext];
}

Now, when drawing i can't get resources to be drawn, i just have a lot of buffer artifacts.

I tried to create a second Context for the NSView, with the sharing option, but i have the same result.

preguntado el 28 de agosto de 12 a las 13:08

Did you flush the buffer using the "mac way"? I don't think that glFlush() worked for me before and I had to use NSOpenGLContext's flushBuffer. -

Hi, glflush is working for me, in fact the first time i use the static context, it's ok. The problem happen when i destroy the view en create an other one which use the static context again. -

1 Respuestas

Not sure, I'm a beginner too but I think that the format is wrong, it should be:

NSOpenGLPixelFormatAttribute attributes [] =
{
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,         // If present, this attribute indicates that only hardware-accelerated renderers are considered.
NSOpenGLPFAPixelBuffer,         // If present, this attribute indicates that rendering to a pixel buffer is enabled.
NSOpenGLPFAColorSize, 
NSOpenGLPFADepthSize, 
NSOpenGLPFAStencilSize, 
32,24,8,
(NSOpenGLPixelFormatAttribute)nil
};

Respondido el 03 de diciembre de 12 a las 17:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.