Global.b glextimp_errors Global.s glextimp_error_string CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Windows ;{ Windows Macro glextimp_Prototype : Prototype : EndMacro Macro glextimp_GetProcAddress(Prototype, function, function_name) Global.Prototype function = wglGetProcAddress_(function_name) If Not function Define.s glextimp_error = "glextimp_GetProcAddress : error " + function_name + " does not exist" : Debug glextimp_error glextimp_error_string + glextimp_error + #CRLF$ glextimp_errors + 1 EndIf EndMacro #WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = $00000002 #WGL_CONTEXT_MAJOR_VERSION_ARB = $2091 #WGL_CONTEXT_MINOR_VERSION_ARB = $2092 #WGL_CONTEXT_FLAGS_ARB = $2094 ; No more needed (seen in PB 5.44) ;Import "opengl32.lib" ;;from luis reply http://purebasic.fr/english/viewtopic.php?f=13&t=45687&start=15#p446875 ;CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86) ; wglGetProcAddress_(s.p-ascii) As "_wglGetProcAddress@4" ;CompilerElse ; wglGetProcAddress_(s.p-ascii) As "wglGetProcAddress" ;CompilerEndIf ;EndImport Prototype PFNwglCreateContextAttribsPROC (hDC.i, hShareContext.i, *attribList) ;Global.PFNwglCreateContextAttribsPROC wglCreateContextAttribsARB = wglGetProcAddress_("wglCreateContextAttribsARB") ;} CompilerCase #PB_OS_MacOS ;{ MacOS Macro glextimp_Prototype : PrototypeC : EndMacro Macro glextimp_GetProcAddress(Prototype, function, function_name) Global.Prototype function = GetFunction(glextimp_hOpenGLlib, function_name) If Not function Define.s glextimp_error = "glextimp_GetProcAddress : error " + function_name + " does not exist" : Debug glextimp_error glextimp_error_string + glextimp_error + #CRLF$ glextimp_errors + 1 EndIf EndMacro ;ImportC "/System/Library/Frameworks/OpenGL.framework/OpenGL" ;Global.i glextimp_hOpenGLlib = OpenLibrary(#PB_Any, "/System/Library/Frameworks/OpenGL.framework/OpenGL") ;} CompilerCase #PB_OS_Linux ;{ Linux ;ImportC "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL" ImportC "/usr/lib/x86_64-linux-gnu/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL" EndImport ImportC "/usr/lib/libGLU.a" EndImport ;ImportC "/usr/lib/libX11.a" ImportC "/usr/lib/x86_64-linux-gnu/libX11.a" EndImport ;ImportC "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL" ImportC "/usr/lib/x86_64-linux-gnu/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL" EndImport ImportC "GL" ;} CompilerEndSelect ; CompilerIf #PB_Compiler_OS <> #PB_OS_MacOS ; ; glGenBuffers(n.i, *buffers) ; glBindBuffer(target.i, buffer.i) ; glBufferData(target.i, size.i, *data, usage.i) ; glBufferSubData(target.i, offset.i, size.i, *data) ; glMapBuffer(target.i, access.i) ; glUnmapBuffer(target.i) ; glEnableVertexAttribArray(index.i) ; glVertexAttribPointer(index.i, size.i, type.i, normalized.b, stride.i, *pointer) ; glCreateShader(type.i) ; glShaderSource(shader.i, count.i, *stringBuffer, *length) ; glCompileShader(shader.i) ; glCreateProgram() ; glAttachShader(program.i, shader.i) ; glGetShaderInfoLog(shader.i, maxLength.i, *length.integer, *infoLog.ascii) ; glLinkProgram(program.i) ; glUseProgram(program.i) ; glGetUniformLocation(program.i, name.p-ascii) ; glUniformMatrix4fv(location.i, count.i, transpose.b, *value) ; ; ; OpenGL 3.3 : Not supported on WindowsXP and MacOS Snow Leopard ; glGenVertexArrays(n.i, *ids.integer) ; glBindVertexArray(id.i) ; glDeleteVertexArrays(n.i, *buffers) ; ; EndImport ; ; CompilerElse ;{ Prototypes glextimp_Prototype PFNGLGENBUFFERSPROC (n.l, *buffers) glextimp_Prototype PFNGLBINDBUFFERPROC (target.l, buffer.l) glextimp_Prototype PFNGLBUFFERDATAPROC (target.l, size.i, *data, usage.l) glextimp_Prototype PFNGLBUFFERSUBDATAPROC (target.l, offset.i, size.i, *data) glextimp_Prototype PFNGLMAPBUFFERPROC (target.l, Access.l) glextimp_Prototype PFNGLUNMAPBUFFERPROC (target.l) glextimp_Prototype PFNGLDELETEBUFFERSPROC (n.l, *buffers) glextimp_Prototype PFNGLENABLEVERTEXATTRIBARRAYPROC (index.l) glextimp_Prototype PFNGLVERTEXATTRIBPOINTERPROC (index.l, size.l, type.l, normalized.b, stride.l, *pointer) ;glextimp_Prototype PFNGLVERTEXATTRIBI1IPROC (index.l, v.l) ;glextimp_Prototype PFNGLVERTEXATTRIB1FPROC (index.l, v0.f) glextimp_Prototype PFNGLVERTEXATTRIB4FVPROC (index.l, *v.Float) glextimp_Prototype PFNGLVERTEXATTRIB4FPROC (index.l, v0.f, v1.f, v2.f, v3.f) glextimp_Prototype PFNGLVERTEXATTRIB3FVPROC (index.l, *v.Float) glextimp_Prototype PFNGLVERTEXATTRIB3FPROC (index.l, v0.f, v1.f, v2.f) glextimp_Prototype PFNGLCREATESHADERPROC (type.l) glextimp_Prototype PFNGLSHADERSOURCEPROC (shader.l, count.l, *string, *length) glextimp_Prototype PFNGLCOMPILESHADERPROC (shader.l) glextimp_Prototype PFNGLATTACHSHADERPROC (program.l, shader.l) glextimp_Prototype PFNGLDETACHSHADERPROC (program.l, shader.l) glextimp_Prototype PFNGLDELETESHADERPROC (shader.l) glextimp_Prototype PFNGLGETSHADERIVPROC (shader.l, pname.l, *params) glextimp_Prototype PFNGLGETSHADERINFOLOGPROC (shader.l, maxLength.l, *length, *infoLog) glextimp_Prototype PFNGLLINKPROGRAMPROC (program.l) glextimp_Prototype PFNGLCREATEPROGRAMPROC () glextimp_Prototype PFNGLUSEPROGRAMPROC (program.l) glextimp_Prototype PFNGLGETPROGRAMIVPROC (program.l, pname.l, *params) glextimp_Prototype PFNGLDELETEPROGRAMPROC (program.l) glextimp_Prototype PFNGLBINDATTRIBLOCATIONPROC (program.l, index.l, *name) ;.p-ascii) ; Plante en 64 bits ! glextimp_Prototype PFNGLDISABLEVERTEXATTRIBARRAYPROC (index.l) glextimp_Prototype PFNGLGETUNIFORMLOCATIONPROC (program.l, name.p-ascii) glextimp_Prototype PFNGLUNIFORM1IPROC (location.l, v0.l) glextimp_Prototype PFNGLUNIFORM1FPROC (location.l, v0.f) glextimp_Prototype PFNGLUNIFORM3FPROC (location.l, v0.f, v1.f, v2.f) glextimp_Prototype PFNGLUNIFORMMATRIX4FVPROC (location.l, count.l, transpose.b, *value) glextimp_Prototype PFNGLACTIVETEXTUREPROC (Texture.l) ; OpenGL 3.3 : Not supported on WindowsXP and MacOS Snow Leopard glextimp_Prototype PFNGLGENVERTEXARRAYSPROC (n.l, *arrays) glextimp_Prototype PFNGLBINDVERTEXARRAYPROC (Array.l) glextimp_Prototype PFNGLDELETEVERTEXARRAYSPROC (n.l, *arrays) glextimp_Prototype PFNGLGENRENDERBUFFERSPROC (n.l, *renderbuffers) glextimp_Prototype PFNGLBINDRENDERBUFFERPROC (target.l, renderbuffer.l) glextimp_Prototype PFNGLRENDERBUFFERSTORAGEPROC (target.l, internalformat.l, width.l, height.l) glextimp_Prototype PFNGLDELETERENDERBUFFERSPROC (n.l, *renderbuffers) glextimp_Prototype PFNGLGENFRAMEBUFFERSPROC (n.l, *ids) glextimp_Prototype PFNGLBINDFRAMEBUFFERPROC (target.l, framebuffer.l) glextimp_Prototype PFNGLFRAMEBUFFERTEXTURE2DPROC (target.l, attachment.l, textarget.l, texture.l, level.l) glextimp_Prototype PFNGLFRAMEBUFFERRENDERBUFFERPROC (target.l, attachment.l, renderbuffertarget.l, renderbuffer.l) glextimp_Prototype PFNGLCHECKFRAMEBUFFERSTATUSPROC (target.l) glextimp_Prototype PFNGLDELETEFRAMEBUFFERSPROC (n.l, *framebuffers) ;} Procedure.b glextimp_Init() CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Windows ;{ Windows ;} CompilerCase #PB_OS_MacOS ;{ MacOS Global.i glextimp_hOpenGLlib = OpenLibrary(#PB_Any, "/System/Library/Frameworks/OpenGL.framework/OpenGL") If Not glextimp_hOpenGLlib : ProcedureReturn #False : EndIf ;} CompilerCase #PB_OS_Linux ;{ Linux ;} CompilerEndSelect glextimp_GetProcAddress(PFNGLGENBUFFERSPROC, glGenBuffers, "glGenBuffers") glextimp_GetProcAddress(PFNGLBINDBUFFERPROC, glBindBuffer, "glBindBuffer") glextimp_GetProcAddress(PFNGLBUFFERDATAPROC, glBufferData, "glBufferData") glextimp_GetProcAddress(PFNGLBUFFERSUBDATAPROC, glBufferSubData, "glBufferSubData") glextimp_GetProcAddress(PFNGLMAPBUFFERPROC, glMapBuffer, "glMapBuffer") glextimp_GetProcAddress(PFNGLUNMAPBUFFERPROC, glUnmapBuffer, "glUnmapBuffer") glextimp_GetProcAddress(PFNGLDELETEBUFFERSPROC, glDeleteBuffers, "glDeleteBuffers") glextimp_GetProcAddress(PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray, "glEnableVertexAttribArray") glextimp_GetProcAddress(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer, "glVertexAttribPointer") ; glextimp_GetProcAddress(PFNGLVERTEXATTRIBI1IPROC, glVertexAttribI1i, "glVertexAttribI1i") ; glextimp_GetProcAddress(PFNGLVERTEXATTRIB1FPROC, glVertexAttrib1f, "glVertexAttrib1f") glextimp_GetProcAddress(PFNGLVERTEXATTRIB4FVPROC, glVertexAttrib4fv, "glVertexAttrib4fv") glextimp_GetProcAddress(PFNGLVERTEXATTRIB4FPROC, glVertexAttrib4f, "glVertexAttrib4f") glextimp_GetProcAddress(PFNGLVERTEXATTRIB3FVPROC, glVertexAttrib3fv, "glVertexAttrib3fv") glextimp_GetProcAddress(PFNGLVERTEXATTRIB3FPROC, glVertexAttrib3f, "glVertexAttrib3f") glextimp_GetProcAddress(PFNGLCREATESHADERPROC, glCreateShader, "glCreateShader") glextimp_GetProcAddress(PFNGLSHADERSOURCEPROC, glShaderSource, "glShaderSource") glextimp_GetProcAddress(PFNGLCOMPILESHADERPROC, glCompileShader, "glCompileShader") glextimp_GetProcAddress(PFNGLATTACHSHADERPROC, glAttachShader, "glAttachShader") glextimp_GetProcAddress(PFNGLDETACHSHADERPROC, glDetachShader, "glDetachShader") glextimp_GetProcAddress(PFNGLDELETESHADERPROC, glDeleteShader, "glDeleteShader") glextimp_GetProcAddress(PFNGLGETSHADERIVPROC, glGetShaderiv, "glGetShaderiv") glextimp_GetProcAddress(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog, "glGetShaderInfoLog") glextimp_GetProcAddress(PFNGLLINKPROGRAMPROC, glLinkProgram, "glLinkProgram") glextimp_GetProcAddress(PFNGLCREATEPROGRAMPROC, glCreateProgram, "glCreateProgram") glextimp_GetProcAddress(PFNGLUSEPROGRAMPROC, glUseProgram, "glUseProgram") glextimp_GetProcAddress(PFNGLGETPROGRAMIVPROC, glGetProgramiv, "glGetProgramiv") glextimp_GetProcAddress(PFNGLDELETEPROGRAMPROC, glDeleteProgram, "glDeleteProgram") glextimp_GetProcAddress(PFNGLBINDATTRIBLOCATIONPROC, glBindAttribLocation, "glBindAttribLocation") glextimp_GetProcAddress(PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVertexAttribArray, "glDisableVertexAttribArray") glextimp_GetProcAddress(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation, "glGetUniformLocation") glextimp_GetProcAddress(PFNGLUNIFORM1IPROC, glUniform1i, "glUniform1i") glextimp_GetProcAddress(PFNGLUNIFORM1FPROC, glUniform1f, "glUniform1f") glextimp_GetProcAddress(PFNGLUNIFORM3FPROC, glUniform3f, "glUniform3f") glextimp_GetProcAddress(PFNGLUNIFORMMATRIX4FVPROC, glUniformMatrix4fv, "glUniformMatrix4fv") glextimp_GetProcAddress(PFNGLACTIVETEXTUREPROC, glActiveTexture, "glActiveTexture") ; OpenGL 3.3 : Not supported in WindowsXP and MacOS Snow Leopard glextimp_GetProcAddress(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays, "glGenVertexArrays") glextimp_GetProcAddress(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray, "glBindVertexArray") glextimp_GetProcAddress(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays, "glDeleteVertexArrays") glextimp_GetProcAddress(PFNGLGENRENDERBUFFERSPROC, glGenRenderbuffers, "glGenRenderbuffers") glextimp_GetProcAddress(PFNGLBINDRENDERBUFFERPROC, glBindRenderbuffer, "glBindRenderbuffer") glextimp_GetProcAddress(PFNGLRENDERBUFFERSTORAGEPROC, glRenderbufferStorage, "glRenderbufferStorage") glextimp_GetProcAddress(PFNGLDELETERENDERBUFFERSPROC, glDeleteRenderbuffers, "glDeleteRenderbuffers") glextimp_GetProcAddress(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers, "glGenFramebuffers") glextimp_GetProcAddress(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer, "glBindFramebuffer") glextimp_GetProcAddress(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D, "glFramebufferTexture2D") glextimp_GetProcAddress(PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer, "glFramebufferRenderbuffer") glextimp_GetProcAddress(PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus, "glCheckFramebufferStatus") glextimp_GetProcAddress(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers, "glDeleteFramebuffers") If Not glextimp_errors : ProcedureReturn #True : EndIf EndProcedure Procedure.b glextimp_Close() CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Windows ;{ Windows ;} CompilerCase #PB_OS_MacOS ;{ MacOS If glextimp_hOpenGLlib CloseLibrary(glextimp_hOpenGLlib) glextimp_hOpenGLlib = 0 EndIf ;} CompilerCase #PB_OS_Linux ;{ Linux ;} CompilerEndSelect EndProcedure ; Init OpenGL context to allow wglGetProcAddress_() function to work and to return a not null address CompilerIf #PB_Compiler_IsMainFile ;{ OpenWindow(0, 0, 0, 0, 0, "") OpenGLGadget(0, 0, 0, 0, 0) glextimp_init() glextimp_close() CompilerEndIf ;} ; IDE Options = PureBasic 5.62 (Windows - x86) ; Folding = SAg