I recently get a mac book pro with a openGL 3.3 capable nvidia graphics card
When using the glfw3 library, I successfully load OpenGL extensions via the glfwGetProcAddress()
However I would like to use the OpenGLGadget...
Anyone knows the simplest way to load specific OpenGL extension on MacOSX from PureBasic?
OpenGL Extensions with OpenGLGadget
-
- User
- Posts: 27
- Joined: Thu Mar 14, 2013 11:24 am
- Location: paris
- Contact:
Re: OpenGL Extensions with OpenGLGadget
You might try dlsym_ with #RTLD_DEFAULT
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
-
- User
- Posts: 27
- Joined: Thu Mar 14, 2013 11:24 am
- Location: paris
- Contact:
Re: OpenGL Extensions with OpenGLGadget
Thanks! It works
I also found that on MacOS extensions can be loaded directly
I also found that you're restricted to OpenGL 2.1 Context and GLSL1.2
So I had to modify my simple shader
(vertex shader)
from
to
(fragment shader)
from
to
But both lead to unpredictables results(flickering geometries)
Code: Select all
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
ImportC "-lGL"
glXGetProcAddress(s.p-ascii) As "glXGetProcAddress"
EndImport
Macro setGLEXT(var, extname)
var = glXGetProcAddress(extname)
EndMacro
CompilerCase #PB_OS_Windows
ImportC "opengl32.lib"
wglGetProcAddress(s.p-ascii) As "wglGetProcAddress"
EndImport
Macro setGLEXT(var, extname)
var = wglGetProcAddress(extname)
EndMacro
CompilerCase #PB_OS_MacOS
Macro setGLEXT(var, extname)
var = dlsym_(#RTLD_DEFAULT,extname)
EndMacro
CompilerEndSelect
Code: Select all
Global macosx_gl_lib = OpenLibrary(#PB_Any,"/System/Library/Frameworks/OpenGL.framework/OpenGL")
...
Macro setGLEXT(var, extname)
var = GetFunction(macosx_gl_lib,extname)
EndMacro
...
CloseLibrary
So I had to modify my simple shader
(vertex shader)
from
Code: Select all
#version330
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
in vec3 position;
void main(){
vec3 p = vec3(view * model * vec4(position,1.0));
gl_Position = projection * vec4(p,1.0);
}
Code: Select all
#version 120
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
varying vec3 position;
void main(){
vec3 p = vec3(view * model * vec4(position,1.0));
gl_Position = projection * vec4(p,1.0);
}
from
Code: Select all
#version 330
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
Code: Select all
#version 120
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
Re: OpenGL Extensions with OpenGLGadget
You should be able to use the OpenGL 3.2 Core Profile on OSX with glutInitDisplayMode but I don't know if it works with PureBasic.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
-
- User
- Posts: 27
- Joined: Thu Mar 14, 2013 11:24 am
- Location: paris
- Contact:
Re: OpenGL Extensions with OpenGLGadget
the error was in the vertex shader(#version 120)
I wrote
It is
I successfully use VAOs, VBOs, GLSL program in an OpenGLGadget with MacOSX ElCapitan
One trick to note for using VAOs
I wrote
Code: Select all
varying vec3 position
Code: Select all
attribute vec3 position
One trick to note for using VAOs
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS And Not #USE_GLFW
setGLEXT( glBindVertexArray, "glBindVertexArrayAPPLE")
setGLEXT( glDeleteVertexArrays, "glDeleteVertexArraysAPPLE")
setGLEXT( glGenVertexArrays, "glGenVertexArraysAPPLE")
CompilerElse
setGLEXT( glBindVertexArray, "glBindVertexArray")
setGLEXT( glDeleteVertexArrays, "glDeleteVertexArrays")
setGLEXT( glGenVertexArrays, "glGenVertexArrays")
CompilerEndIf