2002-04-11 05:51:34 +08:00
|
|
|
#include <osg/DrawPixels>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
DrawPixels::DrawPixels()
|
|
|
|
{
|
|
|
|
// turn off display lists right now, just incase we want to modify the projection matrix along the way.
|
|
|
|
setSupportsDisplayList(false);
|
|
|
|
|
|
|
|
_position.set(0.0f,0.0f,0.0f);
|
|
|
|
|
|
|
|
_useSubImage = false;
|
|
|
|
_offsetX = 0;
|
|
|
|
_offsetY = 0;
|
|
|
|
_width = 0;
|
|
|
|
_height = 0;
|
|
|
|
}
|
|
|
|
|
2002-04-11 21:53:46 +08:00
|
|
|
DrawPixels::DrawPixels(const DrawPixels& drawimage,const CopyOp& copyop):
|
2002-04-11 05:51:34 +08:00
|
|
|
Drawable(drawimage,copyop),
|
|
|
|
_position(drawimage._position),
|
|
|
|
_image(drawimage._image),
|
|
|
|
_useSubImage(drawimage._useSubImage),
|
|
|
|
_offsetX(drawimage._offsetX),
|
|
|
|
_offsetY(drawimage._offsetY),
|
|
|
|
_width(drawimage._width),
|
|
|
|
_height(drawimage._height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPixels::~DrawPixels()
|
|
|
|
{
|
|
|
|
// image will delete itself thanks to ref_ptr :-)
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawPixels::setPosition(const osg::Vec3& position)
|
|
|
|
{
|
|
|
|
_position = position;
|
|
|
|
dirtyBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawPixels::setSubImageDimensions(unsigned int offsetX,unsigned int offsetY,unsigned int width,unsigned int height)
|
|
|
|
{
|
|
|
|
_useSubImage = true;
|
|
|
|
_offsetX = offsetX;
|
|
|
|
_offsetY = offsetY;
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawPixels::getSubImageDimensions(unsigned int& offsetX,unsigned int& offsetY,unsigned int& width,unsigned int& height) const
|
|
|
|
{
|
|
|
|
offsetX = _offsetX;
|
|
|
|
offsetY = _offsetY;
|
|
|
|
width = _width;
|
|
|
|
height = _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool DrawPixels::computeBound() const
|
2002-04-11 05:51:34 +08:00
|
|
|
{
|
|
|
|
// really needs to be dependant of view poistion and projection... will implement simple version right now.
|
|
|
|
_bbox.init();
|
|
|
|
float diagonal = 0.0f;
|
|
|
|
if (_useSubImage)
|
|
|
|
{
|
|
|
|
diagonal = sqrtf(_width*_width+_height*_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t());
|
|
|
|
}
|
|
|
|
|
|
|
|
_bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal));
|
|
|
|
_bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal));
|
|
|
|
_bbox_computed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-11-06 23:43:11 +08:00
|
|
|
void DrawPixels::drawImplementation(State&) const
|
2002-04-11 05:51:34 +08:00
|
|
|
{
|
|
|
|
glRasterPos3f(_position.x(),_position.y(),_position.z());
|
|
|
|
|
|
|
|
if (_useSubImage)
|
|
|
|
{
|
2002-09-02 20:31:35 +08:00
|
|
|
const GLvoid* pixels = _image->data(_offsetX,_offsetY);
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH,_image->s());
|
2002-04-11 05:51:34 +08:00
|
|
|
glDrawPixels(_width,_height,
|
2002-04-16 22:57:39 +08:00
|
|
|
(GLenum)_image->getPixelFormat(),
|
|
|
|
(GLenum)_image->getDataType(),
|
2002-04-11 05:51:34 +08:00
|
|
|
pixels);
|
2002-09-02 20:31:35 +08:00
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH,0);
|
2002-04-11 05:51:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glDrawPixels(_image->s(), _image->t(),
|
2002-04-16 22:57:39 +08:00
|
|
|
(GLenum)_image->getPixelFormat(),
|
|
|
|
(GLenum)_image->getDataType(),
|
2002-04-11 05:51:34 +08:00
|
|
|
_image->data() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|