All frames are being rendered black

Home Forums Syphon Syphon Development – Developer All frames are being rendered black

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #58990
    JamEngulfer
    Participant

    I’m trying to render a frame from a CGImageRef, but no matter what I do, it’s coming out as black.

    I’m not rendering it in a GL view, I’m trying to render it offscreen. I wonder if the context I’ve created for it is bad or something. I created the context as so:

    CGLPixelFormatAttribute attribs[13] = {
            kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, // This sets the context to 3.2
            kCGLPFAColorSize,     (CGLPixelFormatAttribute)24,
            kCGLPFAAlphaSize,     (CGLPixelFormatAttribute)8,
            kCGLPFAAccelerated,
            kCGLPFADoubleBuffer,
            kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1,
            kCGLPFASamples,       (CGLPixelFormatAttribute)4,
            (CGLPixelFormatAttribute)0
        };
        
        CGLPixelFormatObj pix;
        GLint npix;
        CGLChoosePixelFormat(attribs, &pix, &npix);
    
        CGLCreateContext(pix, 0, &_ctx);

    My rendering code is in a different class, so I passed the context to it with

    My render code is passed a CGImageRef as the ‘image’ parameter and tries to render it as such:

    NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:image];
        
        CGLSetCurrentContext(cgl_ctx);
        CGLLockContext(cgl_ctx);
        
        if (_texture) {
            glDeleteTextures(1, &_texture);
        }
        
        glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
        
        int width = 1920;
        int height = 1080;
        
        glEnable(GL_TEXTURE_RECTANGLE_EXT);
        glGenTextures(1, &_texture);
        glBindTexture(GL_TEXTURE_RECTANGLE_EXT, _texture);
        
        glPixelStorei(GL_UNPACK_ROW_LENGTH, [imageRep bytesPerRow] / [imageRep samplesPerPixel]);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
        
        glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [imageRep bitmapData]);
        
        glFlushRenderAPPLE();
    
        CGLUnlockContext(cgl_ctx);

    I’ve followed every single piece of advice relating to this topic and NOTHING has worked. Each time I try, the published frame is still black.

    #58991
    vade
    Keymaster

    Hi

    Thanks for the detailed question.

    So, right now you are making a kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, // This sets the context to 3.2

    Which the stock Syphon Server does not handle. There are forks of Syphon which handle OpenGL Core Profile.

    Apologies, we’ve been slow to uptake Core Profile because many of the Host Apps and underlying technology hasn’t moved to it (Core Image, Core Video) – and plus were lazy and don’t get paid to do this, haha.

    See this:

    https://github.com/Syphon/Syphon-Framework/issues/13

    Thanks, and sorry stock Syphon doesnt handle that for you. We should get on that asap!

    #58998
    JamEngulfer
    Participant

    Does that mean that I have to use one of the forked frameworks, or can I do something else to make my rendering code compatible with Syphon?

    I see in the ‘Simple Server’ application that you get the context from the NSOpenGLView object in the UI. Is there a way to emulate that context?

    Sorry if I’m asking dumb questions, I’ve just never dealt with OpenGL or anything like it before.

    #58999
    bangnoise
    Keymaster

    If you don’t need the new features of OpenGl 3.2 then removing the kCGLPFAOpenGLProfile line should give you a legacy context which will work with stock Syphon.

    #59000
    JamEngulfer
    Participant

    I removed that line and still nothing changed. The server can be detected by the ‘Simple Client’ demo, so I know that part is working. I’m wondering if I’m sending the context incorrectly or something. I’m passing it to each class with:

    - (id)initWithContext:(CGLContextObj)context {
        cgl_ctx = CGLRetainContext(context);
        return self;
    }

    Can I just set it as a normal variable?

    I’m wondering if any of my actual rendering code is wrong, but it seems to match up with all of the recommended code for doing this sort of thing.

    Turns out, I was passing the context in the wrong order and I passed a null context to my renderer. *facedesk* *facedesk* *facedesk*.

    It’s now showing, but it’s upside down and only in red, but it’s a start.

    • This reply was modified 5 years, 9 months ago by JamEngulfer. Reason: Me being dumb
    #59004
    bangnoise
    Keymaster

    Sounds like you’re getting there – just as a note, an init method should always call it’s superclass’s init method, for example

    - (id)initWithContext:(CGLContextObj)context {
        self = [super init]; // Assuming super is NSObject
        if (self) {
            cgl_ctx = CGLRetainContext(context);
        }
        return self;
    }
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.