void onDraw(int nTime)
    {
      glBindFramebuffer(GL_FRAMEBUFFER, 0);
    
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      math::mat4 mM;
      math::mat4 mV;
      math::mat4 mP;
      
      mM = pObject1->getM();
      mV = pCamera->getViewMatrix();
      mP = pCamera->getProjectionMatrix();
      
      pProgramRender->enable();    // ::enable() ::disable()
      pProgramRender->setUniform("u_mM",  mM);
      pProgramRender->setUniform("u_mMV", mV * mM);
      pProgramRender->setUniform("u_mP",  mP);
      pProgramRender->setUniform("u_oDirectLight.vColor",            pDirectLight->mColor);
      pProgramRender->setUniform("u_oDirectLight.vDirection",        math::normalize(pDirectLight->mDirection)); // left to rigth
      pProgramRender->setUniform("u_oDirectLight.fAmbientIntensity", pDirectLight->mAmbientIntensity);
      pProgramRender->setUniform("u_oDirectLight.fDiffuseIntensity", pDirectLight->mDiffuseIntensity);
      pProgramRender->setUniform("u_fSpecularIntensity",             0.0f);
      pProgramRender->setUniform("u_fSpecularPower",                 0.0f);
      pProgramRender->setUniform("u_fEyePosition",                   pCamera->getPosition());
      // pObjectP->draw(); // DEPRICATED
      
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      pProgramBillboard->enable();
      pProgramBillboard->setUniform("u_mVP", pCamera->getProjectionMatrix() * pCamera->getViewMatrix());
      pProgramBillboard->setUniform("u_vCameraPosition", pCamera->getPosition());
      // pObjectB->draw(); // DEPRICATED
      
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      GLint prevCullFace;
      glGetIntegerv(GL_CULL_FACE_MODE, &prevCullFace);
      GLint prevDepthFunc;
      glGetIntegerv(GL_DEPTH_FUNC, &prevDepthFunc);
      
      glCullFace(GL_FRONT);
      glDepthFunc(GL_LEQUAL);
      
      pProgramSkybox->enable();
      mM = math::translate(pCamera->getPosition()) * pObjectS->getM();
      mV = pCamera->getViewMatrix();
      mP = pCamera->getProjectionMatrix();
      pProgramSkybox->setUniform("u_mMVP", mP * mV * mM);
      // pObjectS->draw(); // DEPRICATED
      
      glCullFace(prevCullFace);
      glDepthFunc(prevDepthFunc);

      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      
      //CApp::exit();
    }
 void init_objects()
 {
   { // plane
     ogl::CPlaneObjectBuilder* pObjectBuilder = new ogl::CPlaneObjectBuilder;
     pObjectBuilder->setWidth(10.0f);
     pObjectBuilder->setHeight(10.0f);
     pObjectBuilder->setSubdivisions(10);
     //pObjectBuilder->addOption(ogl::CPlaneObjectBuilder::REPEAT_UV);
     pObjectBuilder->addOption(ogl::CPlaneObjectBuilder::TANGENTS);
     //pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
     pObjectP = pObjectBuilder->build();
     
     ogl::CDdsTextureBuilder* pTextureBuilder = new ogl::CDdsTextureBuilder;
     pTextureBuilder->setFile("ground/rocks_d.dds");
     pObjectP->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::DIFFUSE, pTextureBuilder->build());
     pTextureBuilder->setFile("ground/rocks_h.dds");
     pObjectP->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::HEIGHT, pTextureBuilder->build()); // displacement
     
     delete pObjectBuilder;
   }
   {
     ogl::CAssimpObjectBuilder* pObjectBuilder = new ogl::CAssimpObjectBuilder;
     pObjectBuilder->setFile("monkey/monkey.obj");
     pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
     pObject0 = pObjectBuilder->build();
     pObject0->setM(math::translate(0.0f, 2.0f, 0.0f) * math::rotate(-90.0f, math::X));
     delete pObjectBuilder;
   }
 }
    void init_objects()
    {
      { // plane
        ogl::CPlaneObjectBuilder* pObjectBuilder = new ogl::CPlaneObjectBuilder;
        pObjectBuilder->setWidth(20.0f);
        pObjectBuilder->setHeight(20.0f);
        pObjectBuilder->setSubdivisions(1);
        // pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
        pObjectP = pObjectBuilder->build();
        delete pObjectBuilder;
      }
      { // box from box-builder
//        ogl::CBoxObjectBuilder* pObjectBuilder = new ogl::CBoxObjectBuilder;
//        pObjectBuilder->setWidth(1.0f);
//        pObjectBuilder->setHeight(1.0f);
//        pObjectBuilder->setDepth(1.0f);
//        pObject = pObjectBuilder->build();
//        pObject->setM(math::translate(0.0f, -1.0f, 5.0f) * math::scale(10.0f));
//        delete pObjectBuilder;
      }
      { // random mesh
        ogl::CAssimpObjectBuilder* pObjectBuilder = new ogl::CAssimpObjectBuilder;
        pObjectBuilder->setFile("box/box.obj");
        pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
        pObject1 = pObjectBuilder->build();
        pObject1->setM(math::translate(0.0f, 0.0f, 2.0f));
        delete pObjectBuilder;
      }
      { // skybox
        ogl::CAssimpObjectBuilder* pObjectBuilder = new ogl::CAssimpObjectBuilder;
        pObjectBuilder->setFile("skybox/skydome.obj");
        pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
        pObjectS = pObjectBuilder->build();
        pObjectS->setM(math::scale(20.0f));
        delete pObjectBuilder;
      }
      { // billboarding
        ogl::CPlaneObjectBuilder* pObjectBuilder = new ogl::CPlaneObjectBuilder;
        pObjectBuilder->setWidth(18.0f);
        pObjectBuilder->setHeight(18.0f);
        pObjectBuilder->setSubdivisions(6);
        // pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
        pObjectB = pObjectBuilder->build();
        delete pObjectBuilder;
        
        ogl::CPngTextureBuilder* pTextureBuilder = new ogl::CPngTextureBuilder;
        pTextureBuilder->setFile("monster.png");
        ogl::CTexture* pTexture = pTextureBuilder->build();
        pTexture->setWrapping(ogl::CTexture::EWrapping::CLAMP_TO_BORDER);
        delete pTextureBuilder;
        
        ogl::CMaterial* pMaterial = new ogl::CMaterial;
        pMaterial->setTexture(ogl::CTexture::EScope::DIFFUSE, pTexture);
        
        pObjectB->setMode(GL_POINTS);
        pObjectB->getShape(0)->setMaterial(pMaterial);
      }
    }
예제 #4
0
 void load_objects()
 {
   ogl::CBoxObjectBuilder* pObjectBuilder = new ogl::CBoxObjectBuilder;
   pObjectBuilder->setWidth(1.0f);
   pObjectBuilder->setHeight(1.0f);
   pObjectBuilder->setDepth(1.0f);
   pObject = pObjectBuilder->build();
   pObject->setM(math::rotate(45.0f, math::Z) * math::translate(0.0f, 0.0f, 4.0f));
   delete pObjectBuilder;
 }
예제 #5
0
    void onDraw(int nTime)
    {
      const float fTime = nTime / 1000.0f;
      sys::info << "app::COGLDev02App::onDraw(" << nTime << ") > " << fTime << sys::endl;
      
      static const GLfloat gray[]  = { 0.1f, 0.1f, 0.1f, 0.0f };
      static const GLfloat ones[]  = { 1.0f };
      glClearBufferfv(GL_COLOR, 0, gray);
      glClearBufferfv(GL_DEPTH, 0, ones);
      
      math::mat4 mM = pObject->getM() *
                      math::rotate(fTime * 13.25f, math::Y);
      math::mat4 mV = pCamera->getViewMatrix();
      math::mat4 mP = pCamera->getProjectionMatrix();
//      math::mat4 mV = math::lookat(math::vec3(0.0f, 1.0f, 0.0f), math::vec3(0.0f, 0.8f, 0.5f), math::Y);
//      math::mat4 mP = math::perspective(60.0f, mConfig.mRatio, 0.1f, 100.0f);
      
      //math::mat4 mMV = math::translate(0.0f, 0.0f, -5.0f) *
      //                 math::rotate(fTime * 13.75f, math::Y);
      
      glViewport(0, 0, mConfig.mWidth, mConfig.mHeight);
      
      pProgram->use();
      pProgram->setUniform("u_fTime", fTime);
      //pProgram->setUniform("u_mM", mM);
      //pProgram->setUniform("u_mMV", mMV);
      pProgram->setUniform("u_mMV", mV * mM);
      pProgram->setUniform("u_mP",  mP);
      pProgram->setUniform("u_bWireframe",  false);
      pProgram->setUniform("u_oDirectLight.vColor",     oDirectionalLight.vColor);
      pProgram->setUniform("u_oDirectLight.vDirection", math::normalize(oDirectionalLight.vDirection));
      pProgram->setUniform("u_oDirectLight.fAmbientIntensity", oDirectionalLight.fAmbientIntensity);
      pProgram->setUniform("u_vEyePos",            pCamera->getPosition());
      pProgram->setUniform("u_fSpecularIntensity", 1.0f);
      pProgram->setUniform("u_fSpecularPower",     64.0f);
      
      pTexture->bind(GL_TEXTURE0);
      
      glEnable(GL_POLYGON_OFFSET_FILL);
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      // pObject->draw(); // DEPRICATED
      
//      pProgram->setUniform("u_bWireframe",  true);
      
      pTexture->unbind();
      
//      glEnable(GL_POLYGON_OFFSET_LINE);
//      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//      glLineWidth(1.0f);
//      pObject->draw();
//      glDisable(GL_POLYGON_OFFSET_LINE);
      
      pProgram->unuse();
    }  
    void init_objects()
    {
        {
            ogl::CPlaneObjectBuilder* pObjectBuilder = new ogl::CPlaneObjectBuilder;
            pObjectBuilder->setWidth(10.0f);
            pObjectBuilder->setHeight(10.0f);
            pObjectBuilder->setSubdivisions(1);
            // pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
            pObjectQ = pObjectBuilder->build();
            delete pObjectBuilder;
        }
        {
//        ogl::CBoxObjectBuilder* pObjectBuilder = new ogl::CBoxObjectBuilder;
//        pObjectBuilder->setWidth(1.0f);
//        pObjectBuilder->setHeight(1.0f);
//        pObjectBuilder->setDepth(1.0f);
//        pObject = pObjectBuilder->build();
//        pObject->setM(math::translate(0.0f, -1.0f, 5.0f) * math::scale(10.0f));
//        delete pObjectBuilder;
        }
        {
            ogl::CAssimpObjectBuilder* pObjectBuilder = new ogl::CAssimpObjectBuilder;
            pObjectBuilder->setFile("box/box.obj");
            pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
            pObject1 = pObjectBuilder->build();
            pObject1->setM(math::translate(0.0f, 0.0f, 2.0f));
            delete pObjectBuilder;
        }

        {
            ogl::CAssimpObjectBuilder* pObjectBuilder = new ogl::CAssimpObjectBuilder;
            pObjectBuilder->setFile("skybox/skydome.obj");
            pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
            pObjectS = pObjectBuilder->build();
            pObjectS->setM(math::scale(20.0f));
            delete pObjectBuilder;
        }
    }
    void init_objects()
    {
      sys::info << "app::COGLDev42PCFShadowMapApp::init_objects()" << sys::endl;
      { // plane
        ogl::CPlaneObjectBuilder* pObjectBuilder = new ogl::CPlaneObjectBuilder;
        pObjectBuilder->setWidth(25.0f);
        pObjectBuilder->setHeight(25.0f);
        pObjectBuilder->setSubdivisions(10);
        pObjectBuilder->setTextureScale(0.5f);
        pObjectBuilder->addOption(ogl::CPlaneObjectBuilder::REPEAT_UV);
        pObjectBuilder->addOption(ogl::CObjectBuilder::TANGENTS);
        // pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
        pObjectP = pObjectBuilder->build();
        
        ogl::CTgaTextureBuilder* pTgaTextureBuilder = new ogl::CTgaTextureBuilder;
        ogl::CDdsTextureBuilder* pDdsTextureBuilder = new ogl::CDdsTextureBuilder;
        pTgaTextureBuilder->setFile("ground/concrete_d.tga");
        pObjectP->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::DIFFUSE, pTgaTextureBuilder->build());
        pTgaTextureBuilder->setFile("ground/concrete_n.tga");
        pObjectP->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::NORMALS, pTgaTextureBuilder->build()); // normals
        pDdsTextureBuilder->setFile("skybox/planet.dds");
        pObjectP->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::ENVIRONMENT, pDdsTextureBuilder->build());
        
        // pObjectP->translate(math::vec3(0.0f, -3.0f, 0.0f));
        
        // TODO: move this inside CObject or in a CObjectBuilder
        ogl::CTransformHistory::getInstance()->set(pObjectP, ogl::CTransform(pObjectP->mScale, pObjectP->mOrientation, pObjectP->mPosition));
        
        glExitIfError();
        
        delete pTgaTextureBuilder;
        delete pDdsTextureBuilder;
        delete pObjectBuilder;
      }
      { // box
        ogl::CBoxObjectBuilder* pObjectBuilder = new ogl::CBoxObjectBuilder;
        pObjectBuilder->setWidth(10.0f);
        pObjectBuilder->setHeight(10.0f);
        pObjectBuilder->setDepth(10.0f);
        pObjectBuilder->addOption(ogl::CObjectBuilder::INVERTED);
        pObjectBuilder->setTextureScale(0.5f);
        //pObjectBuilder->addOption(ogl::CObjectBuilder::FLATFACE);
        
        pObjectB = pObjectBuilder->build();
        
        ogl::CTgaTextureBuilder* pTgaTextureBuilder = new ogl::CTgaTextureBuilder;
        ogl::CDdsTextureBuilder* pDdsTextureBuilder = new ogl::CDdsTextureBuilder;
        pTgaTextureBuilder->setFile("tiles/pavers_d.tga");
        pObjectB->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::DIFFUSE, pTgaTextureBuilder->build());
        pTgaTextureBuilder->setFile("tiles/pavers_n.tga");
        pObjectB->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::NORMALS, pTgaTextureBuilder->build()); // normals
        pDdsTextureBuilder->setFile("skybox/skydome.dds");
        pObjectB->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::ENVIRONMENT, pDdsTextureBuilder->build());
        
        pObjectB->translate(math::vec3(0.0f, 5.0f, 0.0f));
        
        glExitIfError();

        delete pTgaTextureBuilder;
        delete pDdsTextureBuilder;
        delete pObjectBuilder;
      }
      { // boblampclean
        ogl::CMd5ObjectBuilder* pObjectBuilder = new ogl::CMd5ObjectBuilder;
        pObjectBuilder->setFile("boblampclean/boblampclean.md5mesh");
        pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
        //pObjectBuilder->addOption(ogl::CObjectBuilder::ADJACENCY); // TODO: unfuck up the MD5 parser
        pObject0 = pObjectBuilder->build();
        
        ogl::CTgaTextureBuilder* pTextureBuilder = new ogl::CTgaTextureBuilder;
        pTextureBuilder->setFile("boblampclean/guard1_body_n.tga");
        // sys::info << sys::tab << "set normal to shape: " << pObject0->getShape(0)->getName() << sys::endl;
        pObject0->getShape(0)->getMaterial()->setTexture(ogl::CTexture::EScope::NORMALS, pTextureBuilder->build());
        
        // TODO: need better normalization
        pObject0->scale(2.0f);
        pObject0->rotate(math::quat(-90.0f, math::X) * math::quat(180.0f, math::Z));
        
        // Remember previous transformation
        ogl::CTransformHistory::getInstance()->set(pObject0, ogl::CTransform(pObject0->mScale, pObject0->mOrientation, pObject0->mPosition));
        
        glExitIfError();
        
        delete pObjectBuilder;
        delete pTextureBuilder;
      }
      { // another box
        ogl::CMd5ObjectBuilder* pObjectBuilder = new ogl::CMd5ObjectBuilder;
        pObjectBuilder->setFile("cube.md5mesh");
        pObjectBuilder->addOption(ogl::CObjectBuilder::NORMALIZED);
        pObject1 = pObjectBuilder->build();
        
        pObject1->scale(0.5f);
        pObject1->translate(math::vec3(4.0f, 5.0f, 1.0f));
        
        ogl::CTransformHistory::getInstance()->set(pObject1, ogl::CTransform(pObject1->mScale, pObject1->mOrientation, pObject1->mPosition));
        
        delete pObjectBuilder;
      }
    }