Hola a todos, el siguiente introducirá OpenGL ES base 3. texturas.
1, leer el archivo
Los archivos de imágenes se almacenarán lee en la memoria (de muchas maneras).
InputStream is = this.getResources().openRawResource(path);
Bitmap bitmapTmp;
try {
bitmapTmp = BitmapFactory.decodeStream(is);
}
finally {
try {
is.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
2. Cargar textura
Sube la memoria de datos a memoria.
void GLAPIENTRY glTexImage2D (GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels);
target:
dimensiones Textura GL_TEXTURE_1D GL_TEXTURE_2D GL_TEXTURE_3D. level:
nivel mapa MIP, por lo general pone a 0. internalformat:
Cada número de componente textura de color en la unidad de almacenamiento. width、height、depth:
Anchura de las texturas cargado, altura, profundidad. Acostumbrado a utilizar el poder de dos a establecer estos parámetros. border:
Se permite especificar el ancho del borde de un mapa de textura. format:
formato de píxel OpenGL. type:
Explicar los parámetros de datos de píxeles apuntaban a contar OpenGL qué tipo de datos Uso de la zona de amortiguamiento de componentes del almacén de colores en el tipo de datos de los datos de píxeles. pixels:
Puntero a los datos de los gráficos.
Además, el método también puede ser usado texImage2D de GLUtils.
GLUtils.texImage2D(
GLES30.GL_TEXTURE_2D, //纹理类型
0, //纹理的层次,0表示基本图像层,可以理解为直接贴图
bitmapTmp, //纹理图像
0 //纹理边框尺寸
);
bitmapTmp.recycle(); //纹理加载成功后释放内存中的纹理图
3, establecer el parámetro de textura
void glTexParameterf (GLenum target, GLenum pname, GLint param);
void glTexParameteri (GLenum target, GLenum pname, GLint param);
void glTexParameterfv (GLenum target, GLenum pname, GLint param);
void glTexParameteriv (GLenum target, GLenum pname, GLint param);
target
: Textura Dimensiones GL_TEXTURE_1D GL_TEXTURE_2D GL_TEXTURE_3D. pname
: ¿Qué parámetros de textura especifica la necesidad de configurar. param
: Valor especificado de un parámetros de textura particulares.
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, //设置纹理采样方式
GLES30.GL_TEXTURE_MIN_FILTER,GLES30.GL_NEAREST); //纹理缩小时,临近采样
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,
GLES30.GL_TEXTURE_MAG_FILTER,GLES30.GL_LINEAR); //纹理放大时,线性采样
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,
GLES30.GL_TEXTURE_WRAP_S,GLES30.GL_CLAMP_TO_EDGE); //S方向环绕方式
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,
GLES30.GL_TEXTURE_WRAP_T,GLES30.GL_CLAMP_TO_EDGE); //T方向环绕方式
4. Crear un objeto de la textura
void glGenTextures (GLsizei n, GLuint *textures);
La textura objeto especificado 数量
y 指针
(puntero a una matriz de enteros sin signo, el relleno de textura objeto identificador).
int[] textures = new int[1];
GLES30.glGenTextures(
1, //产生的纹理id的数量
textures, //纹理id的数组
0 //偏移量
);
5, los Estados textura vinculantes
void glBindTexture (GLenum target, GLuint texture);
target:
GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D. texture:
El objeto de la textura está obligado.
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId);//绑定纹理
6, eliminar el objeto textura
void glDeleteTextures (GLsizei n, const GLuint *textures);
7, una pequeña muestra
public void initTexture()//textureId
{
//生成纹理ID
int[] textures = new int[1];
GLES30.glGenTextures(
1, //产生的纹理id的数量
textures, //纹理id的数组
0 //偏移量
);
textureId=textures[0];
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId);//绑定纹理
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, //设置纹理采样方式
GLES30.GL_TEXTURE_MIN_FILTER,GLES30.GL_NEAREST);
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,GLES30.GL_TEXTURE_MAG_FILTER,
GLES30.GL_LINEAR);
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,
GLES30.GL_TEXTURE_WRAP_S,GLES30.GL_CLAMP_TO_EDGE);
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D,
GLES30.GL_TEXTURE_WRAP_T,GLES30.GL_CLAMP_TO_EDGE);
//通过输入流加载图片===============begin===================
InputStream is = this.getResources().openRawResource(R.drawable.wall);
Bitmap bitmapTmp;
try {
bitmapTmp = BitmapFactory.decodeStream(is);
}
finally {
try {
is.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
//通过输入流加载图片===============end=====================
//实际加载纹理进显存
GLUtils.texImage2D(
GLES30.GL_TEXTURE_2D, //纹理类型
0, //纹理的层次,0表示基本图像层,可以理解为直接贴图
bitmapTmp, //纹理图像
0 //纹理边框尺寸
);
bitmapTmp.recycle(); //纹理加载成功后释放内存中的纹理图
}
Por último, damos la bienvenida al intercambio de aprender juntos: Carta de micro: liaosy666; QQ: 2209115372 .