opengl es - WebGL - which API to use? - Stack Overflow
文章推薦指數: 80 %
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
延伸文章資訊
- 1在JavaScript程序通过attribute变量向顶点着色器传值 - CSDN博客
gl.vertexAttrib3f() 方法是一系列同族函数中的一个,该系列函数的任务就是从JavaScript程序中向顶点着色器中的attribute变量传值
- 2[Day5] WebGL 修羅道(2) - 資料傳遞 - iT 邦幫忙
而傳入值的話,則是使用 gl.vertexAttrib3f ,要注意attribute 這個型別只能夠用在vertex shader 中!其實在使用attribute,是先取用buffer 中的...
- 3Gl.VertexAttrib3f (gb.opengl.glsl) - / - Gambas Documentation
Gl.VertexAttrib3f (gb.opengl.glsl) ... Specifies the value of a generic vertex attribute. Paramet...
- 4WebGL入门-WebGL常用API说明详解_点燃火柴的博客
vertexAttrib3f()的同族函数7. 获取uniform变量地址gl.getUniformLocation()8. ... vertexAttrib3f(); 4.3 给attribu...
- 5使用attribute 變數
const gl = getGLContext(document. ... getAttribLocation(prog, 'position'); const gl_size = gl. .....