Raspberry Pi OpenGL ES 2 without an X server (using EGL)
文章推薦指數: 80 %
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
24
Star
129
RaspberryPiOpenGLES2withoutanXserver(usingEGL)
License
Unlicenselicense
129
stars
24
forks
Star
Notifications
Code
Issues
1
Pullrequests
0
Actions
Projects
0
Security
Insights
More
Code
Issues
Pullrequests
Actions
Projects
Security
Insights
matusnovak/rpi-opengl-without-x
Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository.
master
Branches
Tags
Couldnotloadbranches
Nothingtoshow
{{refName}}
default
Couldnotloadtags
Nothingtoshow
{{refName}}
default
1
branch
0
tags
Code
Clone
HTTPS
GitHubCLI
UseGitorcheckoutwithSVNusingthewebURL.
WorkfastwithourofficialCLI.
Learnmore.
OpenwithGitHubDesktop
DownloadZIP
LaunchingGitHubDesktop
Ifnothinghappens,downloadGitHubDesktopandtryagain.
LaunchingGitHubDesktop
Ifnothinghappens,downloadGitHubDesktopandtryagain.
LaunchingXcode
Ifnothinghappens,downloadXcodeandtryagain.
LaunchingVisualStudioCode
Yourcodespacewillopenonceready.
Therewasaproblempreparingyourcodespace,pleasetryagain.
Latestcommit
Gitstats
15
commits
Files
Permalink
Failedtoloadlatestcommitinformation.
Type
Name
Latestcommitmessage
Committime
LICENSE
Fixedformattingmess(Iamsorryfortabs,don'tkillme)andupdate…
Jul27,2019
README.md
Betterwordingandgrammarfixes
Mar28,2021
output.png
AddedRaspberryPi4example
Sep9,2019
triangle.c
AddedRaspberryPi4example
Sep9,2019
triangle_rpi4.c
Mergebranch'master'intopatch-2
Nov9,2019
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
延伸文章資訊
- 1Raspberry Pi 4: GAMECUBE EMULATION (VULKAN VS ...
- 2Raspberry Pi 4 to Get OpenGL ES 3.1 Compute, Geometry ...
The Raspberry Pi 4, with its powerful new Broadcom VideoCore-VI graphics processor, is set to get...
- 3OpenGl 3.3 on Raspberry Pi 4 8gb
OpenGL is not just a software library, it's a software interface to hardware features of the grap...
- 4Raspberry Pi 4 Model B Gains Official OpenGL ES 3.1 ...
The Khronos Group has officially certified the Raspberry Pi 4 Model B family of single-board comp...
- 5Raspberry Pi 4 8GB上的OpenGl 3.3 - PI - 2022 - Lbrbroadcast
在Raspberry Pi上運行OpenGl 3.3. 晚上好,當我用我的Raspberry Pi 4 8 gb運行Blender(我不知道,我建議它是Blender 2.8(在Ubuntu...