osg蝴蝶纹理
#include <osgViewer/Viewer>
#include <osgDB/WriteFile>
#include <osg/StateSet>
#include <osg/Texture>
#include <osg/Texture2D>
#include <osg/Image>
#include <cmath>
#include <osgDB/ReadFile>
#pragma comment(lib, "osgd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgGAd.lib")
const int FFT_SIZE = ;
const int PASSES = ;
const int N = ;
const float M_PI = osg::PI; int bitReverse(int i, int N)
{
int j = i;
int M = N;
int Sum = ;
int W = ;
M = M / ;
while (M != ) {
j = (i & M) > M - ;
Sum += j * W;
W *= ;
M = M / ;
}
return Sum;
}
void computeWeight(int N, int k, float &Wr, float &Wi)
{
Wr = cosl(2.0 * M_PI * k / float(N));
Wi = sinl(2.0 * M_PI * k / float(N));
} osg::ref_ptr<osg::Image> CreateImage()
{
osg::ref_ptr<osg::Image> image = new osg::Image;
image->allocateImage(FFT_SIZE, PASSES, , GL_RGBA, GL_FLOAT);
image->setInternalTextureFormat(GL_RGBA16);
osg::Vec4 * data = (osg::Vec4 *)image->data();
for (int i = ; i < PASSES; i++) {
int nBlocks = (int) powf(2.0, float(PASSES - - i));
int nHInputs = (int) powf(2.0, float(i));
for (int j = ; j < nBlocks; j++) {
for (int k = ; k < nHInputs; k++) {
int i1, i2, j1, j2;
if (i == ) {
i1 = j * nHInputs * + k;
i2 = j * nHInputs * + nHInputs + k;
j1 = bitReverse(i1, FFT_SIZE);
j2 = bitReverse(i2, FFT_SIZE);
} else {
i1 = j * nHInputs * + k;
i2 = j * nHInputs * + nHInputs + k;
j1 = i1;
j2 = i2;
}
float wr, wi;
computeWeight(FFT_SIZE, k * nBlocks, wr, wi);
int offset1 = (i1 + i * FFT_SIZE);
data[offset1]._v[] = (j1 + 0.5) / FFT_SIZE;
data[offset1]._v[] = (j2 + 0.5) / FFT_SIZE;
data[offset1]._v[] = wr;
data[offset1]._v[] = wi;
int offset2 = (i2 + i * FFT_SIZE);
data[offset2]._v[] = (j1 + 0.5) / FFT_SIZE;
data[offset2]._v[] = (j2 + 0.5) / FFT_SIZE;
data[offset2]._v[] = -wr;
data[offset2]._v[] = -wi;
}
}
}
return image.get();
}
osg::ref_ptr<osg::Geode> CreateQuad()
{
osg::ref_ptr<osg::Geode> quad = new osg::Geode;
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vArray = new osg::Vec3Array;
osg::ref_ptr<osg::Vec2Array> tArray = new osg::Vec2Array;
vArray->push_back(osg::Vec3(-1.0, -1.0, 0.0));
vArray->push_back(osg::Vec3(1.0, -1.0, 0.0));
vArray->push_back(osg::Vec3(1.0, 1.0, 0.0));
vArray->push_back(osg::Vec3(-1.0, 1.0, 0.0)); tArray->push_back(osg::Vec2(0.0, 0.0));
tArray->push_back(osg::Vec2(1.0, 0.0));
tArray->push_back(osg::Vec2(1.0, 1.0));
tArray->push_back(osg::Vec2(0.0, 1.0)); geometry->setVertexArray(vArray.get());
geometry->setTexCoordArray(, tArray.get()); geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, , vArray->size()));
quad->addDrawable(geometry.get());
return quad.get();
} osg::ref_ptr<osg::StateSet> SetUpImageStateSet(osg::ref_ptr<osg::Image> image)
{
osg::ref_ptr<osg::StateSet> stateSet = new osg::StateSet;
osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
texture2D->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture2D->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
texture2D->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
texture2D->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
texture2D->setImage(image.get());
stateSet->setTextureAttributeAndModes(, texture2D.get(), osg::StateAttribute::ON);
return stateSet.get();
} int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setUpViewInWindow(, , , ); osg::ref_ptr<osg::Geode> quad = CreateQuad();
quad->setStateSet(SetUpImageStateSet(CreateImage().get()));
viewer->setSceneData(quad.get());
viewer->getCamera()->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
viewer->run();
return EXIT_SUCCESS;
}
osg蝴蝶纹理的更多相关文章
- osg添加纹理示例
转自http://www.cnblogs.com/ylwn817/articles/1976851.html #include <osgDB/ReadFile>#include <o ...
- ocean所用的蝴蝶纹理
#include <ork/render/FrameBuffer.h> #include <ork/scenegraph/SceneManager.h> #include &l ...
- OSG学习:计算纹理坐标
在很多时候,直接指定纹理坐标是非常不方便的,如曲面纹理坐标,只有少数的曲面(如圆锥.圆柱等)可以在不产生扭曲的情况下映射到平面上,其他的曲面在映射到表面时都会产生一定程度的扭曲.一般而言,曲面表面的曲 ...
- osg纯手工画球+贴纹理
手动计算球面顶点的坐标,纹理坐标,来画球并贴纹理 其中createSphereGeom()函数的的二个参数为18,意思是在经纬度上每10度设一个点,因为经度一共是180度,180/18=10,相当于横 ...
- osg使用shader动态修改纹理坐标
#include <osg/Node> #include <osg/Geometry> #include <osg/Notify> #include <osg ...
- OSG绘制金字塔geode+动态纹理坐标
osg::Node* createPyramidModel() { // create the root node which will hold the model. osg::Group* roo ...
- osg::Texture2D 贴纹理
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include<iostream> #include <osgV ...
- OpenSceneGraph | OSG如何存储带纹理osgb格式可以节省空间
在使用OSG(OpenSceneGraph)存储带纹理osgb格式的过程中,大家会遇到这样一种情况:存储后的osgb文件所占用的大小远大于原始文件的大小,几倍至几十倍.这是为何呢?原因是OSG默认 ...
- 基于osg的python三维程序开发(三)------几何形体及纹理
def createScene(): geode = osg.Geode() pointsGeom = osg.Geometry() vertices = osg.Vec3Array() vertic ...
随机推荐
- 上锁 - leetcode
158. Read N Characters Given Read4 II - Call multiple times 题目: The API: int read4(char *buf) reads ...
- JS 高效快速的数组去重
Array.prototype.uniquer = function() { var result = [], hash = {}; ; i < this.length; i++) { if ( ...
- Unity3D消息:消息传递函数
- hdu 3480 Division(斜率优化DP)
题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思 ...
- mysql 数据库知识
order by 字段 将查到的list集合按指定字段升序排序 order by 字段 DESC 将查到的list集合按指定字段降序排序 GROUP BY 语句用于结合合计函数,根据一个或多 ...
- delphi变量作用域
完全摘自网络(一件飘雪),供参考: 很多初学者对delphi单元的变量和函数访问权限不理解,在此我举例说明,希望初学者看此文后能茅塞顿开. delphi单元的变量和函数访问权限问题如下两个单元描述: ...
- SharpZipLib.dll 压缩文件,可以应用于MVC, webform. C# windows application 等等地方
Nuget 安装:Install-Package ICSharpCode.SharpZipLib.dll private void WriteZipFile(string[] filesToZip, ...
- 高一的我曾对自己说"要放慢脚步去生活"!?
看了高一的时候自己写的日记,瞬间被自己感动到了.以下是当时的几段感慨: 慢是一种放松.是生活的一种良好心态,喜欢这样放慢步伐地生活,那是一种享受! 但我们生活在一个快节奏的时代,我们总是被迫卷进那潮流 ...
- 101个linq例子
FirstOrDefault - Simple public void Linq61() { int[] numbers = { }; int firstNumOrDefault = numbers. ...
- 当今Web应用的主要技术
WWW是World Wide Web的简称,缩写为W3C,称为万维网,也简称为Web.目前Internet已经普及到整个社会,其中Web应用已经称为Internet上最受欢迎的应用之一,正是由于它的出 ...