Fixed indentation

This commit is contained in:
Robert Osfield 2013-06-11 10:49:57 +00:00
parent b0a28a5b2c
commit 4623c251bb

View File

@ -14,7 +14,7 @@ static const char* vertSource = {
"in vec4 osg_Vertex;\n" "in vec4 osg_Vertex;\n"
"out vec3 vPosition;\n" "out vec3 vPosition;\n"
"void main(){\n" "void main(){\n"
" vPosition = osg_Vertex.xyz;\n" " vPosition = osg_Vertex.xyz;\n"
"}\n" "}\n"
}; };
static const char* tessControlSource = { static const char* tessControlSource = {
@ -113,9 +113,9 @@ static const char* fragSource = {
}; };
osg::ref_ptr<osg::Geode> CreateIcosahedron(osg::Program *program){ osg::ref_ptr<osg::Geode> CreateIcosahedron(osg::Program *program){
osg::Geode *geode=new osg::Geode(); osg::Geode *geode=new osg::Geode();
osg::Geometry *geometry = new osg::Geometry(); osg::Geometry *geometry = new osg::Geometry();
const unsigned int Faces[] = { const unsigned int Faces[] = {
2, 1, 0, 2, 1, 0,
3, 2, 0, 3, 2, 0,
4, 3, 0, 4, 3, 0,
@ -139,7 +139,7 @@ osg::ref_ptr<osg::Geode> CreateIcosahedron(osg::Program *program){
4, 9, 8, 4, 9, 8,
5, 10, 9, 5, 10, 9,
1, 6, 10 }; 1, 6, 10 };
int IndexCount = sizeof(Faces) / sizeof(Faces[0]); int IndexCount = sizeof(Faces) / sizeof(Faces[0]);
const float Verts[] = { const float Verts[] = {
0.000f, 0.000f, 1.000f, 0.000f, 0.000f, 1.000f,
0.894f, 0.000f, 0.447f, 0.894f, 0.000f, 0.447f,
@ -155,28 +155,28 @@ osg::ref_ptr<osg::Geode> CreateIcosahedron(osg::Program *program){
0.000f, 0.000f, -1.000f }; 0.000f, 0.000f, -1.000f };
int VertexCount = sizeof(Verts)/sizeof(float); int VertexCount = sizeof(Verts)/sizeof(float);
osg::Vec3Array* vertices = new osg::Vec3Array(); osg::Vec3Array* vertices = new osg::Vec3Array();
for(int i=0;i<VertexCount;i+=3){ for(int i=0;i<VertexCount;i+=3){
vertices->push_back(osg::Vec3(Verts[i],Verts[i+1],Verts[i+2])); vertices->push_back(osg::Vec3(Verts[i],Verts[i+1],Verts[i+2]));
} }
geometry->setVertexArray(vertices); geometry->setVertexArray(vertices);
geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::PATCHES,IndexCount,Faces)); geometry->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::PATCHES,IndexCount,Faces));
geode->addDrawable(geometry); geode->addDrawable(geometry);
return geode; return geode;
} }
osg::ref_ptr<osg::Program> createProgram(){ osg::ref_ptr<osg::Program> createProgram(){
osg::Program *program = new osg::Program(); osg::Program *program = new osg::Program();
program->addShader(new osg::Shader(osg::Shader::VERTEX,vertSource)); program->addShader(new osg::Shader(osg::Shader::VERTEX,vertSource));
program->addShader(new osg::Shader(osg::Shader::TESSCONTROL,tessControlSource)); program->addShader(new osg::Shader(osg::Shader::TESSCONTROL,tessControlSource));
program->addShader(new osg::Shader(osg::Shader::TESSEVALUATION,tessEvalSource)); program->addShader(new osg::Shader(osg::Shader::TESSEVALUATION,tessEvalSource));
program->addShader(new osg::Shader(osg::Shader::GEOMETRY,geomSource)); program->addShader(new osg::Shader(osg::Shader::GEOMETRY,geomSource));
program->addShader(new osg::Shader(osg::Shader::FRAGMENT,fragSource)); program->addShader(new osg::Shader(osg::Shader::FRAGMENT,fragSource));
program->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3); program->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 3);
program->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES); program->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES);
program->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP); program->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);
program->setParameter(GL_PATCH_VERTICES,3); program->setParameter(GL_PATCH_VERTICES,3);
return program; return program;
} }
float tessInner=1.0f; float tessInner=1.0f;
@ -186,62 +186,62 @@ osg::ref_ptr<osg::Uniform> tessOuterU = new osg::Uniform("TessLevelOuter",tessOu
class KeyboardEventHandler : public osgGA::GUIEventHandler { class KeyboardEventHandler : public osgGA::GUIEventHandler {
public: public:
KeyboardEventHandler():osgGA::GUIEventHandler(){} KeyboardEventHandler():osgGA::GUIEventHandler(){}
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& gaa){ virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& gaa){
if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN){ if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN){
switch (ea.getKey()){ switch (ea.getKey()){
case osgGA::GUIEventAdapter::KEY_Up: case osgGA::GUIEventAdapter::KEY_Up:
tessOuter++; tessOuter++;
tessOuterU->set(tessOuter); tessOuterU->set(tessOuter);
return true; return true;
case osgGA::GUIEventAdapter::KEY_Down: case osgGA::GUIEventAdapter::KEY_Down:
tessOuter--; tessOuter--;
tessOuter=std::max(1.0f,tessOuter); tessOuter=std::max(1.0f,tessOuter);
tessOuterU->set(tessOuter); tessOuterU->set(tessOuter);
return true; return true;
case osgGA::GUIEventAdapter::KEY_Left: case osgGA::GUIEventAdapter::KEY_Left:
tessInner--; tessInner--;
tessInner=std::max(1.0f,tessInner); tessInner=std::max(1.0f,tessInner);
tessInnerU->set(tessInner); tessInnerU->set(tessInner);
return true; return true;
case osgGA::GUIEventAdapter::KEY_Right: case osgGA::GUIEventAdapter::KEY_Right:
tessInner++; tessInner++;
tessInnerU->set(tessInner); tessInnerU->set(tessInner);
return true; return true;
} }
} }
return osgGA::GUIEventHandler::handle(ea,gaa); return osgGA::GUIEventHandler::handle(ea,gaa);
} }
}; };
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
viewer.setUpViewInWindow(100,100,800,600); viewer.setUpViewInWindow(100,100,800,600);
osg::ref_ptr<osg::Program> program = createProgram(); osg::ref_ptr<osg::Program> program = createProgram();
osg::ref_ptr<osg::Geode> geode = CreateIcosahedron(program.get()); osg::ref_ptr<osg::Geode> geode = CreateIcosahedron(program.get());
osg::StateSet *state; osg::StateSet *state;
state = geode->getOrCreateStateSet(); state = geode->getOrCreateStateSet();
state->addUniform(new osg::Uniform("AmbientMaterial",osg::Vec3(0.04f, 0.04f, 0.04f))); state->addUniform(new osg::Uniform("AmbientMaterial",osg::Vec3(0.04f, 0.04f, 0.04f)));
state->addUniform(new osg::Uniform("DiffuseMaterial",osg::Vec3(0.0f, 0.75f, 0.75f))); state->addUniform(new osg::Uniform("DiffuseMaterial",osg::Vec3(0.0f, 0.75f, 0.75f)));
state->addUniform(new osg::Uniform("LightPosition",osg::Vec3(0.25f, 0.25f, 1.0f))); state->addUniform(new osg::Uniform("LightPosition",osg::Vec3(0.25f, 0.25f, 1.0f)));
state->addUniform(tessInnerU.get()); state->addUniform(tessInnerU.get());
state->addUniform(tessOuterU.get()); state->addUniform(tessOuterU.get());
state->setAttribute(program.get()); state->setAttribute(program.get());
// switch on the uniforms that track the modelview and projection matrices // switch on the uniforms that track the modelview and projection matrices
osgViewer::Viewer::Windows windows; osgViewer::Viewer::Windows windows;
viewer.getWindows(windows); viewer.getWindows(windows);
for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); for(osgViewer::Viewer::Windows::iterator itr = windows.begin();
itr != windows.end(); itr != windows.end();
++itr) ++itr)
{ {
osg::State *s=(*itr)->getState(); osg::State *s=(*itr)->getState();
s->setUseModelViewAndProjectionUniforms(true); s->setUseModelViewAndProjectionUniforms(true);
s->setUseVertexAttributeAliasing(true); s->setUseVertexAttributeAliasing(true);
} }
viewer.addEventHandler(new KeyboardEventHandler()); viewer.addEventHandler(new KeyboardEventHandler());
viewer.setSceneData(geode.get()); viewer.setSceneData(geode.get());
return viewer.run(); return viewer.run();
} }