@@ -2938,7 +2938,7 @@ pg_message_box(PyObject *self, PyObject *arg, PyObject *kwargs)
2938
2938
return NULL ;
2939
2939
}
2940
2940
2941
- static PyObject * pg_gl_proc_from_address = NULL ;
2941
+ static PyObject * ctypes_functype = NULL ;
2942
2942
2943
2943
static PyObject *
2944
2944
pg_gl_get_proc (PyObject * self , PyObject * arg )
@@ -2958,17 +2958,47 @@ pg_gl_get_proc(PyObject *self, PyObject *arg)
2958
2958
#endif
2959
2959
proc_addr = SDL_GL_GetProcAddress (proc_name );
2960
2960
if (!proc_addr ) {
2961
- return RAISE (pgExc_SDLError , SDL_GetError ());
2961
+ PyErr_Format (pgExc_SDLError , "Unable to get OpenGL function '%s'" ,
2962
+ proc_name );
2963
+ return NULL ;
2962
2964
}
2963
2965
PyObject * proc_addr_obj = PyLong_FromVoidPtr (proc_addr );
2964
2966
if (!proc_addr_obj ) {
2965
2967
return NULL ;
2966
2968
}
2967
- if (!pg_gl_proc_from_address ) {
2968
- return RAISE (PyExc_TypeError , "'_proc_from_address' object is NULL" );
2969
+
2970
+ // load ctypes_functype if it's NULL
2971
+ if (!ctypes_functype ) {
2972
+ PyObject * ctypes_module = PyImport_ImportModule ("ctypes" );
2973
+ if (!ctypes_module ) {
2974
+ return NULL ;
2975
+ }
2976
+
2977
+ PyObject * ctypes_functype_factory ;
2978
+ #if defined(_WIN32 )
2979
+ // gl proc need to be called with WINFUNCTYPE (stdcall) on win32
2980
+ ctypes_functype_factory =
2981
+ PyObject_GetAttrString (ctypes_module , "WINFUNCTYPE" );
2982
+ #else
2983
+ ctypes_functype_factory =
2984
+ PyObject_GetAttrString (ctypes_module , "CFUNCTYPE" );
2985
+ #endif
2986
+ if (!ctypes_functype_factory ) {
2987
+ Py_DECREF (ctypes_module );
2988
+ return NULL ;
2989
+ }
2990
+ ctypes_functype =
2991
+ PyObject_CallOneArg (ctypes_functype_factory , Py_None );
2992
+ if (!ctypes_functype ) {
2993
+ Py_DECREF (ctypes_functype_factory );
2994
+ Py_DECREF (ctypes_module );
2995
+ return NULL ;
2996
+ }
2997
+ Py_DECREF (ctypes_functype_factory );
2998
+ Py_DECREF (ctypes_module );
2969
2999
}
2970
- PyObject * retv =
2971
- PyObject_CallFunction ( pg_gl_proc_from_address , "(O)" , proc_addr_obj );
3000
+
3001
+ PyObject * retv = PyObject_CallOneArg ( ctypes_functype , proc_addr_obj );
2972
3002
Py_DECREF (proc_addr_obj );
2973
3003
return retv ;
2974
3004
}
@@ -3101,19 +3131,6 @@ MODINIT_DEFINE(display)
3101
3131
return NULL ;
3102
3132
}
3103
3133
3104
- /* load _ffi module for display.get_gl_proc function */
3105
- PyObject * pg_ffi_module = PyImport_ImportModule ("pygame._ffi" );
3106
- if (!pg_ffi_module ) {
3107
- return NULL ;
3108
- }
3109
-
3110
- pg_gl_proc_from_address =
3111
- PyObject_GetAttrString (pg_ffi_module , "_gl_proc_from_address" );
3112
- if (!pg_gl_proc_from_address ) {
3113
- return NULL ;
3114
- }
3115
- Py_DECREF (pg_ffi_module );
3116
-
3117
3134
/* create the module */
3118
3135
module = PyModule_Create (& _module );
3119
3136
if (module == NULL ) {
0 commit comments