Opengl学习笔记之Texture 2D Array
来源:互联网 发布:深圳经济数据 编辑:程序博客网 时间:2024/06/08 00:04
Array Textures 范例来自 OpenGl SuperBible(page 177-182),并做了些改动。
1.vertex shader 中改了 vs_out.alien = alien_index % 2;
因为我使用了两张图片。sampler2DArray对象的texture()函数采样的纹理坐标参数的z即指定使用纹理数组内图片的索引。
(color = texture(tex_onePiece, vec3(fs_in.tc, float(fs_in.alien)));
)
2.使用DevIL加载图片,il只需执行一次,放置在start()内
ilInit(); ilGenImages(2, images); ilEnable(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_LOWER_LEFT); LoadImageIndex("Lunamon.gif", 0); LoadImageIndex("images.jpg", 1); GenerateTextureObject();
void LoadImageIndex(string imageName, int index) { ilBindImage(images[index]); ILboolean success = ilLoadImage(imageName.c_str()); ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if (!success) { ilDeleteImages(1, images); } } void GenerateTextureObject() { // general sampler glGenSamplers(1, &samplers); glSamplerParameteri(samplers, GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(samplers, GL_TEXTURE_WRAP_T, GL_REPEAT); glSamplerParameteri(samplers, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(samplers, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindSampler(textureUnit, samplers); // texture object and texture 2d array glGenTextures(2, textures); glBindTexture(GL_TEXTURE_2D_ARRAY, textures[0]); //allocate memory: depth is the length of texture 2d array glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 100, 100, 100); ilBindImage(images[0]); int w = ilGetInteger(IL_IMAGE_WIDTH); int h = ilGetInteger(IL_IMAGE_HEIGHT); unsigned char * data = ilGetData(); //init pixel datas: zoffset is 0 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE, data); ilBindImage(images[1]); int w1 = ilGetInteger(IL_IMAGE_WIDTH); int h1 = ilGetInteger(IL_IMAGE_HEIGHT); unsigned char * data1 = ilGetData(); //init pixel datas: zoffset is 1 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, w1 , h1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data1); // 2d texture glBindTexture(GL_TEXTURE_2D, textures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w1, h1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data1); }
在编译时遇到一些问题:
1.glTexStorage3D()与glTexSubImage3D()的参数设置有问题。google了一些资料。
OpenGL ES: Array Texture初体验
Array Textures
2.GL_TRIANGLE_STRIP
编译成功运行结果:
阅读全文
0 0
- Opengl学习笔记之Texture 2D Array
- OpenGL学习:2D texture
- OpenGL之纹理贴图(2):Texture Objects
- openGL ES 2.0 笔记 texture
- opengl编程学习笔记(三)(2D绘图)
- opengl学习笔记3-2-在3D中画线
- openGL学习笔记6 bmp 2D纹理贴图
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- OpenGL 3D 超级宝典学习笔记
- OpenGL学习笔记(5)3D基本概念
- Texture Array
- 二维纹理 Texture 2D
- 二维纹理 Texture 2D
- OpenGL&CG技术之Render To Texture
- OpenGL学习笔记之配置OpenGL
- OpenGL学习笔记之了解OpenGL
- android学习笔记之3D--(02)-OPenGL ES常用API
- SpringMVC 数据绑定
- codeforces 820B
- [牛客网,剑指offer,python] 从头到尾打印链表
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘测(LCT)
- java虚拟机字节码执行引擎之解释执行
- Opengl学习笔记之Texture 2D Array
- 精确4SAT问题np完全性证明
- 朴素贝叶斯的mapreduce的java实现
- 输入非法数字时进行判断并返回值TryParse
- hadoop2.7.2编译成功的一个配置
- 关于2017上半年的总结及对下半年的计划
- gulp配置
- C++实现100个数字排序
- BaseAdapter的stableIds用处