- Point3D center;
- calc_center_point( nodes, pnt_i, center );
- // cout << center[0] << "," << center[1] << "," << center[2] << endl;
-
-
- // find a vector perpendicular to the normal.
- osg::Vec3 perp1;
- if ( !vertical ) {
- // normal isn't vertical so we can use up as our first vector
- perp1 = up;
- } else {
- // normal is vertical so we have to work a bit harder to
- // determine our first vector
- osg::Vec3 pt1(nodes[pnt_i[0]][0], nodes[pnt_i[0]][1],
- nodes[pnt_i[0]][2] );
- osg::Vec3 pt2(nodes[pnt_i[1]][0], nodes[pnt_i[1]][1],
- nodes[pnt_i[1]][2] );
-
- perp1 = pt2 - pt1;
- }
- perp1.normalize();
-
- osg::Vec3Array *vl = new osg::Vec3Array;
- osg::Vec3Array *nl = new osg::Vec3Array;
- osg::Vec4Array *cl = new osg::Vec4Array;
-
- unsigned int i;
- for ( i = 0; i < pnt_i.size(); ++i ) {
- Point3D ppt = nodes[pnt_i[i]] - center;
- osg::Vec3 pt(ppt[0], ppt[1], ppt[2]);
- osg::Vec3 normal(normals[nml_i[i]][0], normals[nml_i[i]][1],
- normals[nml_i[i]][2] );
-
- // calculate a vector perpendicular to dir and up
- osg::Vec3 perp2 = normal^perp1;
-
- // front face
- osg::Vec3 tmp3 = pt;
- vl->push_back( tmp3 );
- tmp3 += perp1;
- vl->push_back( tmp3 );
- tmp3 += perp2;
- vl->push_back( tmp3 );
-
- nl->push_back( normal );
- nl->push_back( normal );
- nl->push_back( normal );
-
- cl->push_back(osg::Vec4(1, 1, 1, 1));
- cl->push_back(osg::Vec4(1, 1, 1, 0));
- cl->push_back(osg::Vec4(1, 1, 1, 0));
- }
-
- osg::Geometry* geometry = new osg::Geometry;
- geometry->setName("Dir Lights " + mat->get_names().front());
- geometry->setVertexArray(vl);
- geometry->setNormalArray(nl);
- geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
- geometry->setColorArray(cl);
- geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
- geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, vl->size()));
- osg::Geode* geode = new osg::Geode;
- geode->addDrawable(geometry);
-
- if (vasi) {
- // this one is dynamic in its colors, so do not bother with dlists
- geometry->setUseDisplayList(false);
- geometry->setUseVertexBufferObjects(false);
- osg::Vec3 dir(normals[nml_i[0]][0], normals[nml_i[0]][1],
- normals[nml_i[0]][2]);
-
- // calculate the reference position of this vasi and use it
- // to init the vasi structure
- Point3D ppt = nodes[pnt_i[0]] - center;
- osg::Vec3 pt(ppt[0], ppt[1], ppt[2]);
- // up is the "up" vector which is also
- // the reference center point of this tile. The reference
- // center + the coordinate of the first light gives the actual
- // location of the first light.
- pt += up;
-
- // Set up the callback
- geode->setCullCallback(new SGVasiUpdateCallback(cl, pt, up, dir));
- }
-
- if ( mat != NULL ) {
- geode->setStateSet(mat->get_state());
- } else {
- SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: material = NULL" );
- }
-
- // put an LOD on each lighting component
- osg::LOD *lod = new osg::LOD;
- lod->addChild( geode, 0, 20000 );
+ osg::Image* image = new osg::Image;
+
+ osg::Image::MipmapDataType mipmapOffsets;
+ unsigned off = 0;
+ for (int i = logResolution; 0 <= i; --i) {
+ unsigned res = 1 << i;
+ off += res*res;
+ mipmapOffsets.push_back(off);
+ }
+
+ int env_tex_res = (1 << logResolution);
+
+ unsigned char* imageData = new unsigned char[off];
+ image->setImage(env_tex_res, env_tex_res, 1,
+ GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, imageData,
+ osg::Image::USE_NEW_DELETE);
+ image->setMipmapLevels(mipmapOffsets);
+
+ for (int k = logResolution; 0 <= k; --k) {
+ setPointSpriteImage(image->getMipmapData(logResolution - k), k, 1);
+ }
+
+ return image;
+}