Using OpenSceneGraph in Your Application读书笔记

本文详细介绍了如何在程序中使用OpenSceneGraph (OSG)进行渲染,并探讨了从底层实现到利用OSG提供的高级功能的各种方法。文章还对比了直接控制OpenGL与使用OSG简化流程的不同之处。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 今天看英文好像怎么都不大看得进去,索性一边看一遍翻译(所以估计很多地方表诉得都不准确),权当增进理解,同时集中注意力了,呵呵

 

3 Using OpenSceneGraph in Your Application

在程序中使用OSG

 

Real applications need to do more than build a scene graph and write it out to a file. This chapter explores techniques for integrating OSG into your application. You’ll learn how to render a scene graph, change the view, perform picking operations, and dynamically modify scene graph data.

具体的应用程序不仅仅需要建立一个场景并把它输出保存到一个文件中。本章将会探索如何把OSG与应用程序整合起来。通过本章的学习,你将会了解到如何渲染一个场景,改变view,执行采摘操作及如何动态的(实时的)修改场景中的数据。

 

3.1 Rendering

渲染

OSG doesn’t hide any functionality. OSG exposes the lowest levels of its functionality to your application. If you want complete scene graph rendering control, you can write code to perform the following operations in your application.

OSG 没有封装任何的功能。相反,它还提供其最底层的功能函数。如果你想要完全控制一个场景图形的渲染,你可以在应用程序中用代码实现下列操作:

 

l  Develop your own view management code to modify the OpenGL model-view matrix.

l  Create a window and an OpenGL context, and make them current. Write the code to manage multiple windows and contexts if your application requires it.

l  If your application uses paged databases, start the osgDB::DatabasePager

l  Instantiate osgUtil::UpdateVisitor, osgUtil::CullVisitor, and osgUtil::RenderStage objects to implement the update, cull, and draw traversals. If you really want total control, design your own classes to perform these traversals.

l  Write a main loop that handles events from the operating system. Call into your view code to update the model-view matrix.

l  Call glClear() before rendering a frame. Execute update, cull, and draw traversals to render, and then swap buffers.

l  Write additional code to support stereo and multipipe rendering if your applilcation or target platform requires it.

l  Finally, write all of this code in a platform-independent manner, so it works with all target platforms.

 

l  设计你自己的视图操作代码以用来修改OpenGL model-view 矩阵

l  创建一个窗口及一个OpenGL上下文,并make them current。如果你的程序要求的话,同时添加对于多个窗口及上下文的控制

l  如果你的程序使用了分页式数据库的话,启动osgDB::DatabasePager

l  实例化osgUtil::UpdateVisitor, osgUtil::CullVisitor osgUtil::RenderStage 对象,用于执行更新、拣选及绘制遍历。如果你想做到全盘控制,则需要自己定义书写你自己的遍历类

l  写一个由操作系统控制的事件句柄控制的主循环。同时调用你自己的视图来更新model-view 矩阵

l   渲染每一帧之前,调用glClear()函数。执行更新、拣选和绘制遍历, 然后交换缓存

l  编写额外的代码来支持立体及多管道渲染,如果你的程序或目标平台需要如此的话

l  在平台独立的前提下书写这些代码来确保其可以在任何平台上运行

 

This is possible to do, but tedious and time consuming. It’s also potentially incompatible with future versions of OSG that might modify some of the low-level interfaces that such an application uses.

这样做是可行的,但同时也是单调且浪费时间的。而且,这也可能与未来的OSG版本不匹配,因为OSG可能会修改在应用程序中使用到的底层的接口。

 

Fortunately, OSG has evolved over time to increasingly incorporate functionality that makes it easier for applications to render. As you work with OSG, you might encounter some of these utilities and libraries.

幸运的是,经过长时间的进化,OSG的功能已经使应用程序的渲染变得非常的简单。随着你对OSG的使用,一定会遇到类似的Utilities和库文件。

 

l  osgUtil::SceneView – A class that wraps the update, cull, and draw traversals, but doesn’t start the DatabasePager. There are several applications that use SceneView as their main interface for rendering in OSG.

l  Producer and osgProducer-Producer is an external camera library that supports multipipe rendering. osgProducer is a library that unifies OSG and Producer for application usage. Producer has an active user base, and there are many Producer – and osgProducer-based OSG application today.

l  osgUtil::SceneView – 它一个包含了更新、拣选和绘制遍历的类,但是并不会启动DatabasePager。有好几个程序都是用SceneView作为其OSG渲染的主要接口

l  ProducerosgProducer – Producer是一个外部摄像机库文件,该文件支持多管道渲染。osgProducer是一个库文件,它为应用程序的应用统一了OSGProducerProducer拥有一个active user base, 至今,已经有非常多的Producer- osgProducer-based OSG应用程序了。

 

OSG v2.0 adds a new library to the core OSG libraries – the osgViewer library. osgViewer contains a set of viewer classes that encapsulate a large amount of functionality commonly required by applications, such as display management, event handling, and rendering. It uses the osg::Camera class to manipulate the OpenGL model-view matrix. Unlike the SceneView class, the osgViewer library’s viewer classes provide full support for the DatabasePager. osgViewer also simplifies support for multiple independent views into the same scene graph.

OSG 2.0版本增加了一个OSG核心库文件——osgViewerosgViewer包含一系列的viewer类,这些类封装了大量的应用程序常用功能;例如显示管理、时间控制及渲染。它使用osg::Camera类来控制OpenGLmodel-view矩阵。与SceneView类不同的是,osgViewer库文件所包含的各个viewer类都支持DatabasePager. osgViewer同时也基本支持多个独立的视图into到同一个场景中。

 

Section 1.6.3 Components provides an overview of the osgViewer of the osgViewer library’s two viewer classes, Viewer, and CompositeViewer. This chapter demonstrates how your application can use the Viewer class to implement OSG rendering functionality.

1.6.3节(组件)对osgViewer库文件的两个viewer类(Viewer类和compositeViewer类)做了大概的介绍。本章将介绍如何在应用程序中使用Viewer类来执行OSG的渲染功能。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值