void initialise() { glClearColor(0.0f, 1.0f, 1.0f, 1.0f); projection = glm::perspective(30.0f, 800.0f/600.0f, 0.1f, 10000.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); shaders[0] = loadShader("diffuse.vert", GL_VERTEX_SHADER); shaders[1] = loadShader("diffuse.frag", GL_FRAGMENT_SHADER); if (shaders[0] && shaders[1]) { program = createProgram(shaders, 2); if (!program) exit(EXIT_FAILURE); } else exit(EXIT_FAILURE); MVPuniform = glGetUniformLocation(program, "modelViewProjection"); MITuniform = glGetUniformLocation(program, "modelInverseTranspose"); diffuseMaterialUniform = glGetUniformLocation(program, "diffuseMaterial"); diffuseLightUniform = glGetUniformLocation(program, "diffuseLight"); lightDirUniform = glGetUniformLocation(program, "lightDir"); //object.geometry = createSierpinski(5); object.geometry = createTorus(4, 100, 100); object.transform.position = glm::vec3(0.0f, 0.5f, 0.0f); }
void readGeometry(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); for (; iter != pt.end(); ++iter) { std::string name = iter->first; geometry* geom; if (name == "cube") geom = createBox(); else if (name == "tetrahedron") geom = createTetrahedron(); else if (name == "pyramid") geom = createPyramid(); else if (name == "disk") { int slices = iter->second.get_child("slices").get_value<int>(); geom = createDisk(slices); } else if (name == "cylinder") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createCylinder(stacks, slices); } else if (name == "sphere") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createSphere(stacks, slices); } else if (name == "torus") { float radius = iter->second.get_child("radius").get_value<float>(); int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createTorus(radius, stacks, slices); } else if (name == "plane") { int width = iter->second.get_child("width").get_value<int>(); int depth = iter->second.get_child("depth").get_value<int>(); geom = createPlane(width, depth); } else if (name == "sierpinski") { int divisions = iter->second.get_child("divisions").get_value<int>(); geom = createSierpinski(divisions); } else { std::cerr << "Error - Geometry type not recognised: " << name << std::endl; exit(EXIT_FAILURE); } scene->geometry[name] = geom; } }
osg::Node *createOrientatedTorus(float innerRadius, float outerRadius) { osg::Node *node = createTorus(innerRadius, outerRadius, 64, 32); osg::PositionAttitudeTransform *transform = new osg::PositionAttitudeTransform(); transform->addChild(node); osg::Quat q = osg::Quat( M_PI / 2, osg::Vec3d(1, 0, 0), 0, osg::Vec3d(0, 1, 0), 0, osg::Vec3d(0, 0, 1)); transform->setAttitude(q); // transform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); // node->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON); return transform; }
MyWindow () : GlutWindow ( 200, 100, 400, 400, "ARB_shader_atomic_counters" ) { glClearColor ( 0.5, 0.5, 0.5, 1.0 ); glEnable ( GL_DEPTH_TEST ); glDepthFunc ( GL_LEQUAL ); const char * err = getGlErrorString (); if ( !program.loadProgram ( "atomic-counters.glsl" ) ) { printf ( "Error building program: %s\n", program.getLog ().c_str () ); exit ( 2 ); } else printf ( "Shader loaded:\n%s\n", program.getLog ().c_str () ); mesh = createTorus ( 2, 4, 30, 30 ); counterBuf.create (); counterBuf.bindBase ( GL_ATOMIC_COUNTER_BUFFER, 0 ); // unbind ??? }
void init() { gameScore = 0; //Texture Object definition glGenTextures(12, textureArray); TGA_Texture(textureArray, "stone.tga", 0); TGA_Texture(textureArray, "checker.tga", 1); TGA_Texture(textureArray, "pause.tga", 2); TGA_Texture(textureArray, "death.tga", 3); TGA_Texture(textureArray, "tree.tga", 4); TGA_Texture(textureArray, "particle.tga", 5); TGA_Texture(textureArray, "lensFlare/Flare1.tga", 6); TGA_Texture(textureArray, "lensFlare/Flare2.tga", 7); TGA_Texture(textureArray, "lensFlare/Flare3.tga", 8); TGA_Texture(textureArray, "lensFlare/Flare4.tga", 9); TGA_Texture(textureArray, "lensFlare/Sun.tga", 10); TGA_Texture(textureArray, "lensFlare/SunLight.tga", 11); srand(time(NULL)); for (int i = 0; i < 10; i++) { Car* life = new Car(); life->setPosition(-5.0f + 0.5f*i, -4.0, 5.0f); _lives.push_back(life); } car.setPosition(0.0f, 0.45f, 2.8f); carX = car.getPosition().getX(); carY = car.getPosition().getY(); carZ = car.getPosition().getZ(); std::vector<Car> cars; cars.push_back(car); orangeArray.push_back(orange1); orangeArray.push_back(orange2); orangeArray.push_back(orange3); for (int i = 0; i < orangeArray.size(); i++) { orangeArray[i].init(); } staticObjects.push_back(&butter1); staticObjects.push_back(&butter2); staticObjects.push_back(&butter1ref); staticObjects.push_back(&butter2ref); for (int i = 0; i < 128; i++) { Cheerio* cheerio = new Cheerio(); cheerioArray.push_back(*cheerio); } float xBot = 2.4f; float yBot = 2.5f; float xTop = -2.4f; float yTop = -3.6f; float xRight = 2.4f; float yRight = -2.1f; float xLeft = -2.4f; float yLeft = -2.1f; for (int i = 0; i < 17; i++) { cheerioArray[i].setPosition(xBot - 0.3f * i, 0.52f, yBot); cheerioArray[i+17].setPosition(xBot - 0.3f * i, 0.52f, yBot + 1.2f); cheerioArray[i+34].setPosition(xTop + 0.3f * i, 0.52f, yTop); cheerioArray[i+51].setPosition(xTop + 0.3f * i, 0.52f, yTop + 1.2f); } for (int i = 0; i < 15; i++) { cheerioArray[i+68].setPosition(xRight, 0.52f, yRight + 0.3f * i); cheerioArray[i+83].setPosition(xRight + 1.2f, 0.52f, yRight + 0.3f * i); cheerioArray[i+98].setPosition(xLeft, 0.52f, yLeft + 0.3f * i); cheerioArray[i+113].setPosition(xLeft - 1.2f, 0.52f, yLeft + 0.3f * i); } butter1.setPosition(3.6f, 0.5f, 3.0f); butter2.setPosition(-3.4f, 0.5f, -4.0f); butter1ref.setPosition(3.6f, 0.5f, 3.0f); butter2ref.setPosition(-3.4f, 0.5f, -4.0f); table.setPosition(-4.5, 0.5f, -4.5f); pauseScreen.setPosition(-2.5, -2.5, 5.0f); deathScreen.setPosition(-2.5, -2.5, 5.0f); HUDbg.setPosition(-5.5, -4.0, 0.0f); broccoli[0].setPosition(1.5f, 0.5f, 1.5f); broccoli[1].setPosition(1.5f, 0.5f, -1.5f); broccoli[2].setPosition(-1.5f, 0.5f, -1.5f); broccoli[3].setPosition(-1.5f, 0.5f, 1.5f); sun.setPosition(5.0f, 2.0f, -5.0f); cup.setPosition(-1.5f, 1.0f, 0.0f); speed = Vector3(0.0f, 0.0f, 0.0f); // set the camera position based on its spherical coordinates camX = r * sin(alpha * 3.14f / 180.0f) * cos(beta * 3.14f / 180.0f); camZ = r * cos(alpha * 3.14f / 180.0f) * cos(beta * 3.14f / 180.0f); camY = r * sin(beta * 3.14f / 180.0f); float amb[]= {0.2f, 0.15f, 0.1f, 1.0f}; float diff[] = {0.8f, 0.6f, 0.4f, 1.0f}; float spec[] = {0.8f, 0.8f, 0.8f, 1.0f}; float emissive[] = {0.0f, 0.0f, 0.0f, 1.0f}; float shininess= 100.0f; int texcount = 0; // create geometry and VAO of the pawn objId=0; memcpy(mesh[objId].mat.ambient, amb,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); float amb1[] = { 0.1f, 0.1f, 0.1f, 1.0f }; float diff1[] = { 0.4f, 0.4f, 0.4f, 1.0f }; float spec1[] = { 0.5f, 0.5f, 0.5f, 1.0f }; shininess = 50.0f; // create geometry and VAO of the sphere objId=1; memcpy(mesh[objId].mat.ambient, amb1,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff1,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec1,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); // create geometry and VAO of the cylinder float amb2[] = { 0.2f, 0.2f, 0.2f, 1.0f }; float diff2[] = { 0.8f, 0.8f, 0.8f, 1.0f }; float spec2[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 50.0f; objId=2; memcpy(mesh[objId].mat.ambient, amb2,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff2,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec2,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); float amb3[] = { 0.1f, 0.075f, 0.0f, 1.0f }; float diff3[] = { 0.8f, 0.6f, 0.0f, 1.0f }; float spec3[] = { 0.3f, 0.3f, 0.3f, 1.0f }; shininess = 50.0f; // create geometry and VAO of the objId=3; memcpy(mesh[objId].mat.ambient, amb3,4*sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff3,4*sizeof(float)); memcpy(mesh[objId].mat.specular, spec3,4*sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive,4*sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(0.04f, 0.1f, 6, 10); //BlackWheels objId = 4; float amb4[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float diff4[] = { 0.3f, 0.3f, 0.3f, 1.0f }; float spec4[] = { 0.5f, 0.5f, 0.5f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb4, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff4, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec4, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(1.0f, 3.0f, 6, 12); //CarBiggerCube objId = 5; float amb5[] = { 0.025f, 0.025f, 0.1f, 1.0f }; float diff5[] = { 0.1f, 0.1f, 0.4f, 1.0f }; float spec5[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb5, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff5, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec5, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); //CarSmallerCube objId = 6; float amb6[] = { 0.0f, 0.2f, 0.0f, 1.0f }; float diff6[] = { 0.0f, 0.8f, 0.0f, 1.0f }; float spec6[] = { 0.9f, 0.9f, 0.9f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb6, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff6, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec6, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createCube(); car.addMesh(&mesh[4]); car.addMesh(&mesh[5]); car.addMesh(&mesh[6]); for (Car* life : _lives) { life->addMesh(&mesh[4]); life->addMesh(&mesh[5]); life->addMesh(&mesh[6]); } butter1.addMesh(&mesh[5]); butter2.addMesh(&mesh[5]); butter1ref.addMesh(&mesh[5]); butter2ref.addMesh(&mesh[5]); butter1ref.reflect(); butter2ref.reflect(); table.addMesh(&mesh[0]); pauseScreen.addMesh(&mesh[0]); pauseScreen.addTexture(textureArray[2]); pauseScreen.addTexture(textureArray[2]); deathScreen.addMesh(&mesh[0]); deathScreen.addTexture(textureArray[3]); deathScreen.addTexture(textureArray[3]); HUDbg.addMesh(&mesh[2]); road.addMesh(&mesh[1]); road.addMesh(&mesh[2]); road.addTexture(textureArray[0]); road.addTexture(textureArray[1]); for (int i = 0; i < 128; i++) { cheerioArray[i].addMesh(&mesh[3]); } //Orange objId = 7; float amb7[] = { 0.2f, 0.1f, 0.025f, 1.0f }; float diff7[] = { 0.8f, 0.4f, 0.1f, 1.0f }; float spec7[] = { 0.0f, 0.0f, 0.0f, 1.0f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb7, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff7, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec7, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createSphere(1.0, 9); for (int i = 0; i < orangeArray.size(); i++) { orangeArray[i].addMesh(&mesh[7]); } //Quad objId = 8; float amb8[] = { 0.1f, 0.1f, 0.1f, 1.0f }; float diff8[] = { 0.6f, 0.6f, 0.6f, 1.0f }; memcpy(mesh[objId].mat.ambient, amb8, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff8, 4 * sizeof(float)); createCube(); for (int i = 0; i < 4; i++) { broccoli[i].addMesh(&mesh[8]); broccoli[i].addTexture(textureArray[4]); } //Cup objId = 9; float amb9[] = { 0.1f, 0.1f, 0.7f, 0.3f }; float diff9[] = { 0.1f, 0.1f, 0.4f, 0.1f }; float spec9[] = { 0.9f, 0.9f, 0.9f, 0.3f }; shininess = 500.0; memcpy(mesh[objId].mat.ambient, amb9, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff9, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec9, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createTorus(0.9f, 1.0f, 32, 12); objId = 10; memcpy(mesh[objId].mat.ambient, amb9, 4 * sizeof(float)); memcpy(mesh[objId].mat.diffuse, diff9, 4 * sizeof(float)); memcpy(mesh[objId].mat.specular, spec9, 4 * sizeof(float)); memcpy(mesh[objId].mat.emissive, emissive, 4 * sizeof(float)); mesh[objId].mat.shininess = shininess; mesh[objId].mat.texCount = texcount; createSphere(1.0, 9); cup.addMesh(&mesh[9]); cup.addMesh(&mesh[10]); //SUN objId = 11; float amb11[] = { 1.0f, 1.0f, 1.0f, 1.0f }; memcpy(mesh[objId].mat.ambient, amb11, 4 * sizeof(float)); createCube(); sun.addMesh(&mesh[11]); sun.addTexture(textureArray[10]); sun.addTexture(textureArray[10]); // some GL settings glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_MULTISAMPLE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.5f, 0.5f, 0.5f, 1.0f); //lights _directional_light.setPosition(0.0f, 1.0f, 0.0f, 0.0f); //4th parameter == 0 => directional light _directional_light.setEnabled(true); LightSource *l1 = new LightSource(); l1->setPosition(2.5f, 1.0f, 2.5f, 1.0f); l1->setEnabled(true); l1->setLocal(true); _lamps.push_back(l1); LightSource *l2 = new LightSource(); l2->setPosition(2.5f, 1.0f, -2.5f, 1.0f); l2->setEnabled(true); l2->setLocal(true); _lamps.push_back(l2); LightSource *l3 = new LightSource(); l3->setPosition(0.0f, 1.0f, 2.5f, 1.0f); l3->setEnabled(true); l3->setLocal(true); _lamps.push_back(l3); LightSource *l4 = new LightSource(); l4->setPosition(0.0f, 1.0f, -2.5f, 1.0f); l4->setEnabled(true); l4->setLocal(true); _lamps.push_back(l4); LightSource *l5 = new LightSource(); l5->setPosition(-2.5f, 1.0f, 2.5f, 1.0f); l5->setEnabled(true); l5->setLocal(true); _lamps.push_back(l5); LightSource *l6 = new LightSource(); l6->setPosition(-2.5f, 1.0f, -2.5f, 1.0f); l6->setEnabled(true); l6->setLocal(true); _lamps.push_back(l6); LightSource *spot1 = new LightSource(); spot1->setEnabled(true); spot1->setLocal(true); spot1->setSpot(true); float cutOff = 2.0f; spot1->setCutOff(cutOff); spot1->setExponent(0.2f); _spotLights.push_back(spot1); LightSource *spot2 = new LightSource(); spot2->setEnabled(true); spot2->setLocal(true); spot2->setSpot(true); cutOff = 2.0f; spot2->setCutOff(cutOff); spot2->setExponent(0.2f); _spotLights.push_back(spot2); // create cameras PerspectiveCamera* p1 = new PerspectiveCamera(53.13f, 0.1f, 1000.0f); _cameras.push_back(p1); OrtogonalCamera* ortho = new OrtogonalCamera(-5, 5, -5, 5, -100, 100); _cameras.push_back(ortho); PerspectiveCamera* p2 = new PerspectiveCamera(53.13f, 0.1f, 1000.0f); _cameras.push_back(p2); _hudCamera = new OrtogonalCamera(-5, 5, -5, 5, -100, 100); // create geometry and VAO of the quad for particles objId = 11; mesh[objId].mat.texCount = texcount; createQuad(2, 2); //particles.init(); }
/** * @brief ParticleSystem activate method */ bool ParticleSystem::Activate(void) { // -------------------------------------------------- // Get the path name of the plugin folder, e.g. // "/path/to/oglcore/Plugins/PCVC/ParticleSystem" // -------------------------------------------------- std::string pathName = this->GetCurrentPluginPath(); // -------------------------------------------------- // Initialize manipulator for camera view // -------------------------------------------------- int camHandle = this->AddManipulator("View", &this->viewMX, Manipulator::MANIPULATOR_ORBIT_VIEW_3D); this->SelectCurrentManipulator(camHandle); this->SetManipulatorRotation(camHandle, glm::vec3(0, 1, 0), 180.0f); this->SetManipulatorRotation(camHandle, glm::vec3(1, 0, 0), 180.0f); this->SetManipulatorDolly(camHandle, -1.5f); modelMX = glm::scale(glm::translate(glm::mat4(), glm::vec3(0.0f, -0.25f, 0.0f)), glm::vec3(0.5f, 0.5f, 0.5f)); // -------------------------------------------------- // Initialize API variables here // -------------------------------------------------- fovY.Set(this, "FoVy"); fovY.Register(); fovY.SetMinMax(5.0f, 90.0f); fovY = 45.0f; simulationSpeed.Set(this, "simulationSpeed"); simulationSpeed.Register("step=0.01 min=0.01 max=1.0"); simulationSpeed = 0.2f; num_points.Set(this, "numOfPoints", &OnnumPointsChanged); num_points.Register("step=1000 min=1 max=500000"); num_points = 100000; num_instances.Set(this, "num_instances"); num_instances.Register("step=1 min=1 max=3"); num_instances = 1; pointSize.Set(this, "pointSize"); pointSize.Register("step=0.1 min=0.1 max=10.0"); pointSize = 0.1f; scale.Set(this, "scale"); scale.Register("step=0.01 min=0.0 max=2.0"); scale = 0.5f; velocity.Set(this, "velocity", &OnColorChanged); velocity.Register(); velocity = glm::vec3(0.01f, 0.01f, 0.01f); targetSpeed = velocity; showBox.Set(this, "showBox"); showBox.Register(); showBox = true; stopMotion.Set(this, "stopMotion"); stopMotion.Register(); stopMotion = false; EnumPair ep[] = {{0, "None"},{1, "cube"}, {2, "sphere"}, {3, "torus"}, {4, "ef"}, {5, "ef5"}}; importObject.Set(this, "importObject", ep, 6, &onObjectChanged); importObject.Register(); // -------------------------------------------------- // Initialize shaders and VAs // -------------------------------------------------- vsQuad = pathName + std::string("/resources/quad.vert"); fsQuad = pathName + std::string("/resources/quad.frag"); shaderQuad.CreateProgramFromFile(vsQuad.c_str(), fsQuad.c_str()); vaQuad.Create(4); vaQuad.SetArrayBuffer(0, GL_FLOAT, 2, ogl4_2dQuadVerts); vsBox = pathName + std::string("/resources/box.vert"); fsBox = pathName + std::string("/resources/box.frag"); shaderBox.CreateProgramFromFile(vsBox.c_str(), fsBox.c_str()); vsCube = pathName + std::string("/resources/cube.vert"); gsCube = pathName + std::string("/resources/cube.geom"); fsCube = pathName + std::string("/resources/cube.frag"); shaderCube.CreateProgramFromFile( vsCube.c_str(), gsCube.c_str(), fsCube.c_str() ); createCube(); vsObject = pathName + std::string("/resources/object.vert"); gsObject = pathName + std::string("/resources/object.geom"); fsObject = pathName + std::string("/resources/object.frag"); shaderObject.CreateProgramFromFile( vsObject.c_str(), fsObject.c_str() );//gsObject.c_str(), createTransformProgram(pathName); createBox(); createSphere(); createTorus(); createCube(); createEF(pathName, true); createEF(pathName, false); if(!checkProgram(pathName, "/resources/ctrlPoints.vert", "/resources/ctrlPoints.frag")){//, "/resources/ctrlPoints.geom" std::cout.flush(); std::cout << "******** shader error ********" <<std::endl; exit(0); } createCtrlPoints(); vsCtrlPoints = pathName + std::string("/resources/ctrlPoints.vert"); fsCtrlPoints = pathName + std::string("/resources/ctrlPoints.frag"); shaderCtrlPoints.CreateProgramFromFile(vsCtrlPoints.c_str(),//gsCtrlPoints.c_str(), fsCtrlPoints.c_str()); // -------------------------------------------------- // fbo and textures // -------------------------------------------------- initFBO(); // -------------------------------------------------- // random textures // -------------------------------------------------- srand (time(NULL)); for(int i = 0; i < random_tex_size; i++) { for(int j = 0; j < random_tex_size; j++) { texdata[4 * (i * random_tex_size + j) + 0] = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX));// - 0.5f; texdata[4 * (i * random_tex_size + j) + 1] = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX));// - 0.5f; texdata[4 * (i * random_tex_size + j) + 2] = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX));// - 0.5f; texdata[4 * (i * random_tex_size + j) + 3] = 1.0f; } } glGenTextures(1, &randomTex); glBindTexture(GL_TEXTURE_2D, randomTex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, random_tex_size, random_tex_size, 0, GL_RGBA, GL_FLOAT, texdata); int tex_cube_width = 800; int tex_cube_height = 400; char *texpathBoard = (pathName + std::string("/resources/textures/board.ppm")).c_str(); texBoard = LoadPPMTexture(texpathBoard, tex_cube_width, tex_cube_height); //target point targetPoint= glm::vec3(static_cast <float> (rand()) / static_cast <float> (RAND_MAX), static_cast <float> (rand()) / static_cast <float> (RAND_MAX), static_cast <float> (rand()) / static_cast <float> (RAND_MAX)); direction = glm::vec3(1.0f,1.0f,1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); return true; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Main Scene Node NodeRecPtr Scene = makeCoredNode<Group>(); NodeRecPtr TorusNode = createTorus(); NodeRecPtr SphereNode = createSphere(); NodeRecPtr ConeNode = createCone(); NodeRecPtr BoxNode = createBox(); Scene->addChild(TorusNode); Scene->addChild(SphereNode); Scene->addChild(ConeNode); Scene->addChild(BoxNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a Background ******************************************************/ ColorLayerRecPtr GreyBackground = ColorLayer::create(); GreyBackground->setColor(Color4f(.93,.93,.93,1.0)); /****************************************************** Create some Borders ******************************************************/ LineBorderRecPtr PanelBorder = LineBorder::create(); EmptyBorderRecPtr Panel1Border = EmptyBorder::create(); EmptyBorderRecPtr Panel2Border = EmptyBorder::create(); EmptyBorderRecPtr emptyBorder = EmptyBorder::create(); PanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder->setWidth(1); Panel1Border->setTopWidth(0); Panel1Border->setBottomWidth(6); Panel1Border->setLeftWidth(0); Panel1Border->setRightWidth(0); Panel2Border->setTopWidth(0); Panel2Border->setBottomWidth(0); Panel2Border->setLeftWidth(0); Panel2Border->setRightWidth(0); /****************************************************** Create some Labels and stuff to go with them ******************************************************/ LabelRecPtr LeftPanelLabel1 = Label::create(); UIFontRecPtr LeftPanelLabel1Font = UIFont::create(); LeftPanelLabel1Font->setSize(50); LeftPanelLabel1->setBorders(emptyBorder); LeftPanelLabel1->setBackgrounds(GreyBackground); LeftPanelLabel1->setFont(LeftPanelLabel1Font); LeftPanelLabel1->setText("OSG Gui"); LeftPanelLabel1->setPreferredSize(Vec2f(300, 100)); LeftPanelLabel1->setAlignment(Vec2f(0.0f, 0.5f)); /****************************************************** Create some Layouts ******************************************************/ BoxLayoutRecPtr MainInternalWindowLayout = BoxLayout::create(); FlowLayoutRecPtr LeftPanelLayout = FlowLayout::create(); BoxLayoutRecPtr RightPanelLayout = BoxLayout::create(); MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setMinorAxisAlignment(1.0f); RightPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); /****************************************************** Create MainFrame and Panels ******************************************************/ PanelRecPtr LeftPanel = Panel::createEmpty(); PanelRecPtr RightPanel = Panel::createEmpty(); // LeftPanel stuff LeftPanel->setPreferredSize(Vec2f(400, 500)); LeftPanel->pushToChildren(LeftPanelLabel1); PanelRecPtr LeftPanelButtonPanel = createLeftPanelButtonPanel(); LeftPanel->pushToChildren(LeftPanelButtonPanel); PanelRecPtr LeftPanelRadioTextPanel = createLeftPanelRadioTextPanel(); LeftPanel->pushToChildren(LeftPanelRadioTextPanel); LeftPanel->setLayout(LeftPanelLayout); LeftPanel->setBackgrounds(GreyBackground); LeftPanel->setBorders(Panel1Border); //RightPanel stuff RightPanel->setPreferredSize(Vec2f(200, 620)); PanelRecPtr RightPanelButtonPanel = createRightPanelButtonPanel(); RightPanel->pushToChildren(RightPanelButtonPanel); PanelRecPtr RightPanelCheckPanel = createRightPanelCheckPanel(TorusNode, SphereNode, ConeNode, BoxNode); RightPanel->pushToChildren(RightPanelCheckPanel); RightPanel->setLayout(RightPanelLayout); RightPanel->setBackgrounds(GreyBackground); RightPanel->setBorders(Panel2Border); // Create The Main InternalWindow InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(LeftPanel); MainInternalWindow->pushToChildren(RightPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(GreyBackground); MainInternalWindow->setBorders(PanelBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); //MainInternalWindow->setOpacity(0.7f); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Make A 3D Rectangle to draw the UI on UIRectangleRecPtr UIRectCore = UIRectangle::create(); UIRectCore->setPoint(Pnt3f(-310.0,-310.0,370.0)); UIRectCore->setWidth(620); UIRectCore->setHeight(620); UIRectCore->setDrawingSurface(TutorialDrawingSurface); NodeRecPtr UIRectNode = Node::create(); UIRectNode->setCore(UIRectCore); // add the UIRect as a child Scene->addChild(UIRectNode); sceneManager.setRoot(Scene); // Show the whole Scene sceneManager.showAll(); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "21ExampleInterface"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }