简体   繁体   English

OpenGL ES 2.0-用纹理绘制线条?

[英]OpenGL ES 2.0 - Draw Line with Texture?

What is the best approach for drawing a Line with a specific texture? 绘制具有特定纹理的线的最佳方法是什么?

Right now I'm attempting to draw a Line with a texture by simply drawing lines instead of another Primitive. 现在,我试图通过简单地绘制线条而不是另一个基本体来绘制带有纹理的线条。

    setupMandatoryHandlers(shader);

    GLES20.glEnableVertexAttribArray(positionHandler);
    GLES20.glVertexAttribPointer(positionHandler, COORDS, GLES20.GL_FLOAT, false, STRIDE, vertexBuffer);

    if (texture != null)
        setupTextureData();     

    GLES20.glUniform4fv(colorHandler, 1, color, 0);

    GLES20.glUniformMatrix4fv(MVPMatrixHandle, 1, false, orthoMatrix, 0);       
    GLES20.glDrawElements(drawType, indices.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLRenderer.CheckGLError("Draw Elements");       

    GLES20.glDisableVertexAttribArray(positionHandler);

    if (texture != null)
        GLES20.glDisableVertexAttribArray(texCoordHandler);

Is this the most efficient way of drawing lines with textures or should I be looking somewhere else? 这是用纹理绘制线条的最有效方法,还是应该在其他地方查看? Should I use glDrawArrays instead of glDrawElements for lines? 我应该使用glDrawArrays而不是glDrawElements线条吗?

我无法用简单的纹理对一维线进行纹理化,因为据我所知,目前尚无办法获取当前正在绘制的片段着色器的线的当前像素位置。

To draw a texture on a line you either have to use PointSprites or draw small textured Quads. 要在直线上绘制纹理,您必须使用PointSprites或绘制小的带纹理的PointSprites In my case I used Triangle_Strips and textured those because the line in my case could be small and still look exactly like a line. 在我的情况下,我使用了Triangle_Strips并对其进行了纹理处理,因为在我的情况下,该行可能很小,但仍然看起来像一条线。

If anyone has a better solution or has implemented the above feel free to post an answer! 如果有人有更好的解决方案或已实施上述方法,请随时发布答案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM