//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. HDOJ 3709 Balanced Number

    数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java ...

  2. bug--java访问hdfs (Server IPC version 9 cannot communicate with client version 4 错误)

    1. 今天想做一个hdfs的java工具类,但是在连接hdfs的时候,报如下错误: Exception in thread "main" org.apache.hadoop.ipc ...

  3. input注意事项

    一.更改place-holder颜色 input::-webkit-input-placeholder { color: #D6D0CA !important; /* WebKit browsers ...

  4. iOS开发——网络篇——NSURLSession,下载、上传代理方法,利用NSURLSession断点下载,AFN基本使用,网络检测,NSURLConnection补充

    一.NSURLConnection补充 前面提到的NSURLConnection有些知识点需要补充 NSURLConnectionDataDelegate的代理方法有一下几个 - (void)conn ...

  5. [HDU4507]吉哥系列故事——恨7不成妻

    [HDU4507]吉哥系列故事--恨7不成妻 试题描述 单身!依然单身!吉哥依然单身!DS级码农吉哥依然单身!所以,他生平最恨情人节,不管是214还是77,他都讨厌!吉哥观察了214和77这两个数,发 ...

  6. phpcms 根据条件调取内容

    asdasdsd <script> 正则 截取 function getUrlParam(name) { var reg = new RegExp("(^|&)" ...

  7. BZOJ 4580: [Usaco2016 Open]248

    Description 一个序列,每次可以把相邻的两个数合为一个,价值+1,求最后的最大价值. Sol 区间DP. \(f[i][j]\) 表示 \(i-j\) 中合成一个数字为多少,转移就是枚举断点 ...

  8. linux回收站设计

    linux回收站设计 在windows下有一个很好的东西,那就是回收站,虽然有很多人批评它.linux不是没有回收站,很多桌面环境都可以看到是有回收站的. 这里是讨论如何设计一个回收站,而不是有没有的 ...

  9. __getattr__ 与动态属性

    直接上代码 >>> class Test(object): ... def __getattr__(self,attr_name): ... setattr(self, attr_n ...

  10. Python 正则表达式:只要整数和小数

    要求用户只能输入数字(包括整数和小数),如何用正则表达式验证用户输入? 有两种思路: 1. 给出正确格式的正则表达式,然后看输入是否合法. 2. 列出所有错误的输入,看输入是否非法. 对于思路1,想想 ...