Drawing lines with shader - OpenGL - Khronos Forums

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

Hello, I'm trying to draw cube with lines which connects every single vertex on 3D space. and I want lines that are actually visible to user ... Drawinglineswithshader OpenGL pluxy January11,2022,3:02pm #1 Hello, I’mtryingtodrawcubewithlineswhichconnectseverysinglevertexon3Dspace. andIwantlinesthatareactuallyvisibletousertobedrawnonthescreen. [Expected] IcaneasilydrawcubeandlinesseparatelywithglBegin()/glEnd() image896×9237.31KB [Actual] image907×9092.19KB [VertexShader] #version450core layout(location=0)invec3aPos; outvec4aColor; uniformmat4projection; uniformmat4view; uniformmat4model; uniformvec4color; voidmain(){ aColor=color; gl_Position=projection*view*model*vec4(aPos,1.0); } [FragmentShader] #version450core invec4aColor; outvec4FragColor; voidmain(){ FragColor=aColor; } [Drawingcodes] glBindVertexArray(VAO); glDrawArrays(GL_TRIANGLES,0,36);//drawcube glBindVertexArray(0); Isthereanyguidelineswhichcanhelpmetoachievemygoalwithshader? Thanks, Alfonse_Reinheart January11,2022,3:09pm #2 Didyouturnoffdepthtestingwhenyou’rerenderinglines,sothatthetrianglesdon’tblockthemfromview? GClements January11,2022,3:29pm #3 Alfonse_Reinheart: Didyouturnoffdepthtestingwhenyou’rerenderinglines,sothatthetrianglesdon’tblockthemfromview? pluxy: andIwantlinesthatareactuallyvisibletousertobedrawnonthescreen. IOW,depth-testingneedstobeenabledtoremovethehiddenlines. YoumighttryglDepthFunc(GL_LEQUAL).ThedefaultisGL_LESS,whichwilldiscardfragmentswhosedepthvalueisequaltothatinthedepthbuffer. Butthatmaynotbeenough.Becauseofthedifferencesinrasterisation,thefragmentsgeneratedbythelineswon’thavethesamedepthasthosegeneratedbythetriangles.Thefragmentsgeneratedbytriangleswillhavethedepthcalculatedbysamplingtheplaneequationatthefragmentcentre.Thosegeneratedbylineswillbecalculatedbysamplingthelineequationattheclosestpointtothefragmentcentre. Todealwiththat,useglEnable(GL_POLYGON_OFFSET_LINE)andglPolygonOffsettomakethelineshaveslightlylowerdepthvalues.You’llneedtoexperimentregardingtheparameters,astherequiredoffsetwilldependuponthenearandfarplanedistancesusedtoconstructtheprojectionmatrixandalsouponthedistancefromtheviewpoint. 1Like pluxy January12,2022,12:37pm #4 Thankyousomuch!! Problemhasbeenresolved!! system closed July14,2022,12:38pm #5 Thistopicwasautomaticallyclosed183daysafterthelastreply.Newrepliesarenolongerallowed.



請為這篇文章評分?