OpenGl第三章后续,纹理,绘制图片,文字

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;
   }  


有需要的可以下载我的代码,写的不好,见谅!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值