pyobjc
pyobjc copied to clipboard
CIBevelSample doesn't work (pyobjc-framework-Quartz)
Original report by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
Uses "import CGL" and that module doesn't exist anymore...
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
Likewise for CIMicroPaint
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).
Removing version: 3.0 (automated comment)
Any suggestions on how to work around this? ie: import CGL fails?
Not at this time. This is a library I don't use myself, and definitely needs attention.
@ronaldoussoren What is the status here, or how could we help? I tried to fix it by converting the current deprecated method for CGL (inside Cocoa-Framework) initFrameworkWrapper
into the createFrameworkDirAndGetattr
format:
def _setup():
import objc
dir_func, getattr_func = objc.createFrameworkDirAndGetattr(
name="CGL",
frameworkIdentifier="com.apple.opengl",
frameworkPath=objc.pathForFramework("/System/Library/Frameworks/OpenGL.framework"),
globals_dict=globals(),
inline_list=None,
parents=(),
metadict={},
)
globals()["__dir__"] = dir_func
globals()["__getattr__"] = getattr_func
globals().pop("_setup")()
But this seems not to help. It is a real pity not be able to access CGL.CGLGetCurrentContext()
since it is needed to get the actual context. The only workaround is by finding the actual window and receiving the context from there (e.g. glfw). But this is not really a good solution tbh.
glfw_window_obj = glfw.get_current_context()
raw_nsgl_context_obj = glfw.get_nsgl_context(glfw_window_obj)
ns_open_gl_context = objc.objc_object(c_void_p=raw_nsgl_context_obj)
current_context = ns_open_gl_context.CGLContextObj()
It would be great if you could give me a hint into the direction on how to dynamically load the Core OpenGL Framework and execute the CGLGetCurrentContext()
method.
Ok, I figured it out by using pyopengl directly, but it seems that I can not convert it into a objc.PyObjCPointer
? But this is needed to pass it to the next method.
platform = OpenGL.platform.darwin.DarwinPlatform()
opengl_ctx = platform.GetCurrentContext() # int - should point to a CGLContextObj
# how to convert int to type objc.PyObjCPointer?
opengl_ctx_ptr = objc.objc_object(c_void_p=opengl_ctx) # this crashes with EXC_BAD_ACCESS (SIGSEGV)
I think the problem is that I have to convert the opengl context into a CGLContextObj
, right? However since the CGLContextObj
is defined as opaque type in GCL
, which can not be imported from pyobjc, I am a bit out of luck.
To get the current CGL context, use the following method (no need to use pyopengl
, just AppKit
):
from typing import Any
import AppKit
def get_current_cgl_context_obj() -> Any:
ns_ctx = AppKit.NSOpenGLContext.currentContext()
if ns_ctx is None:
raise Exception("Could not read current NSOpenGLContext. "
"Please first create a valid context or pass an existing one to the constructor.")
return ns_ctx.CGLContextObj()