1、《OpenGL超级宝典》中对帧缓冲区的解释比较简单,文中说一个OpenGL窗口的表面被称作“帧缓冲区”。又查了一些资料可以更加容易理解一些,帧缓冲区(显存):是由像素组成的二维数组,每一个存储单元对应屏幕上的一个像素,整个帧缓冲对应一帧图像即当前屏幕画面。帧缓冲通常包括:颜色缓冲,深度缓冲,模板缓冲和累积缓冲。这些缓冲区可能是在一块内存区域,也可能单独分开,看硬件。
2、osg 屏幕坐标和世界坐标转换
//屏幕-〉世界:
osgUtil::SceneView::projectWindowIntoObject
//或者自己运算
Matrix VPW = camera->getViewMatrix() *
camera->getProjectionMatrix() *
camera->getViewport()->computeWindowMatrix();
Matrix inverseVPW = Matrix::inverse(VPW);
Vec3d world = window * inverseVPW;
//世界-〉屏幕:
osgUtil::SceneView::projectObjectIntoWindow
//或者自己运算
Matrix VPW = camera->getViewMatrix() *
camera->getProjectionMatrix() *
camera->getViewport()->computeWindowMatrix();
Vec3 window = world * VPW;
// 屏幕坐标转世界坐标
osg::Vec3d ScreenToWorld(const osg::Vec3d screen)
{
osg::Camera* camera = _global->Viewer->getCamera();
osg::Matrix VPW = camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix();
osg::Matrix inverseVPW = osg::Matrix::inverse(VPW);
osg::Vec3d world = screen * inverseVPW;
return world;
}
// 世界坐标转屏幕坐标
osg::Vec3d WorldToScreen(const osg::Vec3d world)
{
osg::Camera* camera = _global->Viewer->getCamera();
osg::Matrix VPW = camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix();
osg::Vec3d screen = world * VPW;
return screen;
}
// 世界坐标转经纬度
osg::Vec3d WorldToLonLatAlt(const osg::Vec3d world)
{
osg::EllipsoidModel* em = new osg::EllipsoidModel();
osg::Vec3d lonLatAlt;
em->convertXYZToLatLongHeight(world.x(), world.y(), world.z(), lonLatAlt.y(), lonLatAlt.x(), lonLatAlt.z());
lonLatAlt.x() = osg::RadiansToDegrees(lonLatAlt.x());
lonLatAlt.y() = osg::RadiansToDegrees(lonLatAlt.y());
return lonLatAlt;
}
// 经纬度转世界坐标
osg::Vec3d LonLatAltToWorld(const osg::Vec3d lonLatAlt)
{
osg::Vec3d world;
osg::EllipsoidModel* em = new osg::EllipsoidModel();
em->convertLatLongHeightToXYZ(osg::DegreesToRadians(lonLatAlt.y()), osg::DegreesToRadians(lonLatAlt.x()), lonLatAlt.z(), world.x(), world.y(), world.z());
return world;
}
// 屏幕坐标转经纬度
osg::Vec3d ScreenToLonLatAlt(const osg::Vec3d screen)
{
return WorldToLonLatAlt(ScreenToWorld(screen));
}
// 经纬度转屏幕坐标
osg::Vec3d LonLatAltToScreen(const osg::Vec3d lonLatAlt)
{
return WorldToScreen(LonLatAltToWorld(lonLatAlt));
}
///////////////////////////////////////////////////////////////////////////////////////////
osg::readNodeFile() 异常std::bab_alloc
j解决方法,我遇到的原因是vs中链接器->输入中的.lib文件用成了release版的了(osg的release版库:*.lib)而Debug版的库为*d.lib。因此只需要将链接器->输入 中的lib文件换成debug版的就可以了。
///////////////////////////////////////////////////////////////////////////////////////////
调试信息显示
OSG 可以将各式各样的调试信息输出到std:cout。这在开发OSG 程序时十分有用,你可以借此观察OSG 的执行的各种操作。环境变量OSG_NOTIFY_LEVEL用于控制OSG调试信息显示的数量。你可以将此变量设置为七个不同的信息量层级之一:ALWAYS(最简略),FATAL,WARN,NOTICE,INFO,DEBUG_INFO以及DEBUG_FP(最详细)。一个典型的OSG开发环境可以设置OSG_NOTIFY_LEVEL为NOTICE,如果要获取更多或者更少的输出信息,可以根据信息量的详细程度上下调整此变量。
新建(W) OSG_NOTIFY_LEVEL
值 DEBUG_FP
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
在OSG中
void setProjectionMatrixAsOrtho2D
(double left, double right, double bottom, double top)
它是一个特殊的正射投影函数,主要用于二维图像到二维屏幕上的投影。它的near和far缺省值
分别为-1.0和1.0,所有二维物体的Z坐标都为0.0。
因此它的裁剪面是一个左下角点为(left,bottom)、右上角点为(right,top)的矩形。
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
osgb是二进制文件
osg是文本文件
osgb可以通过osgconv.exe转换成osg文件
osgb可以包含纹理文件(就是贴图)
osg只能连接外部纹理文件(是的,你看到的cow.osg都是用的外部的reflect.rgb文件)
osgb转成osg带贴图的参数:
osgconv.exe --compressed Tile_+000_+000.osgb Tile_+000_+000.osg
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
Texture::setUnRefImageDataAfterApply当该值设置为true时,OSG在应用过该纹理对象后(apply),自动释放其对Image对象的引用,以减少内存占用
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use,
// you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default.
gc->getState()->setUseModelViewAndProjectionUniforms(true);
gc->getState()->setUseVertexAttributeAliasing(true);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Texture::setUnRefImageDataAfterApply当该值设置为true时,OSG在应用过该纹理对象后(apply),自动释放其对Image对象的引用,以减少内存占用
解决了,原因是osg本身在读取stl文件时会对该文件进行三角面的优化,我们只需要关闭该处优化就行了,在读取stl时传入下面这个参数:
osgDB::Options* option = new osgDB::Options(std::string("noTriStripPolygons"))