void ForwardRenderTechnique::render() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); if(!m_scene) { return; } glUseProgram(m_shader->getProgramId()); const auto &renderMap = m_scene->getRenderMap(); const auto &lightList = m_scene->getLightList(); int i = 0; for(const auto &l : lightList) { m_shader->setLight(i++, l); } m_shader->setNumLights(lightList.size()); for(auto it : renderMap) { if(it.first) { if(!setupMaterial(m_shader, it.first)) { m_logManager->logErr("Failed to setup material"); continue; } } for(auto o : it.second) { m_shader->setMVP(m_viewCamera->getVP()*o->getWorldMat()); if(!setupMesh(m_shader, o->getMesh())) { m_logManager->logErr("Failed to setup mesh"); continue; } drawCall(o->getMesh()->getNumVerts()); } } }
RenderableBound::RenderableBound() : Renderable() { mMesh = NULL; mSubMesh = NULL; mMaterial = NULL; mMaterial = NULL; setupMaterial(kDefaultBoundMaterial); }
GLRenderer::GLRenderer(void) { GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set the clear Display state to the black color; the windows will use this setting during the whole execution program = std::unique_ptr<GLProgram>(new GLProgram()); program->run(); program->transformObjIndex = glGetUniformLocation(program->getID(),"gObjectTransform"); program->transformCamIndex = glGetUniformLocation(program->getID(),"gCamera"); program->lightColorIndex = glGetUniformLocation(program->getID(), "light.lightColor"); program->ambientIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityAmbient"); program->diffuseIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityDiffuse"); program->directionIndex = glGetUniformLocation(program->getID(), "light.direction"); program->eyeIndex = glGetUniformLocation(program->getID(), "eyeWorldSpace"); program->specularIntensityIndex = glGetUniformLocation(program->getID(), "specularIntensity"); program->specularPowerIndex = glGetUniformLocation(program->getID(), "specularPower"); _root = std::unique_ptr<Node>(new Node); /* Setup the scene */ RawSceneLoader loader; Scene scene; loader.load(scene); setupMesh(scene.meshes[0],1); setupTexture(scene.textures[0],1); setupLight(scene.lights[0], 1); setupMaterial(scene.materials[0],1); }
void Disk::setHash(Hash* hash) { center.set(hash->getValue("center")->getArray()); normal.set(hash->getValue("normal")->getArray()); normal.normalize(); radius = hash->getDouble("radius"); radiusSquared = radius * radius; inverseArea = 1.0 / M_PI * radiusSquared; a = Vector3D(0, 0, 1).cross(normal); b = normal.cross(a); setupMaterial(hash->getValue("material")->getHash()); }
//=========================================================== void CSegRemanenceShape::render(IDriver *drv, CTransformShape *trans, bool opaquePass) { if ((!opaquePass && _Mat.getBlend()) || (opaquePass && !_Mat.getBlend()) ) { CSegRemanence *sr = NLMISC::safe_cast<CSegRemanence *>(trans); #ifndef DEBUG_SEG_REMANENCE_DISPLAY if (!sr->isStarted()) return; #endif setupMaterial(); // sr->render(drv, _Mat); } }
void ofApp::setup(){ setupLight(); setupMaterial(); // scene.addLight(light); scene.setLight(light); scene.setMaterial(material); extSphere.setup(); cam.orbit(0, -10, 300); ofVec3f p = cam.getPosition(); cam.setPosition(p.x, p.y + 20.0, p.z); // cam.setupPerspective(true, 60, 1, 2000); gui.setup(scene.parameters); }
void cPlane::render() const { glPushMatrix(); Eigen::Vector3f mPos = -mNormal * mD; Eigen::Vector3f eX, eY; if (mD > 1e-6f) { Eigen::Vector3f v(10, 10, 10); int i = -1; float m = 0; if (fabs(mNormal.x()) > 1e-6f) i = 0; else if (fabs(mNormal.y()) > 1e-6f) i = 1; else if (fabs(mNormal.z()) > 1e-6f) i = 2; m = mNormal(i), v(i) = 0; m = (mD + v.dot(mNormal)) / m; v(i) = m; eX = v; } else { eX = Eigen::Vector3f(0, 0, 1); } eX = (eX + mPos).normalized(); eY = mNormal.cross(eX).normalized(); float W = 50; float H = 50; glTranslatef((GLfloat)mPos.x(), (GLfloat)mPos.y(), (GLfloat)mPos.z()); setupMaterial(); //glutSolidSphere(0.01, 20, 20); glBegin(GL_QUADS); glVertex3fv(Eigen::Vector3f(-W * eX - H * eY).data()); glVertex3fv(Eigen::Vector3f(-W * eX + H * eY).data()); glVertex3fv(Eigen::Vector3f(W * eX + H * eY).data()); glVertex3fv(Eigen::Vector3f(W * eX - H * eY).data()); glEnd(); glPopMatrix(); }
void Mesh::setHash(Hash* hash) { if(hash->contains("material")) { setupMaterial(hash->getValue("material")->getHash()); } if(hash->contains("verticies")) { Array* verts = hash->getValue("verticies")->getArray(); for(unsigned int i = 0; i < verts->size(); i++) { Array* vert = verts->at(i)->getArray(); addPoint(new Point3D(vert->at(0)->getDouble(), vert->at(1)->getDouble(), vert->at(2)->getDouble())); } } if(hash->contains("faces")) { Array* faces = hash->getValue("faces")->getArray(); for(unsigned int i = 0; i < faces->size(); i++) { Array* f = faces->at(i)->getArray(); addFace(f->at(0)->getInteger(), f->at(1)->getInteger(), f->at(2)->getInteger()); } calculateNormals(); } }
void ParticleSystemEngine::exec( const Tempest::Matrix4x4 &mview, const Tempest::Matrix4x4 &mproj, int dt, bool invCullMode ) { view.clear(); Tempest::Matrix4x4 mvp = mproj; Tempest::Matrix4x4 vmat = mview; mvp.mul( vmat ); double ileft[3] = { vmat.data()[0], vmat.data()[4], vmat.data()[8] }; double itop[3] = { vmat.data()[1], vmat.data()[5], vmat.data()[9] }; double inorm[3] = { vmat.data()[2], vmat.data()[6], vmat.data()[10] }; std::copy( ileft, ileft+3, left ); std::copy( itop, itop +3, top ); std::copy( inorm, inorm+3, norm ); float ll = left[0]*left[0]+left[1]*left[1]+left[2]*left[2]; float lt = top[0]* top[0]+ top[1]* top[1]+ top[2]* top[2]; float ln = norm[0]*norm[0]+norm[1]*norm[1]+norm[2]*norm[2]; ll = 0.5*sqrt(ll); lt = 0.5*sqrt(lt); ln = sqrt(ln); if( invCullMode ){ ll = -ll; ln *= -0.5; } for( int i=0; i<3; ++i ){ left[i] /= ll; top [i] /= lt; norm[i] /= ln; } Tempest::ModelBounds bds; std::fill( bds.min, bds.min+3, -0.5 ); std::fill( bds.mid, bds.mid+3, 0 ); std::fill( bds.max, bds.max+3, 0.5 ); visible.clear(); for( size_t i=0; i<particles.size(); ++i ){ ParticleSystem &p = *particles[i]; Tempest::ModelBounds bds1 = bds; float dpos[3] = {p.x(), p.y(), p.z()}; for( int r=0; r<3; ++r ){ bds1.min[r] += dpos[r]; bds1.mid[r] += dpos[r]; bds1.max[r] += dpos[r]; } if( scene.viewTester().isVisible( bds1, mvp ) ) visible.push_back( &p ); } for( size_t i=0; i<dispath.size(); ++i ){ ParticleSystem &p = *dispath[i]; Tempest::ModelBounds bds1 = bds; float dpos[3] = {p.x(), p.y(), p.z()}; for( int r=0; r<3; ++r ){ bds1.min[r] += dpos[r]; bds1.mid[r] += dpos[r]; bds1.max[r] += dpos[r]; } if( scene.viewTester().isVisible( bds1, mvp ) ) visible.push_back( &p ); else dispath[i].reset(); } { size_t dc = 0; for( size_t i=0; i<dispath.size(); ++i ){ if( dispath[i] ){ dispath[dc] = dispath[i]; ++dc; } } dispath.resize(dc); } std::sort( visible.begin(), visible.end(), cmpMat ); raw.vertex.clear(); const ProtoObject::View *currView = 0; for( size_t i=0; i<visible.size(); ++i ){ ParticleSystem &p = *visible[i]; if( currView==0 || currView->name != p.viewInfo().name ){ if( currView && raw.vertex.size() ){ GraphicObject obj(scene); res.model( raw ).setTo( obj ); setupMaterial( obj, *currView, Tempest::Color() ); view.push_back( obj ); raw.vertex.clear(); } currView = &p.viewInfo(); } p.exec( dt ); } if( currView && raw.vertex.size() ){ GraphicObject obj(scene); res.model( raw ).setTo(obj); setupMaterial( obj, *currView, Tempest::Color() ); view.push_back( obj ); } for( size_t i=0; i<dispath.size(); ){ if( dispath[i]->par.size()==0 ){ std::swap( dispath[i],dispath.back() ); dispath.pop_back(); } else { ++i; } } }
void RenderingCoreAnaglyph::resetEye() { setupMaterial(video::ECP_ALL); RenderingCoreStereo::resetEye(); }
void RenderingCoreAnaglyph::useEye(bool right) { RenderingCoreStereo::useEye(right); driver->clearZBuffer(); setupMaterial(right ? video::ECP_GREEN | video::ECP_BLUE : video::ECP_RED); }