OPENGL如何使用glTexImage3D函数 [英] OPENGL how to use glTexImage3D function

查看:1424
本文介绍了OPENGL如何使用glTexImage3D函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于绘制海洋,我试图将其转换为C#代码,但由于我不了解3D函数的功能,所以我失败了,所以我想对这些函数进行一些解释(我的意思是3D纹理) ...

the following code is used to draw an ocean, i tried to convert it to c# code, but i failed because i didn't understand what 3d functions do, so i want some explanation on these functions (3d texture i mean)...

int res = 64;
int nr = res / 2;
int nv = res * 2;
int nb = res / 2;
int na = 8;
f = fopen("E:\\New folder\\ConsoleApplication1\\Debug\\data\\inscatter.raw", "rb");
data = new float[nr*nv*nb*na*4];
fread(data, 1, nr*nv*nb*na*4*sizeof(float), f);
fclose(f);
glActiveTexture(GL_TEXTURE0 + INSCATTER_UNIT);
glGenTextures(1, &inscatterTex);
glBindTexture(GL_TEXTURE_3D, inscatterTex);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F_ARB, na*nb, nv, nr, 0, GL_RGBA, GL_FLOAT, data);
delete[] data;

推荐答案

3D纹理是体积图像,即它们就像是一个长方体,充满了彩色体素.因此,有一张width × height × depth · color_channels的图片代替了width × height · color_channels的图片.

3D textures are volumetric images, i.e. they're sort of a cuboid filled with voxels of color. So instead of a picture of width × height · color_channels you have a picture of width × height × depth · color_channels.

这是一个显示体积图像的动画(我是研究小组的研究室):

This is an animation showing a volumetric image (courtsey of the research working group I'm a member of): http://www.bmo.physik.uni-muenchen.de/~z19/OCTanimation.gif (unfortunately StackOverflow doesn't allow linking of animated GIFs).

我看到了某人.其他是关于海洋渲染的另一篇文章.请注意,这是一个非常重要的主题,需要一些非常复杂的算法.使用称为嵌入"的3D纹理表明,无论您查询的是什么代码,都将实现那些复杂的模型之一,其中将3D纹理用作散射项查找表.

I saw that sb. else was about ocean rendering in another post. Be advised that this is a hugely nontrivial subject requiring some very sophisticated algorithms. The use of a 3D texture called "inscatter" suggests that whatever code you've looked up implements one of those complex models, where the 3D texture is used as a scattering term lookup table.

请注意,如果没有对OpenGL和实现海洋渲染器的数值方法的扎实的理解,几乎是不可能执行任务的.我将从首先了解基础知识开始.

Note that without a solid understanding of OpenGL and numerical methods implementing an ocean renderer is a almost impossible to perform task. I'd start with understanding the basics first.

这篇关于OPENGL如何使用glTexImage3D函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆