root/OpenSceneGraph/trunk/src/osg/DrawPixels.cpp @ 11472

Revision 11472, 3.3 kB (checked in by robert, 4 years ago)

Convesion of osg::notify to OSG_INFO etc.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13#include <osg/DrawPixels>
14
15using namespace osg;
16
17DrawPixels::DrawPixels()
18{
19    // turn off display lists right now, just incase we want to modify the projection matrix along the way.
20    setSupportsDisplayList(false);
21   
22    _position.set(0.0f,0.0f,0.0f);
23   
24    _useSubImage = false;
25    _offsetX = 0;
26    _offsetY = 0;
27    _width = 0;
28    _height = 0;
29}
30
31DrawPixels::DrawPixels(const DrawPixels& drawimage,const CopyOp& copyop):
32    Drawable(drawimage,copyop),
33    _position(drawimage._position),
34    _image(drawimage._image),
35    _useSubImage(drawimage._useSubImage),
36    _offsetX(drawimage._offsetX),
37    _offsetY(drawimage._offsetY),
38    _width(drawimage._width),
39    _height(drawimage._height)
40{
41}
42
43DrawPixels::~DrawPixels()
44{
45    // image will delete itself thanks to ref_ptr :-)
46}
47
48void DrawPixels::setPosition(const osg::Vec3& position)
49{
50    _position = position;
51    dirtyBound();
52}
53
54void DrawPixels::setSubImageDimensions(unsigned int offsetX,unsigned int offsetY,unsigned int width,unsigned int height)
55{
56    _useSubImage = true;
57    _offsetX = offsetX;
58    _offsetY = offsetY;
59    _width = width;
60    _height = height;
61}
62
63void DrawPixels::getSubImageDimensions(unsigned int& offsetX,unsigned int& offsetY,unsigned int& width,unsigned int& height) const
64{
65    offsetX = _offsetX;
66    offsetY = _offsetY;
67    width = _width;
68    height = _height;
69}
70
71
72BoundingBox DrawPixels::computeBound() const
73{
74    // really needs to be dependent of view position and projection... will implement simple version right now.
75    BoundingBox bbox;
76    float diagonal = 0.0f;
77    if (_useSubImage)
78    {
79        diagonal = sqrtf(_width*_width+_height*_height);
80    }
81    else
82    {
83        diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t());
84    }
85   
86    bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal));
87    bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal));
88    return bbox;
89}
90
91void DrawPixels::drawImplementation(RenderInfo&) const
92{
93#ifdef OSG_GL1_AVAILABLE
94    glRasterPos3f(_position.x(),_position.y(),_position.z());
95
96    if (_useSubImage)
97    {
98        const GLvoid* pixels = _image->data(_offsetX,_offsetY);
99        glPixelStorei(GL_UNPACK_ROW_LENGTH,_image->s());
100        glDrawPixels(_width,_height,
101                     (GLenum)_image->getPixelFormat(),
102                     (GLenum)_image->getDataType(),
103                     pixels);
104        glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
105    }
106    else
107    {
108        glDrawPixels(_image->s(), _image->t(),
109                     (GLenum)_image->getPixelFormat(),
110                     (GLenum)_image->getDataType(),
111                     _image->data() );
112    }
113#else
114    OSG_NOTICE<<"Warning: DrawPixels::drawImplementation(RenderInfo&) - not supported."<<std::endl;
115#endif
116}
Note: See TracBrowser for help on using the browser.