//By smells2 at Lab 2012-02-21
#include <osg/Group>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osgViewer/Viewer>
#include <osgDB/readfile>

#include <osg/PositionAttitudeTransform>
#include <osg/TexEnv>
#include <osg/Texture2D>
#include <iostream>
int main()
{
osg::ref_ptr<osg::Group> root = new osg::Group;
osgViewer::Viewer myViewer;

//Declear Sphere instance,the constructor takes an osg::vec3 to define
//center and a float to define the radius.
//Then we declear the ShapDrawable instance that derive from Drawable .We should
//initalize it with the shape we create above .
osg::ref_ptr<osg::Geode> unitSphere = new osg::Geode;
osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(osg::Vec3(0,0,0), 1.0f);
osg::ref_ptr<osg::ShapeDrawable> shapeDrawable = new osg::ShapeDrawable(sphere.get());
unitSphere->addDrawable(shapeDrawable.get());
osg::ref_ptr<osg::PositionAttitudeTransform> sphereForm = new osg::PositionAttitudeTransform;
sphereForm->setPosition(osg::Vec3(2.5,0.0,0.0));
sphereForm->addChild(unitSphere.get());
root->addChild(sphereForm.get());

//load image from the file
osg::ref_ptr<osg::Texture2D> earthTexture = new osg::Texture2D;
earthTexture->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::Image> earthImage = osgDB::readImageFile("D:\\OSG\\osg2.9\\OpenSceneGraph2.9.5\\data\\Images\\land_shallow_topo_2048.jpg");
if (!earthImage.get())
{
std::cout<<"load texture failed !"<<std::endl;
return -1;
}

//assign the texture from the image file
earthTexture->setImage(earthImage.get());

//set the stateset for decal texture
osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
texenv->setMode(osg::TexEnv::DECAL);
stateset->setTextureAttributeAndModes(0,earthTexture.get(),osg::StateAttribute::ON);
stateset->setTextureAttribute(0,texenv.get());

//realize
root->setStateSet(stateset.get());
myViewer.setSceneData(root.get());
myViewer.realize();
myViewer.run();
}

osg绘制一个球体的更多相关文章

  1. Three.js 第一篇:绘制一个静态的3D球体

    第一篇就画一个球体吧 首先我们知道Three.js其实是一个3D的JS引擎,其中的强大之处就在于这个JS框架并不是依托于JQUERY来写的.那么,我们在写这一篇绘制3D球体的文章的时候,应该注意哪些地 ...

  2. opengl学习笔记(五):组合变换,绘制一个简单的太阳系

    创建太阳系模型 描述的程序绘制一个简单的太阳系,其中有一颗行星和一颗太阳,用同一个函数绘制.需要使用glRotate*()函数让这颗行星绕太阳旋转,并且绕自身的轴旋转.还需要使用glTranslate ...

  3. [Modern OpenGL系列(三)]用OpenGL绘制一个三角形

    本文已同步发表在CSDN:http://blog.csdn.net/wenxin2011/article/details/51347008 在上一篇文章中已经介绍了OpenGL窗口的创建.本文接着说如 ...

  4. 使用canvas绘制一个时钟

    周末学习canvas的一些基础功能,顺带写了一个基础的时钟.现在加工一下,做的更好看一点,先放上效果图: 谈一些自己的理解: (1).要绘制一个新的样式(不想被其他样式影响,或者影响到其他样式),那么 ...

  5. iOS----自定义UIView,绘制一个UIView

    绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时,drawRect:方 ...

  6. IOS 中openGL使用教程2(openGL ES 入门篇 | 绘制一个多边形)

    在上一篇我们学习了如何搭建IOS下openGL的开发环境,接下来我们来学习如何绘制一个多边形. 在2.0之前,es的渲染采用的是固定管线,何为固定管线,就是一套固定的模板流程,局部坐标变换 -> ...

  7. OSG第一个Demo

    环境:Vs2010 OpenSceneGraph-3.0.1-VS10.0.30319-x86-debug-12741 OpenSceneGraph-3.0.1-VS10.0.30319-x86-re ...

  8. HTML5 在canvas绘制一个矩形

    笔者:本笃庆军 原文地址:http://blog.csdn.net/qingdujun/article/details/32930501 一.绘制矩形 canvas使用原点(0,0)在左上角的坐标系统 ...

  9. 绘制一个绿色矩形平面((50, 50)->(350, 350))

    //VS2008+opencv2.4 //绘制一个绿色矩形平面 #include "stdafx.h" #include "highgui.h" #includ ...

随机推荐

  1. “RESTful架构”相关资料收藏

    [阮一峰]理解RESTful架构 [InfoQ]深入浅出REST 用于构建 RESTful Web 服务的多层架构 REST会是SOA的未来吗? Restful 与 SOA 的关系? 回答1: 注意r ...

  2. springmvc之定时器

    一.通过注解方式实现定时器 1.工程结构 2.所需jar包 3.spring-config.xml,springmvc配置文件 <?xml version="1.0" enc ...

  3. setImageResource和setBackgroundResource的區別

    它們的原型如下:void android.widget.ImageView.setImageResource(int resId)void android.view.View.setBackgroun ...

  4. HDU 4927 Series 1(高精度+杨辉三角)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927 解题报告:对于n,结果如下: C(0,n-1) *A[n] - C(1,n-1) * A[n-1 ...

  5. iOS开发——项目篇—高仿百思不得姐

    01 一.包装为导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewControll ...

  6. php写入txt换行符

    1.问题 写入txt文件想换行,老是直接输出了\r\n. 2.解决 要用双引号对\r\n进行解释,否则php会直接当字符输出. 3.例子 要求:往test.txt文本每一行后面加abc $a=file ...

  7. http基础实战

    1.需求 了解http的基础知识,能看懂chrome下网络的情况 2.前置知识 下面是tcp/ip协议的一些东西,今天就只用了解应用层的http就够了. 3.http是什么 我们在网上浏览网页,会发送 ...

  8. jquery的change():下拉框值改变时触发

    <script src="jquery.min.js" type="text/javascript"></script> <scr ...

  9. OAuth 2.0攻击面与案例总结

    本文整理了OAuth 2.0的攻击面+实际案例+辅助测试代码. OAuth流程 本文以两种广泛使用的方案为标准展开..如对流程不了解,请先移步学习: 理解OAuth 2.0 Authorization ...

  10. apache2 + virtualenv +djangocms

    命令记录: cd /var/www makedir django cd django/ virtualenv env --no-site-packages source /var/www/django ...