久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用片段著色器和 GL_LINE_STRIP 在 OpenGL GLES20 andr

Draw a simple dotted line or dashed line in OpenGL GLES20 android using fragment shader and GL_LINE_STRIP(使用片段著色器和 GL_LINE_STRIP 在 OpenGL GLES20 android 中繪制簡單的虛線或虛線) - IT屋-程序員軟件開發(fā)技術(shù)分
本文介紹了使用片段著色器和 GL_LINE_STRIP 在 OpenGL GLES20 android 中繪制簡單的虛線或虛線的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我查看了不同的來源,發(fā)現(xiàn)我們可以使用片段著色器繪制虛線.因?yàn)槲沂?OpenGL 新手,所以我無法理解.

誰能分享一些在Android中使用片段著色器和GL_LINE_STRIP繪制虛線或虛線的代碼示例.

參考資料:

  • <小時(shí)>

    <子>除了使用紋理,您還可以在片段著色器中生成點(diǎn)畫.查看桌面 OpenGL cor 配置文件的解決方案:
    glLineStipple 在 OpenGL 3.1 中已棄用
    OpenGL3 中的虛線?

    I went through different sources and seen that we could draw a dotted line using a fragment shader. Because I am new to OpenGL I couldn't able to understand.

    Can anyone share some code sample that plot dotted or dashed line using fragment shader and GL_LINE_STRIP in Android.

    References:

    • Dashed line in OpenGL3?
    • Dotted back edges of object

    解決方案

    Line stipple is not supported in OpenGL ES.

    If you use OpenGL ES 1.00, then you can use the approach which is presented in the answers to OpenGL ES - Dashed Lines.
    You have to create a 1 dimensional texture (2 dimensional Nx1 texture), and wrap the texture on the lines. The texture has a stipple pattern encoded in its alpha channel. The space between the dashes is discarded by the Alpha test.

    If you use OpenGL ES 2.00 or higher (OpenGL ES 3.x), then you can't use the alpha test, because it is deprecated. You have to use a fragment shader and to skip fragments by the discard keyword.

    Create a texture with a red color channel only. The stipple pattern is encoded in the red color channel, but the code is very similar to that one from OpenGL ES - Dashed Lines, beside the fact that you have to use GL10.GL_RED for the internal texture format (instead of GL10.GL_ALPHA):

    byte arr[] = new byte[] { 255, 0, 0, 255 };
    ByteBuffer textureBuffer = ByteBuffer.wrap(arr);
    
    gl.glGenTextures(1, texture_id_, stippleTexObj);
    gl.glBindTexture(GLES20.GL_TEXTURE_2D, stippleTexObj);
    gl.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    gl.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    gl.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    gl.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
    gl.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RED, 4, 1, 0,
                    GLES20.GL_RED, GLES20.GL_UNSIGNED_BYTE, textureBuffer);
    

    When you draw the lines, the you have to use a shader program, that discard the fragments dependent on the red color channel of the texture. A very simple GLSL ES 1.00 shader (for OpenGL ES 3.00) may look as follows:

    Vertex shader:

    attribute vec2  inPos;
    attribute float inU;
    varying   float vU;
    
    void main()
    {
        outU        = inU;
        gl_Position = vec4( inPos.xy, 0.0, 1.0 );
    }
    

    Fragment shader:

    precision mediump float;
    
    varying float     vU;
    uniform sampler2D u_stippleTexture;
    
    void main()
    {
        float stipple = texture2D(u_stippleTexture, vec2(vU, 0.0)).r;
        if (stipple < 0.5)
            discard;
        gl_FragColor = vec4(1.0);
    }
    

    Ensure that the texture coordinates which are associated to the vertices are aligned to integral values when you draw the line, that causes the the lines start and end with a dash:

    e.g. a quad with bottom left of (-0.5 -0.5) and to right of (0.5, 0.5) and the texture coordinates in range [0, 5]:

     x     y       u   
    -0.5f -0.5f    0.0f
     0.5f -0.5f    5.0f
     0.5f  0.5f    0.0f
    -0.5f  0.5f    5.0f
    

    Since the wrap function is GL_REPEAT and the texture coordinates are in range [0, 5], 5 repetitions of the stipple pattern are wrapped to each edge of the quad.


    Instead of using a texture, you can also generate the stippling in the fragment shader. See the solutions for desktop OpenGL cor profile:
    glLineStipple deprecated in OpenGL 3.1
    Dashed line in OpenGL3?

    這篇關(guān)于使用片段著色器和 GL_LINE_STRIP 在 OpenGL GLES20 android 中繪制簡單的虛線或虛線的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

    【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 羞羞视频网站免费看 | 国产露脸对白88av | 午夜精品久久久久久久99黑人 | 国产日韩一区二区 | 日韩天堂av| 一区二区三区视频在线免费观看 | 91精品国产综合久久婷婷香蕉 | 欧美一区二区久久 | 久久中文字幕一区 | 国产ts人妖系列高潮 | 欧美一级做性受免费大片免费 | 欧美a级成人淫片免费看 | av天天看 | 天天天天操 | 中文字幕亚洲一区 | 中文字幕91av | 国内自拍偷拍 | 国产精久久久久久久 | av黄色在线| 亚洲精品免费视频 | 91av视频| 日本三级日产三级国产三级 | 隔壁老王国产在线精品 | 国产美女黄色片 | 国产激情免费视频 | 久久小视频 | 日韩一区二区三区精品 | 久久99网站 | 久久久久亚洲精品中文字幕 | 成人二区 | xx视频在线 | 综合久久久 | 一区二区免费在线视频 | 91五月婷蜜桃综合 | 精品国产不卡一区二区三区 | 欧美黑人一区 | 欧美精品久久久久 | 久久精品日产第一区二区三区 | 亚洲网站在线播放 | 国产三级一区二区三区 | 成人福利网|