Raspberry Pi OpenGL ES 2 without an X server (using EGL)

文章推薦指數: 80 %
投票人數:10人

Raspberry Pi 1,2,3. For the Raspberry Pi 4 instructions see the next section. What do I need? You need a GCC compiler, EGL, and GLES libraries ... Skiptocontent {{message}} matusnovak / rpi-opengl-without-x Public Notifications Fork 23 Star 126 RaspberryPiOpenGLES2withoutanXserver(usingEGL) License Unlicenselicense 126 stars 23 forks Star Notifications Code Issues 1 Pullrequests 0 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository. master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 1 branch 0 tags Code Latestcommit   Gitstats 15 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime LICENSE     README.md     output.png     triangle.c     triangle_rpi4.c     Viewcode RaspberryPiOpenGLES2withoutanXserver(usingEGL) WhichRaspberryPiworks? RaspberryPi1,2,3 RaspberryPi4 TroubleshootingandQuestions License README.md RaspberryPiOpenGLES2withoutanXserver(usingEGL) Haveyoueverwantedtorenderthingswithheadless(noscreen)RaspberryPi?Thenthisissomethingyoumightbeinterestedin! Thefollowingfiletriangle.ccontainsanexamplethatrendersatriangleandsavesitintoaoutput.rawfile.TheexampleusesEGLtocreateapixelbufferasasurface.Normally,whenusingXserver,youwouldcreateawindowsurface,butinherewedonotdothatatall.ThisexamplealsousesOpenGLES2tosetupaverysimpleshadertorenderatriangle. Thetriangle.ccontainscommentswhichshouldexplainyouallthenecessaryparts.PleasenotethatthisexamplewillnotteachyoufundamentalsofOpenGL!ThepurposeofthisfileissolelytodemonstratecreatinganOpenGLES2contextandgettingtherawpixeloutputwithoutusinganyvirtualLinuxframebuffersorphysicalscreen(noXserver). WhichRaspberryPiworks? RaspberryPi1(testedandworks) RaspberryPi2(testedandworks) RaspberryPi3(testedandworks) RaspberryPi4(testedandworks,butwon'tworkinheadlessmode,youneedaHDMIoutputworksjustfineintheheadlessmode,nolongertrue,seeissue#11) RaspberryPi1,2,3 FortheRaspberryPi4instructionsseethenextsection WhatdoIneed? YouneedaGCCcompiler,EGL,andGLESlibraries.IfyouareusingthelatestRaspbiandistro,allthosearealreadylocatedontheimage,noextraapt-getneeded.YoucancheckifyouhavetheGCCinstalledbyexecutinggcc--version.YoucanalsocheckiftheGLESandEGLareinstalledbyexecutingls/opt/vc/libwhichshouldlistlibbrcmEGL.soandlibbrcmGLESv2.so.TheyareallalreadyincludedintheJessie/Stretch/BusterRaspbian!Ifyoudon'thavelibbrcmEGL.so,youwillhavetousethelibEGL.soinstead,whichislocatedinthesamefolder. Theproblemofmesaaptpackage Thefollowingpackagesmesa-common-devandmesa-utilsdoNOTworkandinsteadtheymaybreakEGLonyourOS.ThelibrariesinstalledthroughanyofthemesapackageswillinstallincompatibleversionoftheEGL,mostlikelyintothe/lib/arm-linux-gnueabihffolder.Don'tusethese!UsetheonesprovidedbytheofficialRaspbianOSimageinthe/opt/vc/libfolder! HowdoItryit? Copyordownloadthetriangle.cfileontoyourRaspberryPi.Usethefollowingcommandstocompilethesourcefile: gcc-ctriangle.c-otriangle.o-I/opt/vc/include gcc-otriangletriangle.o-lbrcmEGL-lbrcmGLESv2-L/opt/vc/lib Toruntheexecutable,typethefollowing: ./triangle Youshouldseethefollowingoutput: InitializedEGLversion:1.4 GLViewportsize:800x600 Atthesametime,anewfileshouldbecreated:output.raw.Thisfilecontainsraw800x600RGBpixels.YoucanusePhotoshoporanyothersoftwaretoimportandviewthisfile.Youshouldbeabletoseethefollowingpurpletriangle.PleasenotethattheimageismirroredverticallyasthepixelcoordinatesinOpenGLstartfromthebottom,notfromthetop.Exampleoftheimage: RaspberryPi4 RaspberryPi4,atthemomentofwritingthis,hasnofullKMSdriver,becausetheGPUisdifferentfromthepreviousones.Insteadofusingthevclibraries,youwillneedtousetheDRM/GBM. WhatdoIneed? YouneedaGCCcompiler,GDM,EGL,andGLESlibraries.TheGCCcompilerisalreadyincludedintheRaspbianimage.Toinstalltheotherlibraries,simplyrun: sudoapt-getinstalllibegl1-mesa-devlibgbm-devlibgles2-mesa-dev YouwillalsoneedtoconnectyourRaspberryPitoascreen.Thebootconfigfrom/boot/config.txtthatIhaveusedformytests,ifithelpsinanyway: dtoverlay=vc4-fkms-v3d max_framebuffers=2 hdmi_force_hotplug=1 hdmi_group=2 hdmi_mode=81 HowdoItryit? Copyordownloadthetriangle_rpi4.cfileontoyourRaspberryPi.Usinganyterminal,writethefollowingcommandstocompilethesourcefile: gcc-otriangle_rpi4triangle_rpi4.c-ldrm-lgbm-lEGL-lGLESv2-I/usr/include/libdrm-I/usr/include/GLES2 Toruntheexecutable,typethefollowing: ./triangle_rpi4 Youshouldseethefollowingoutput: resolution:1366x768 InitializedEGLversion:1.4 GLViewportsize:1366x768 Atthesametime,anewfileshouldbecreated:output.raw.Thisfilecontainsraw1366x768RGBpixels.YoucanusePhotoshoporanyothersoftwaretoimportandviewthisfile.Youshouldbeabletoseethefollowingpurpletriangle.PleasenotethattheimageismirroredverticallyasthepixelcoordinatesinOpenGLstartfromthebottom,notfromthetop.Exampleoftheimage: TroubleshootingandQuestions FailedtogetEGLversion!Error: YourEGLmightbefaulty!MakesureyouareusingthelibrariesprovidedbyRaspbianandnottheonesinstalledthroughapt-getorotherpackagemanagers.Usetheonesinthe/opt/vc/libfolder.Ifthatdoesnotwork,tryreinstallingyourRaspberryPiOS. Iget"Error!TheglViewport/glGetIntegervarenotworking!EGLmightbefaulty!"WhatshouldIdo? Sameasabove. HowdoIchangethepixelbufferresolution? FindpbufferAttribsandchangeEGL_WIDTHandEGL_HEIGHT. Iget"undefinedreference"onsomeglfunctions! SomeGLfunctionsmaynotcomefromGLESlibrary.YoumayneedtogetGL1librarybyexecutingsudoapt-getinstalllibgl1-mesa-devandthensimplyadd:-lGLflagtothelinker,soyouget:gcc-otriangletriangle.o-lbrcmEGL-lbrcmGLESv2-lGL-L/opt/vc/lib HowdoIchangethebuffersamplesizeorthedepthbuffersizeorthestencilsize? FindconfigAttribsatthetopofthetriangle.cfileandmodifytheattributesyouneed.Allconfigattributesarelocatedherehttps://www.khronos.org/registry/EGL/sdk/docs/man/html/eglChooseConfig.xhtml CanIuseglBegin()andglEnd()? Youshouldnot,butyoucan.However,itseemsthatOpenGLESdoesnotlikethatandnothingwillberendered.ForthisyouwillneedtolinktheGLlibraryaswell.Simply,add-lGLtothegcccommand. Failedtoaddservice-alreadyinuse? Asmentionedinthisissue,youhavetoremovebothvc4-kms-v3dandvc4-fkms-v3dfromR-Piconfig.Alsorelevantdiscussionhere:https://stackoverflow.com/questions/40490113/eglfs-on-raspberry2-failed-to-add-service-already-in-use.IfyouareusingRaspberryPi4(thetriangle_rpi4.c)itmighthappensometimes.Icouldnotfullyfigureitout,butitmightbeduetoincorrectEGLorDRM/GBMcleanupinthecode.Isay"incorrect",butIdon'tknowwhere. License Dowhateveryouwant. Thisisfreeandunencumberedsoftwarereleasedintothepublicdomain. Anyoneisfreetocopy,modify,publish,use,compile,sell,or distributethissoftware,eitherinsourcecodeformorasacompiled binary,foranypurpose,commercialornon-commercial,andbyany means. Injurisdictionsthatrecognizecopyrightlaws,theauthororauthors ofthissoftwarededicateanyandallcopyrightinterestinthe softwaretothepublicdomain.Wemakethisdedicationforthebenefit ofthepublicatlargeandtothedetrimentofourheirsand successors.Weintendthisdedicationtobeanovertactof relinquishmentinperpetuityofallpresentandfuturerightstothis softwareundercopyrightlaw. THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT. INNOEVENTSHALLTHEAUTHORSBELIABLEFORANYCLAIM,DAMAGESOR OTHERLIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE, ARISINGFROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOR OTHERDEALINGSINTHESOFTWARE. Formoreinformation,pleasereferto About RaspberryPiOpenGLES2withoutanXserver(usingEGL) Topics raspberry-pi opengl raspberrypi opengl-es egl opengl-tutorial opengl-shading-language Resources Readme License Unlicenselicense Stars 126 stars Watchers 7 watching Forks 23 forks Releases Noreleasespublished Packages0 Nopackagespublished Contributors2     Languages C 100.0% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?