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();
    }
Ejemplo n.º 2
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();
    }