//-------------------------------------------------------------- void EnvironmentMapping::draw(){ ofBackgroundGradient(ofColor(50), ofColor(255)); ofEnableDepthTest(); cam.begin(); //texture[0].getTexture().bind(); shader.begin(); shader.setUniformMatrix3f("normalMatrix", mat4ToMat3(ofGetCurrentNormalMatrix())); shader.setUniformTexture("EnvMap", texture[0].getTexture(), 0); shader.setUniform3f("BaseColor",baseColor->x/255,baseColor->y/255,baseColor->z/255); shader.setUniform1f("MixRatio", mixRatio); shader.setUniform3f("LightPosition",lightPos->x,lightPos->y,lightPos->z); //cout<<ofGetCurrentNormalMatrix()<<endl; //model.drawFaces(); sphere.draw(); shader.end(); //texture[0].getTexture().unbind(); cam.end(); ofDisableDepthTest(); gui.draw(); }
//-------------------------------------------------------------- void CubeMapping::draw(){ ofBackgroundGradient(ofColor(50), ofColor(255)); int pos=800; int boundToTextureUnit=pos; glActiveTexture( GL_TEXTURE0 + pos ); glEnable( GL_TEXTURE_CUBE_MAP ); glBindTexture( GL_TEXTURE_CUBE_MAP, textureObjectID ); ofEnableDepthTest(); cam.begin(); //texture[0].getTexture().bind(); shader.begin(); shader.setUniformMatrix3f("normalMatrix", mat4ToMat3(ofGetCurrentNormalMatrix())); shader.setUniform1i("EnvMap", 0); shader.setUniform3f("LightPosition",lightPos->x,lightPos->y,lightPos->z); shader.setUniform3f("BaseColor",baseColor->x/255,baseColor->y/255,baseColor->z/255); shader.setUniform1f("MixRatio", mixRatio); //cout<<ofGetCurrentNormalMatrix()<<endl; cube.draw(); shader.end(); glActiveTexture( GL_TEXTURE0 + boundToTextureUnit ); glBindTexture(GL_TEXTURE_CUBE_MAP, 0 ); glDisable( GL_TEXTURE_CUBE_MAP ); glActiveTexture( GL_TEXTURE0 ); cam.end(); ofDisableDepthTest(); gui.draw(); }
void ofApp::updateNormalMatrix() { normalMatrix = mat4ToMat3(ofGetCurrentMatrix(OF_MATRIX_MODELVIEW)); normalMatrix.invert(); normalMatrix.transpose(); }