Reputation: 1005
I am developing static library that takes screenshots, and taking them from OpenGL applications require special handling.
When client application links to my static library it have to add frameworks used by my library, for example to take OpenGL screenshots, even if client app is not using OpenGL it have to link with OpenGLES.framework which is bad. I am trying to check in the library if client have linked with OpenGLES.framework and dynamically enable taking screenshots from OpenGL.
The problem is I get compilation error when I try to use C functions like:
if(&glReadPixels != NULL) {
glReadPixels(0, 0, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
}
As you can see, I can check for method existence, but how do I invoke it to not cause linker error? When I compile client with my library I get this:
Undefined symbols for architecture i386:
"_glReadPixels", referenced from:
+[TakeScreenshotUtil takeOpenGLScreenshotWithContext:layerSize:] in libScr-iOS.a(TakeScreenshotUtil.o)
I am trying to use
__attribute__ ((weak))
but it doesn't work (doesn't change anything).
Upvotes: 5
Views: 778
Reputation:
You can open app being executed and check if it links to OpenGL. First, recompile your app with -rdynamic (or whatever equivalent Apple's GCC understands). Then use the following code to find a function:
#import <dlfcn.h>
void (*_glReadPixels)(int, int, float, float, int, int, void *);
_glReadPixels = dlsym(NULL, "glReadPixels");
if (_glReadPixels != NULL) {
/* take screenshot */
}
Upvotes: 1
Reputation: 7065
Here is a link to a great set of code for screenshotting without using the OpenGL libraries. Even OpenGL views begin with a UIView, thus if you are doing Full Screen screenshots this should still work. http://www.icodeblog.com/2009/07/27/1188/
Also, If it is screenshots of portions of an OpenGL view that you are after, then I would suggest that you still use the code referenced above, and simply crop it down to what you need / want, else you could go down the path of getting a partial capture of the pixels within the OpenGL View. If you are doing this though, then the user of your API is already using OpenGL and thus most likely linking to the framework anyway.
Upvotes: 0