匿名用户2021年12月24日
49阅读
开发技术C/C++
所属分类程序开发、图形/图像处理
授权协议View license

作品详情

glad

GL/GLES/EGL/GLX/WGLLoader-Generatorbasedontheofficialspecs.

Usethewebservicetogeneratethefilesyouneed!

#include<glad/glad.h>intmain(){//--snip--GLFWwindow*window=glfwCreateWindow(WIDTH,HEIGHT,"LearnOpenGL",NULL,NULL);glfwMakeContextCurrent(window);if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){std::cout<<"FailedtoinitializeOpenGLcontext"<<std::endl;return-1;}glViewport(0,0,WIDTH,HEIGHT);//--snip--

Thefullcode:hellowindow2.cpp.

Glad2

Glad2isbecomingmatureandisprettystablenow,considerusingtheglad2branchoritswebservice.

Thereisnoneedtoswitch,ifyoudon'twantto.Iwillsupportbothversions.

Glad2bringsseveralimprovementsandnewfeatures:

BetterEGL,GLX,WGLsupportVulkanSupportRustSupportMoreGeneratorFeatures(e.g.headeronly)BetterXML-SpecificationparsingBetterWeb-GeneratorBetterCmakesupportBetterExamplesBetterCLIBetterLoaderBetterAPI

Ifyou'reusinggladformorethanGL,Ihighlyrecommendcheckingoutglad2.

Usage

Ifyoudon'twanttoinstallgladyoucanusethewebservice

Otherwiseeitherinstallgladviapip:

#Windowspipinstallglad#Linuxpipinstall--userglad#Linuxglobal(root)pipinstallglad

ToinstallthemostrecentversionfromGithub:

pipinstall--upgradegit+https://github.com/dav1dde/glad.git#egg=glad

Orlaunchgladdirectly(aftercloningtherepository):

python-mglad--help

Installingandbuildinggladviavcpkg

Youcandownloadandinstallgladusingthevcpkgdependencymanager:

gitclonehttps://github.com/Microsoft/vcpkg.gitcdvcpkg./bootstrap-vcpkg.sh./vcpkgintegrateinstallvcpkginstallglad

ThegladportinvcpkgiskeptuptodatebyMicrosoftteammembersandcommunitycontributors.Iftheversionisoutofdate,pleasecreateanissueorpullrequestonthevcpkgrepository.

Whenintegratinggladintoyourbuildsystemthe--reproducibleoptionishighlyrecommended.

GeneratorsC/C++structgladGLversionStruct{intmajor;intminor;};externstructgladGLversionStructGLVersion;typedefvoid*(*GLADloadproc)(constchar*name);/**LoadOpenGLusingtheinternalloader.*Returnsthetrue/1ifloadingsucceeded.**/intgladLoadGL(void);/**LoadOpenGLusinganexternalloaderlikeSDL_GL_GetProcAddress.**SubstituteGLwiththeAPIyougenerated**/intgladLoadGLLoader(GLADloadproc);/***WGLandGLXhaveanunloadfunctiontofreethemodulehandle.*CalltheunloadfunctionafteryourlastGLXorWGLAPIcall.*/voidgladUnloadGLX(void);voidgladUnloadWGL(void);

glad.hcompletelyreplacesanygl.horgl3.honlyincludeglad.h.

if(!gladLoadGL()){exit(-1);}printf("OpenGLVersion%d.%dloaded",GLVersion.major,GLVersion.minor);if(GLAD_GL_EXT_framebuffer_multisample){/*GL_EXT_framebuffer_multisampleissupported*/}if(GLAD_GL_VERSION_3_0){/*WesupportatleastOpenGLversion3*/}

Onnon-Windowsplatformsgladrequireslibdl,makesuretolinkwithit(-ldl).

Note,therearetwokindsofextension/versionsymbols,e.g.GL_VERSION_3_0andGLAD_VERSION_3_0.Latterisaruntimeboolean(representedasinteger),whereasthefirst(notprefixedwithGLAD_)isacompiletime-constant,indicatingthatthisheadersupportsthisversion(theofficialheadersdefinethesesymbolsaswell).TheruntimebooleansareonlyvalidafterasuccessfulcalltogladLoadGLorgladLoadGLLoader.

C/C++Debug

TheC-DebuggeneratorextendstheAPIbythesetwofunctions:

//thissymbolonlyexistsifgeneratedwiththec-debuggenerator#defineGLAD_DEBUGtypedefvoid(*GLADcallback)(constchar*name,void*funcptr,intlen_args,...);/**Setsacallbackwhichwillbecalledbeforeeveryfunctioncall*toafunctionloadedbyglad.**/GLAPIvoidglad_set_pre_callback(GLADcallbackcb);/**Setsacallbackwhichwillbecalledaftereveryfunctioncall*toafunctionloadedbyglad.**/GLAPIvoidglad_set_post_callback(GLADcallbackcb);

TocallafunctionlikeglGetErrorinacallbackprefixitwithglad_,e.g.thedefaultpostcallbacklookslikethis:

void_post_call_callback_default(constchar*name,void*funcptr,intlen_args,...){GLenumerror_code;error_code=glad_glGetError();if(error_code!=GL_NO_ERROR){fprintf(stderr,"ERROR%din%s\n",error_code,name);}}

Youcanalsosubmitownimplementationsforeverycallmadebyoverwritingthefunctionpointerwiththenameofthefunctionprefixedbyglad_debug_.

E.g.youcoulddisablethecallbacksforglClearwithglad_debug_glClear=glad_glClear,whereglad_glClearisthefunctionpointerloadedbyglad.

TheglClearmacroisdefinedas#defineglClearglad_debug_glClear,glad_debug_glClearisinitializedwithadefaultimplementation,whichcallsthetwocallbacksandtherealfunction,inthiscaseglad_glClear.

FAQHowdoIbuildgladorhowdoIintegrateglad?

Easiestwayofusinggladisthroughthewebservice.

Alternativelygladintegrateswith:

CMakeConanVCPKG

Thanksforallthehelpandsupportmaintainingthose!

gladincludeswindows.h#42

Since0.1.30:gladdoesnotincludewindows.hanymore.

Before0.1.30:DefiningAPIENTRYbeforeincludingglad.hsolvesthisproblem:

#ifdef_WIN32#defineAPIENTRY__stdcall#endif#include<glad/glad.h>

ButmakesureyouhavethecorrectdefinitionofAPIENTRYforplatformswhichdefine_WIN32butdon'tuse__stdcall

What'sthelicenseofgladgeneratedcode?

#101#253

ThegladgeneratedcodeitselfisanyofPublicDomain,WTFPLorCC0,thesourcefilesforthegeneratedcodeareundervariouslicensesfromKhronos.

EGL:Seeegl.xmlGL:ApacheVersion2.0GLX:ApacheVersion2.0WGL:ApacheVersion2.0Vulkan:ApacheVersion2.0withexceptionsforgeneratedcode

NowtheApacheLicensemayapplytothegeneratedcode(notalawyer),butseethisclarifyingcomment.

GladalsoaddsheaderfilesformKhronos,thesehaveseparatedlicensesintheirheader.

Contribute

Contributingiseasy!Foundabug?Messagemeormakeapullrequest!Addedanewgeneratorbackend?Makeapullrequest!

Specialthanksforallthepeoplewhocontributedandaregoingtocontribute!AlsotothesewhohelpedmesolveaproblemwhenIsimplycouldnotthinkofasolution.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论