<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 12, 2015, at 1:39 PM, David Turnbull via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">It's looking like the Epoxy requirement for SwiftGL is going away real soon now. I was able to lookup the OpenGL symbols from pure Swift code. No compiled C code is needed at all. What follows is roughly how I will do it. It lazily loads the pointer the first time you use it. The Linux version is only slightly different.<div class=""><br class=""></div><div class=""><div class="">Does anyone know a way to do this without the unsafeBitCast?<br class=""></div><div class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">import</span> Darwin</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="color:rgb(187,44,162)" class="">let</span><span style="" class=""> handle = </span><span style="color:rgb(61,29,129)" class="">dlopen</span><span style="" class="">(</span>"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"<span style="" class="">, </span><span style="color:rgb(112,61,170)" class="">RTLD_LAZY</span><span style="" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">func</span> DLOADglGetIntegerv(a:<span style="color:rgb(79,129,135)" class="">GLenum</span>, <span style="color:rgb(187,44,162)" class="">_</span> b:<span style="color:rgb(112,61,170)" class="">UnsafeMutablePointer</span>&lt;<span style="color:rgb(79,129,135)" class="">GLint</span>&gt;) -&gt; <span style="color:rgb(112,61,170)" class="">Void</span> {</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="" class="">&nbsp; &nbsp; </span>glGetIntegerv<span style="" class=""> = </span><span style="color:rgb(61,29,129)" class="">unsafeBitCast</span><span style="" class="">(</span><span style="color:rgb(61,29,129)" class="">dlsym</span><span style="" class="">(</span>handle<span style="" class="">, </span><span style="color:rgb(209,47,27)" class="">"glGetIntegerv"</span><span style="" class="">), </span>glGetIntegerv<span style="" class="">.</span><span style="color:rgb(187,44,162)" class="">dynamicType</span><span style="" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="" class="">&nbsp; &nbsp; </span>glGetIntegerv<span style="" class="">(a,b)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">public</span> <span style="color:rgb(187,44,162)" class="">var</span> glGetIntegerv:<span style="color:rgb(187,44,162)" class="">@convention</span>(c) (<span style="color:rgb(79,129,135)" class="">GLenum</span>, <span style="color:rgb(112,61,170)" class="">UnsafeMutablePointer</span>&lt;<span style="color:rgb(79,129,135)" class="">GLint</span>&gt;) -&gt; <span style="color:rgb(112,61,170)" class="">Void</span> = { <span style="color:rgb(49,89,93)" class="">DLOADglGetIntegerv</span>($0,$1) }</div></div></div></div></div></div></blockquote><br class=""></div><div>I think the unsafeBitCast is fundamentally necessary here to coerce the void pointer you get from dlsym to a C function pointer. I don't think it's a problem. This is pretty awesome!</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>