Opengl 4.3 gl_VertexID not incrementing with glDrawArrays
文章推薦指數: 80 %
I'm having difficulty in understanding why gl_VertexID is not properly incrementing for each new vertex in the code below for rendering "debug ... 2022DeveloperSurveyisopen!Takesurvey. Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore Opengl4.3gl_VertexIDnotincrementingwithglDrawArrays AskQuestion Asked 8years,10monthsago Modified 8years,10monthsago Viewed 2ktimes 1 0 I'mhavingdifficultyinunderstandingwhygl_VertexIDisnotproperlyincrementingforeachnewvertexinthecodebelowforrendering"debugtext".Hints/tips? (Originalcodeisreferencedatthebottomofthispost) Hereafteristhevertexshader: #version430core layout(location=0)inintCharacter; outintvCharacter; outintvPosition; voidmain() { vPosition=gl_VertexID; vCharacter=Character; gl_Position=vec4(0,0,0,1); } Thegeometryshader: #version430core layout(points)in; layout(triangle_strip,max_vertices=4)out; inintvCharacter[1]; inintvPosition[1]; outvec2gTexCoord; uniformsampler2DSampler; uniformvec2CellSize; uniformvec2CellOffset; uniformvec2RenderSize; uniformvec2RenderOrigin; voidmain() { //Determinethefinalquad'spositionandsize: floatx=RenderOrigin.x+float(vPosition[0])*RenderSize.x*2.0f; floaty=RenderOrigin.y; vec4P=vec4(x,y,0,1); vec4U=vec4(1,0,0,0)*RenderSize.x; vec4V=vec4(0,1,0,0)*RenderSize.y; //Determinethetexturecoordinates: intletter=vCharacter[0]; letter=clamp(letter-32,0,96); introw=letter/16+1; intcol=letter%16; floatS0=CellOffset.x+CellSize.x*col; floatT0=CellOffset.y+1-CellSize.y*row; floatS1=S0+CellSize.x-CellOffset.x; floatT1=T0+CellSize.y; //Outputthequad'svertices: gTexCoord=vec2(S0,T1);gl_Position=P-U-V;EmitVertex(); gTexCoord=vec2(S1,T1);gl_Position=P+U-V;EmitVertex(); gTexCoord=vec2(S0,T0);gl_Position=P-U+V;EmitVertex(); gTexCoord=vec2(S1,T0);gl_Position=P+U+V;EmitVertex(); EndPrimitive(); } Thedrawcallandotherrelevantcode: glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER,0); GLuintattribLocation=glGetAttribLocation(m_ProgramTextPrinter,"Character"); glVertexAttribIPointer(attribLocation,1,GL_UNSIGNED_BYTE,1,text.data()->c_str()); glEnableVertexAttribArray(attribLocation); glDrawArrays(GL_POINTS,0,text.data()->size()); Basicallythiscodewillbeusedforsometextrendering.WhenIusethiscode,Iseethatmylettersareputontopofeachother.WhenImodify glVertexAttribIPointer(attribLocation,1,GL_UNSIGNED_BYTE,1,text.data()->c_str()); into glVertexAttribIPointer(attribLocation,1,GL_UNSIGNED_BYTE,2,text.data()->c_str()); Inoticethereisashiftinthex-directionasexpectedfromtheGeometryshader,neverthelessthelettersarestillontopofeachother. I'musinganNVIDIAGeforceGT630M,driverversion:320.18andanOpenGL4.3context. Referencetotheoriginalauthor'scode openglglsl Share Follow editedJul11,2013at14:47 genpfault 49.3k1010goldbadges7979silverbadges128128bronzebadges askedJul11,2013at12:58 StevenDeBockStevenDeBock 41944silverbadges2121bronzebadges 3 3 IIRCnon-VBOglVertexAttrib(I)Pointeroffsetsaredeprecatednow(spec4.3,§10.3.1).Itlooksextremelyfunky,though:)Alsopleasechangestrlen(text.data()->c_str())->text.data()->size() – BartekBanachewicz Jul11,2013at13:02 Thankyouforpointingoutthebettersize()call.Ieditedthecode. – StevenDeBock Jul11,2013at13:11 1 Also,pertheactualproblem:I'dexpectGeometryshadertomovepointspereachletter,andvertexshadertomoveeachletter.(I'dmovetheuniformRenderOrigintotheVS).Iamnotsureifitwillfixit,butthatsavesyou3/4ofadditions(assumingquads):) – BartekBanachewicz Jul11,2013at13:16 Addacomment | 1Answer 1 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 1 IgotthecodeworkingbyusingVBOsasBartekhintedat:Ibasicallyreplaced glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER,0); GLuintattribLocation=glGetAttribLocation(m_ProgramTextPrinter,"Character"); glVertexAttribIPointer(attribLocation,1,GL_UNSIGNED_BYTE,1,text.data()->c_str()); glEnableVertexAttribArray(attribLocation); glDrawArrays(GL_POINTS,0,text.data()->size()); with GLuintvaoID,bufferID; glGenVertexArrays(1,&vaoID); glBindVertexArray(vaoID); glGenBuffers(1,&bufferID); glBindBuffer(GL_ARRAY_BUFFER,bufferID); glBufferData(GL_ARRAY_BUFFER,text.data()->size()*sizeof(GL_UNSIGNED_BYTE),text.data()->data(),GL_DYNAMIC_DRAW); GLuintattribLocation=glGetAttribLocation(m_ProgramTextPrinter,"Character"); glVertexAttribIPointer(attribLocation,1,GL_UNSIGNED_BYTE,0,0); glEnableVertexAttribArray(attribLocation); glDrawArrays(GL_POINTS,0,text.data()->size()); glDeleteVertexArrays(1,&vaoID); glDeleteBuffers(1,&bufferID); Share Follow answeredJul11,2013at21:15 StevenDeBockStevenDeBock 41944silverbadges2121bronzebadges 0 Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedopenglglsloraskyourownquestion. TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication RetiringOurCommunity-SpecificClosureReasonsforServerFaultandSuperUser Temporarilypausingthesitesatisfactionsurvey StagingGround:ReviewerMotivation,Scaling,andOpenQuestions Related 1 GLSL-Problemofcastingandweirdbug 3 Passingontworectangleswithdifferentmeaningfromgeometrytofragmentshader 1 Randomcolouredblocks 6 OpenGLandGLSLmemoryalignmentforuniformsandvaryings 3 PyOpenGL-MinimalglDrawArraysExample HotNetworkQuestions CovidTestRequirementforDubaiTransitFromIrelandtoIndonesia Whyweremarijuanarestrictionsimplementedinthe1970smoresuccessfulinSouthKoreathanintheUnitedStates? Mymodelhasnotfinishedevaluatinginmorethanadaysocan'ttestifitworks,whatiswrongwithit? WhatpreventsmefrommakingonebigestimatedFederaltaxpaymentonJan15? Wouldn'tMiller'splanetbefriedbyblueshiftedradiation? Inbetweenfractions DifferencebetweenfirewallandACL Can"LaCorrida"mean"TheBullfight"? Can'tmultiplywidthin\newcommandforincludegraphics SelectonlyonepointinpolygonusingQGIS HowtopreventthewhiteflashwhenItrytogobeyondtheend/beginningofline? IsitallowedtocopycodeundertheUnityReference-OnlyLicense? Howdoyougagafish-personwithouttape? Planeticketincludestrainticket(Europe),whatifIdonotshowupattrainstation? Whatmakesaluminumaerospacegrade? Mybosssayshe'sjealouswhenItellhimaboutaworkachievement Movingplayerinsideofmovingspaceship? HowdoesHebrews11:27sayMoseswasnotafraid? Howdoyouemptyanonlinevirtualdebitcard? AquestionaboutCubeNuroadRaceFE'shubdynamo? Wouldn'tMiller'splanetbefriedbyblueshiftedradiation? Isitdangeroustoconsume30mgofZinc(asZincPicolinate)perday? Alphaparticlemovingfasterthanthespeedoflight? StarWars:R2D2connectedtomainframe morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-c Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1Using gl_VertexID as an array index? - OpenGL - Khronos ...
- 2gl_PointCoord - OpenGL 4 Reference Pages - Khronos Group
- 3Intro to GLSL - Cornell CS
- 4Computer Graphics - Joan Llobera
A geometry shader example. 3. Input to geometry shaders ... For example: gl_Position = vertices[g...
- 5Simple postprocessing in three.js | by Luigi De Rosa | Medium
There are already multiple examples and implementation in three.js. ... gl_VertexID is available ...