【Android OpenGL ES 开发 (四)】纹理相关(一)
生活随笔
收集整理的這篇文章主要介紹了
【Android OpenGL ES 开发 (四)】纹理相关(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
紋理貼圖的原理
1.作用:可以用來渲染視頻。
2.紋理坐標
生成OpenGL中的紋理對象
1.像素數據想要繪制出來需要先變成紋理
2.創建紋理放在GPU上
GLuint CreateTexture2D(unsigned char *pixelData,int width,int height,GLenum type) {GLuint texture;glGenTextures(1,&texture);//創建一個紋理對象glBindTexture(GL_TEXTURE_2D,texture);//設置成當前要操作的2D紋理glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//線性過濾glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);//GL_CLAMP,U方向glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);//V方向glTexImage2D(GL_TEXTURE_2D,0,type,width,height,0,type,GL_UNSIGNED_BYTE,pixelData);//GL_RGBA,像素數據發送到顯卡上去glBindTexture(GL_TEXTURE_2D,0);//伴讀return texture; }紋理貼圖在Shader中的修改
VS
attribute vec4 position; attribute vec4 texcoord; //紋理坐標 uniform mat4 U_ModelMatrix; uniform mat4 U_ViewMatrix; uniform mat4 U_ProjectionMatrix; varying vec4 V_Texcoord; void main(){V_Texcoord = texcoord;gl_Position = U_ProjectionMatrix*U_ViewMatrix*U_ModelMatrix*position; }FS?
#ifdef GL_ES precision mediump float; #endif uniform sampler2D U_Texture; //紋理圖片 varying vec4 V_Texcoord; void main(){gl_FragColor = texture2D(U_Texture,V_Texcoord.xy); }3.插入紋理
glBindTexture(GL_TEXTURE_2D,texture);//設置紋理?
總結
以上是生活随笔為你收集整理的【Android OpenGL ES 开发 (四)】纹理相关(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Pixel Tablet 平板有望加入手
- 下一篇: 【安卓开发 】Android初级开发(一