opengl es - WebGL - which API to use? - Stack Overflow

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

gl.vertexAttrib3f only lets you supply a single constant value to a GLSL attribute so you'll need to use gl.vertexAttribPointer and gl. 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 WebGL-whichAPItouse? AskQuestion Asked 8years,1monthago Modified 8years,1monthago Viewed 335times 0 1 Iwanttodrawmultiplepolygonshapes(whereeachshapehasit'sownsetofvertices). Iwanttobeabletopositiontheseshapesindependentlyofeachother. WhichAPIcaniusetosetthea_Positionforthevertexshader? A)gl.vertexAttrib3f B)gl.vertexAttribPointer+gl.enableVertexAttribArray thanks. opengl-eswebglvertex-arrayvertex-attributes Share Follow editedJun3,2014at3:39 AlvinfromDiaspar askedJun3,2014at3:33 AlvinfromDiasparAlvinfromDiaspar 6,3791313goldbadges6868silverbadges127127bronzebadges Addacomment  |  1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 1 Yourquestionmakesitsoundlikeyou'rereallynewtoWebGL?Maybeyoushouldreadsometutorials?Butinanswertoyourquestion: gl.vertexAttrib3fonlyletsyousupplyasingleconstantvaluetoaGLSLattributesoyou'llneedtousegl.vertexAttribPointerandgl.enableVertexAttribArray.You'llalsoneedtosetupbufferswithyourvertexdata. gl.vertexAttrib3fonlypointisarguablytoletyoupassinaconstantinthecasethatyouhaveashaderthatusesmultipleattributesbutyoudon'thavedataforallofthem.Forexampleletssayyouhaveashaderthatusesbothtexturesandsoneedstexturecoordinatesanditalsohasvertexcolors.Somethinglikethis vertexshader attributevec4a_position; attributevec2a_texcoord; attributevec4a_color; varyingvec2v_texcoord; varyingvec4v_color; uniformmat4u_matrix; voidmain(){ gl_Position=u_matrix*a_position; //passtexcoordandvertexcolorstofragmentshader v_texcoord=a_texcoord; v_color=v_color; } fragmentshader precisionmediumpfloat; varyingvec2v_texcoord; varyingvec4v_color; uniformsampler2Du_texture; voidmain(){ vec4textureColor=texture2D(u_texture,v_texcoord); //multiplythetexturecolorbythevertexcolor gl_FragColor=textureColor*v_color; } Thisshaderrequiresvertexcolors.Ifyourgeometrydoesn'thavevertexcolorsthenyouhave2options(1)useadifferentshader(2)turnofftheattributeforvertexcolorsandsetittoaconstantcolor,probablywhite. gl.disableVertexAttribArray(aColorLocation); gl.vertexAttrib4f(aColorLocation,1,1,1,1); Nowyoucanusethesameshadereventhoughyouhavenovertexcolordata. Similarlyifyouhavenotexturecoordinatesyoucouldpassinawhite1pixelshaderandsetthetexturecoordinatestosomeconstant. gl.displayVertexAttribArray(aTexcoordLocation); gl.vertexAttrib2f(aTexcoordLocation,0,0); gl.bindTexture(gl.TEXTURE_2D,some1x1PixelWhiteTexture); Inthatcaseyoucouldalsodecidewhatcolortodrawwithbysettingthevertexcolorattribute. gl.vertexAttrib4f(aColorLocation,1,0,1,1);//drawinmagenta Share Follow editedJun3,2014at8:02 answeredJun3,2014at7:53 gmangman 93k2929goldbadges235235silverbadges349349bronzebadges 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?Browseotherquestionstaggedopengl-eswebglvertex-arrayvertex-attributesoraskyourownquestion. TheOverflowBlog HowStackOverflowislevelingupitsunittestinggame Developersvsthedifficultybomb(Ep.459) FeaturedonMeta Testingnewtrafficmanagementtool Duplicatedvotesarebeingcleanedup Trending:Anewanswersortingoption Updatedbuttonstylingforvotearrows:currentlyinA/Btesting Linked 1 gl_PositionwillnotmovevertexwhenIpassinpositiontoshaderwithattribute? Related 4 usingWebGLindexbuffersfordrawingmeshes 0 NotabletogetoutputwithglDrawElements()&glMultiDrawElements() 0 Webglcoloringtheentiregeometry? 1 WebGL/Javascript:Objecttransformationswithmultipleobjects 0 WebGL-multipleshapesbutonlyoneisrenderedinsteadoftheothers 0 DrawlinesindifferentcolorsusingWebGL 1 WebGLfixingtextureofcellsinagridwithoutduplicatedvertices 3 OpenGLES(WebGL)renderingmanysmallobjects 1 reduceredundantwebglattributedata 19 AreMTLVertexAttributeDescriptorsnecessary?Whyaretheyneeded? HotNetworkQuestions Cgenericdynamicarray(usingpreprocessor) WhichoutputfilefromCASTEPaftergeometryoptimizationislikewiththeCONTCARfromVASP? Whatadvantages/disadvantageswouldHomoErectushaveina19thCenturymilitaryconflict? Whyisitassumedthatspaceflightshavetobesafe? HowmanyRussianssayAlaskaisrightfullytheirs? Is86%ofthefoodfedtolivestockunfitforhumanconsumption,andismostofitbyproductsofcropsgrownforhumanconsumption? Arebriftersmeanttospin/slideonimpact,bythechoiceofalowattachment-bolttorque? IncomingandOutgoingWavesinQuantumFieldTheory Examplesoflocallyhyperbolicgroups DrawtheUSAflag Hugegalaxiesseenfromearth GolfGitHub'sPagerLogic C++confusingclosurecaptures[v]vs[v=v] WhydoesIsCoinBase()checkifthereisexactlyoneinput? Wordforheavilyforeign-influencedspeech? Difficultyforafiremantoholdahosewhichejectslargeamountsofwateratahighvelocity "if"statementsyntaxdifferencesbetweenCandC++ Is3/4"plywoodsufficientlystrongtomountan85"television? Howareweatherballoonsdifferentfrom"regular"biglatexballoons? HowtoputMicrosoftTeamscallonhold? Whatpumpsbloodthroughalistener'sbody? I'mwantingtohaveatwistwereTiamatgetsturnedintoadracolichbefore,duringorafterthebigfight Creatingatitlepage AsBlack,howdoyoudealwiththedoublepawnsintheRuyLopezexchangevariation? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?