【问题标题】:Android OpenGL Circle Texture DoubledAndroid OpenGL 圆形纹理加倍
【发布时间】:2015-11-01 02:24:26
【问题描述】:

我正在尝试绘制带有纹理的圆形,它应该在所有顶点上拉伸。

问题是我得到的结果是这样的:

http://s14.postimg.org/3wyb74469/image.png

我尝试根据需要绘制三角扇,第一个坐标在 0,0,0 并根据需要休息:

http://escience.anu.edu.au/lecture/cg/surfaceModeling/image/surfaceModeling015.png

这里也是同样的问题,我无法从中得到答案:

OpenGL ES, add texture to circle

加载圆顶点坐标函数:

private final int mVerticesDataSize = 3;    
private final int mNumberOfVertices = 180;
private final int mBytesPerFloat = 4;   
private float[] vertices;
private  FloatBuffer mVerticesBuff;

public void loadCircleVerticesBuff(Context mActivityContext){

       mVerticesBuff = ByteBuffer.allocateDirect(mNumberOfVertices * mVerticesDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                            
       vertices = new float[mNumberOfVertices * mVerticesDataSize];
       float theta = 0;


       for (int i = 0; i < (mNumberOfVertices * mVerticesDataSize); i += 3) {   
       vertices[i] = (float) (((float) 5*Math.cos(theta)));
       vertices[i + 1] = (float) ((float) 5*Math.sin(theta));
       vertices[i + 2] = 0;
       theta += Math.PI / 90;
       }

       mVerticesBuff.put(vertices);
       mVerticesBuff.position(0);          
}

加载圆纹理坐标函数:

private final int mTextureCoordinateDataSize = 3;
public void loadCircleTextureBuff(){
    mCircleTextureCoordinatesBuff = ByteBuffer.allocateDirect(mNumberOfVertices * mTextureCoordinateDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                          
    mCircleTextureCoordinatesBuff.put(vertices);
    mCircleTextureCoordinatesBuff.position(0);
}

用于绘图的opengl函数是:

 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, mNumberOfVertices);  

【问题讨论】:

  • 我从未直接使用过 OpenGL,但根据我使用 SFML 的经验,您的纹理似乎没有被“拉伸”。您的精灵比您要绘制的表面小,因此它以重复的模式绘制(默认行为)。有没有办法将你的纹理/精灵设置为缩放/拉伸?
  • 嗨 ^^ 通常是的,这是解决方案......但不幸的是,在这种情况下,这不是纹理图像大小):但也许是的,我忘了使用一些拉伸标志,但我知道是哪一个这是 。请看第三个链接,我给出了同样的问题“OpenGL ES, add texture to circle”
  • 您链接的问题有答案。虽然很短,但我认为它清楚地解释了解决方案。您不能对顶点位置和纹理坐标使用相同的值来获得所需的结果。使用正确的纹理坐标定义单独的顶点属性,或者在顶点着色器中移动/缩放值。

标签: android opengl-es textures geometry


【解决方案1】:

所以找到了解决方案(:我错过了 1 件非常非常重要的事情/或 openGL 错过了。

纹理坐标只能在 0 到 1 的范围内。

所以这是技巧/解决方案:

//Build vertices :
vertices[i] = (float) (((float) raduis*Math.cos(theta)))+raduis;
vertices[i + 1] = (float) ((float) raduis*Math.sin(theta))+raduis;

// Build texture :
 for (int i = 0; i < (mNumberOfVertices * mVerticesDataSize); i += 3) {   
           vertices[i] = (vertices[i])/(raduis*2);
           vertices[i + 1] = (vertices[i+1])/(raduis*2);
           vertices[i + 2] = 0;
  }

这里是资源:

http://s2.postimg.org/tno4jr4y1/image.png

别忘了翻转纹理顶点,因为我忘了(:

【讨论】:

    猜你喜欢
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多