Added a bunch of files synched with 0.8.42
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
#include "osg/Image"
|
||||
#include "osg/Input"
|
||||
#include "osg/Output"
|
||||
#include "osg/GL"
|
||||
#include "osg/Notify"
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/GeoState>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Texture>
|
||||
|
||||
#include <GL/glu.h>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Image::Image()
|
||||
{
|
||||
_fileName = NULL;
|
||||
_fileName = "";
|
||||
_s = _t = _r = 0;
|
||||
_internalFormat = 0;
|
||||
_pixelFormat = (unsigned int)0;
|
||||
@@ -26,26 +26,22 @@ Image::Image()
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if (_fileName) ::free(_fileName);
|
||||
if (_data) ::free(_data);
|
||||
}
|
||||
|
||||
|
||||
void Image::setFileName(const char* fileName)
|
||||
void Image::setFileName(const std::string& fileName)
|
||||
{
|
||||
if (_fileName) ::free(_fileName);
|
||||
|
||||
if (fileName) _fileName = strdup(fileName);
|
||||
else _fileName = NULL;
|
||||
_fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
void Image::setImage(int s,int t,int r,
|
||||
int internalFormat,
|
||||
unsigned int pixelFormat,
|
||||
unsigned int dataType,
|
||||
void Image::setImage(const int s,const int t,const int r,
|
||||
const int internalFormat,
|
||||
const unsigned int pixelFormat,
|
||||
const unsigned int dataType,
|
||||
unsigned char *data,
|
||||
int packing)
|
||||
const int packing)
|
||||
{
|
||||
if (_data) ::free(_data);
|
||||
|
||||
@@ -58,48 +54,23 @@ void Image::setImage(int s,int t,int r,
|
||||
_dataType = dataType;
|
||||
|
||||
_data = data;
|
||||
|
||||
|
||||
|
||||
if (packing<0)
|
||||
{
|
||||
if (_s%4==0)
|
||||
_packing = 4;
|
||||
else
|
||||
_packing = 1;
|
||||
_packing = 1;
|
||||
}
|
||||
else
|
||||
_packing = packing;
|
||||
|
||||
// scaleImageTo(16,16,_r);
|
||||
|
||||
// test scaling...
|
||||
// scaleImageTo(16,16,_r);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool Image::readLocalData(Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
if (fr[0].matchWord("file") && fr[1].isString())
|
||||
{
|
||||
//loadFile(fr[1].getStr());
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
|
||||
bool Image::writeLocalData(Output& fw)
|
||||
{
|
||||
if (_fileName)
|
||||
{
|
||||
fw.indent() << "file \""<<_fileName<<"\""<<endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::scaleImage(int s,int t,int /*r*/)
|
||||
void Image::scaleImage(const int s,const int t,const int /*r*/)
|
||||
{
|
||||
if (_data==NULL) return;
|
||||
|
||||
@@ -109,20 +80,21 @@ void Image::scaleImage(int s,int t,int /*r*/)
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,_packing);
|
||||
|
||||
GLint status = gluScaleImage((GLenum)_pixelFormat,
|
||||
_s,
|
||||
_t,
|
||||
(GLenum)_dataType,
|
||||
_data,
|
||||
s,
|
||||
t,
|
||||
(GLenum)_dataType,
|
||||
newData);
|
||||
|
||||
if (status==0) {
|
||||
|
||||
_s,
|
||||
_t,
|
||||
(GLenum)_dataType,
|
||||
_data,
|
||||
s,
|
||||
t,
|
||||
(GLenum)_dataType,
|
||||
newData);
|
||||
|
||||
if (status==0)
|
||||
{
|
||||
|
||||
// free old image.
|
||||
::free(_data);
|
||||
|
||||
|
||||
_s = s;
|
||||
_t = t;
|
||||
_data = newData;
|
||||
@@ -135,29 +107,34 @@ void Image::scaleImage(int s,int t,int /*r*/)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Image::ensureDimensionsArePowerOfTwo()
|
||||
{
|
||||
float sp2 = logf((float)_s)/logf(2.0f);
|
||||
float rounded_sp2 = floorf(sp2+0.5f);
|
||||
int new_s = (int)(powf(2.0f,rounded_sp2));
|
||||
|
||||
|
||||
float tp2 = logf((float)_t)/logf(2.0f);
|
||||
float rounded_tp2 = floorf(tp2+0.5f);
|
||||
int new_t = (int)(powf(2.0f,rounded_tp2));
|
||||
|
||||
|
||||
if (new_s!=_s && new_t!=_t)
|
||||
{
|
||||
notify(NOTICE) << "Scaling image '"<<_fileName<<"' from ("<<_s<<","<<_t<<") to ("<<new_s<<","<<new_t<<")"<<endl;
|
||||
if (!_fileName.empty()) notify(NOTICE) << "Scaling image '"<<_fileName<<"' from ("<<_s<<","<<_t<<") to ("<<new_s<<","<<new_t<<")"<<endl;
|
||||
else notify(NOTICE) << "Scaling image from ("<<_s<<","<<_t<<") to ("<<new_s<<","<<new_t<<")"<<endl;
|
||||
|
||||
scaleImage(new_s,new_t,_r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Geode* osg::createGeodeForImage(osg::Image* image)
|
||||
{
|
||||
return createGeodeForImage(image,image->s(),image->t());
|
||||
}
|
||||
|
||||
Geode* osg::createGeodeForImage(osg::Image* image,float s,float t)
|
||||
|
||||
Geode* osg::createGeodeForImage(osg::Image* image,const float s,const float t)
|
||||
{
|
||||
if (image)
|
||||
{
|
||||
@@ -167,20 +144,19 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t)
|
||||
float y = 1.0;
|
||||
float x = y*(s/t);
|
||||
|
||||
// set up the texture.
|
||||
// set up the texture.
|
||||
osg::Texture* texture = new osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
// set up the geostate.
|
||||
osg::GeoState* gstate = new osg::GeoState;
|
||||
gstate->setMode(osg::GeoState::FACE_CULL,osg::GeoState::OFF);
|
||||
gstate->setMode(osg::GeoState::LIGHTING,osg::GeoState::OFF);
|
||||
gstate->setMode(osg::GeoState::TEXTURE,osg::GeoState::ON);
|
||||
gstate->setAttribute(osg::GeoState::TEXTURE,texture);
|
||||
// set up the drawstate.
|
||||
osg::StateSet* dstate = new osg::StateSet;
|
||||
dstate->setMode(GL_CULL_FACE,osg::StateAttribute::OFF);
|
||||
dstate->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
dstate->setAttributeAndModes(texture,osg::StateAttribute::ON);
|
||||
|
||||
// set up the geoset.
|
||||
osg::GeoSet* gset = new osg::GeoSet;
|
||||
gset->setGeoState(gstate);
|
||||
gset->setStateSet(dstate);
|
||||
|
||||
osg::Vec3* coords = new Vec3 [4];
|
||||
coords[0].set(-x,0.0f,y);
|
||||
@@ -198,7 +174,7 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t)
|
||||
gset->setTextureBinding(osg::GeoSet::BIND_PERVERTEX);
|
||||
|
||||
osg::Vec4* colours = new Vec4;
|
||||
colours->set(1.0f,1.0f,1.0,0.0f);
|
||||
colours->set(1.0f,1.0f,1.0,1.0f);
|
||||
gset->setColors(colours);
|
||||
gset->setColorBinding(osg::GeoSet::BIND_OVERALL);
|
||||
|
||||
@@ -207,7 +183,7 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t)
|
||||
|
||||
// set up the geode.
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geode->addGeoSet(gset);
|
||||
geode->addDrawable(gset);
|
||||
|
||||
return geode;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user