OpenGl第三章后续,纹理,绘制图片,文字,直接
// 创建文理
gl.glEnable(GL10.GL_TEXTURE_2D);
texturesBuffer = IntBuffer.allocate(1);
gl.glGenTextures(1, texturesBuffer);
gl.glBindTexture(GL10.GL_TEXTURE_2D, texturesBuffer.get(0));
// 设置文理的参数
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
// 把这个纹理放进去
// Bitmap texture = BufferUtil.getTextureFromBitmapResource(context, R.drawable.ic_launcher);
Bitmap texture =initFontBitmap();
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0);
texture.recycle();
//获取要绘制的文字
public Bitmap initFontBitmap(){
String font = "需要渲染的文字测试!";
Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
//背景颜色
canvas.drawColor(Color.LTGRAY);
Paint p = new Paint();
//字体设置
String fontType = "宋体";
Typeface typeface = Typeface.create(fontType, Typeface.BOLD);
//消除锯齿
p.setAntiAlias(true);
//字体为红色
p.setColor(Color.RED);
p.setTypeface(typeface);
p.setTextSize(28);
//绘制字体
canvas.drawText(font, 0, 100, p);
return bitmap;
}
有需要的可以下载我的代码,写的不好,见谅!!!!