Home › Forums › Syphon › Syphon Development – Developer › All frames are being rendered black
Tagged: black screen, cgimageref, opengl
- This topic has 5 replies, 3 voices, and was last updated 5 years, 9 months ago by bangnoise.
-
AuthorPosts
-
June 10, 2015 at 6:46 am #58990JamEngulferParticipant
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.
June 10, 2015 at 7:28 am #58991vadeKeymasterHi
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!
June 10, 2015 at 8:24 am #58998JamEngulferParticipantDoes 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.
June 10, 2015 at 10:30 am #58999bangnoiseKeymasterIf 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.
June 10, 2015 at 12:45 pm #59000JamEngulferParticipantI 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
June 11, 2015 at 4:35 am #59004bangnoiseKeymasterSounds 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; }
-
AuthorPosts
- You must be logged in to reply to this topic.