OpenGL es2.0 加载纹理图片和CubMap
2015-03-31 08:39
260 查看
一、加载纹理:
二、加载CubMap:
public static int initTexture(int drawableId, Resources resources) { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); int textureId = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); InputStream is = resources.openRawResource(drawableId); Bitmap bitmapTmp; try { bitmapTmp = BitmapFactory.decodeStream(is); } finally { try { is.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapTmp, 0); bitmapTmp.recycle(); return textureId; }
二、加载CubMap:
public static int initCubeMap(int[] resourceIds, Resources resources) { int[] ids = new int[1]; GLES20.glGenTextures(1, ids, 0); int cubeMapTextureId = ids[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, cubeMapTextureId); GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameterf(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); for (int face = 0; face < 6; face++) { InputStream is = resources.openRawResource(resourceIds[face]); Bitmap bitmap; try { bitmap = BitmapFactory.decodeStream(is); } finally { try { is.close(); } catch (Exception e) { // TODO: handle exception Log.e("CubeMap", "Could ont decode texture for face " + Integer.toString(face)); } } GLUtils.texImage2D(GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, bitmap, 0); bitmap.recycle(); } return cubeMapTextureId; }
相关文章推荐
- OpenGL es2.0 加载纹理图片和CubMap
- OpenGL es2.0 加载纹理图片和CubMap
- OpenGL中不用AUX库来加载BMP图片作为纹理[转载]
- iPhone OpenGL ES加载纹理的方法
- OpenGL ES2.0教程:纹理贴图(6)
- openGL es2.0 创建纹理球
- openGL es2.0 创建可移动的纹理平面
- OpenGL中不用AUX库来加载BMP图片作为纹理
- 【C#/OpenGL】CSGL中2D纹理加载PNG等透明图片显示的黑边问题
- TexturePacker打包图片并使用addImageAsync实现longding界面异步加载图片纹理---cocos2d-x学习之路
- OpenGL ES2.0 生成Mipmap纹理
- 解决Scaleform中使用AS2.0的UILoader不加载图片的问题
- Opengl ES2.0之mipmap纹理技术小结
- cocos2d中如何使用图片纹理图集的加载来实现一个动画的功能
- OpenGL9-(FreeImage)加载图片-作为纹理
- unity3d,通过WWW加载图片纹理
- 从图片加载纹理-使用glut工具
- Android Opengl ES 2.0 纹理贴图
- 从后台返回游戏的时候,新增弹出窗口的图片在android不加载(纹理变黑)的解决办法
- opengl利用SOIL加载图片dds纹理