//---------------------------------------------------------- void ofTexture::bind(int textureLocation){ //we could check if it has been allocated - but we don't do that in draw() if(texData.alphaMask){ ofGetGLRenderer()->setAlphaMaskTex(*texData.alphaMask); } enableTextureTarget(textureLocation); if(ofGetUsingNormalizedTexCoords()) { ofSetMatrixMode(OF_MATRIX_TEXTURE); ofPushMatrix(); ofMatrix4x4 m; #ifndef TARGET_OPENGLES if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) m.makeScaleMatrix(texData.width, texData.height, 1.0f); else #endif m.makeScaleMatrix(texData.width / texData.tex_w, texData.height / texData.tex_h, 1.0f); ofLoadMatrix(m); ofSetMatrixMode(OF_MATRIX_MODELVIEW); } if(texData.useTextureMatrix){ ofSetMatrixMode(OF_MATRIX_TEXTURE); if(!ofGetUsingNormalizedTexCoords()) ofPushMatrix(); ofMultMatrix(texData.textureMatrix); ofSetMatrixMode(OF_MATRIX_MODELVIEW); } texData.isBound = true; }
//-------------------------------------------------------------- void ofApp::setup() { #ifdef TARGET_OPENGLES // While this will will work on normal OpenGL as well, it is // required for OpenGL ES because ARB textures are not supported. // If this IS set, then we conditionally normalize our // texture coordinates below. ofEnableNormalizedTexCoords(); #endif img.load("linzer.png"); // OF_PRIMITIVE_TRIANGLES means every three vertices create a triangle mesh.setMode(OF_PRIMITIVE_TRIANGLES); int skip = 10; // this controls the resolution of the mesh int width = img.getWidth(); int height = img.getHeight(); ofVec2f imageSize(width,height); ofVec3f zero(0, 0, 0); for(int y = 0; y < height - skip; y += skip) { for(int x = 0; x < width - skip; x += skip) { /* To construct a mesh, we have to build a collection of quads made up of the current pixel, the one to the right, to the bottom right, and beneath. These are called nw, ne, se and sw. To get the texture coords we need to use the actual image indices. */ ofVec3f nw = getVertexFromImg(img, x, y); ofVec3f ne = getVertexFromImg(img, x + skip, y); ofVec3f sw = getVertexFromImg(img, x, y + skip); ofVec3f se = getVertexFromImg(img, x + skip, y + skip); ofVec2f nwi(x, y); ofVec2f nei(x + skip, y); ofVec2f swi(x, y + skip); ofVec2f sei(x + skip, y + skip); // ignore any zero-data (where there is no depth info) if(nw != zero && ne != zero && sw != zero && se != zero) { addFace(mesh, nw, ne, se, sw); // Normalize our texture coordinates if normalized // texture coordinates are currently enabled. if(ofGetUsingNormalizedTexCoords()) { nwi /= imageSize; nei /= imageSize; sei /= imageSize; swi /= imageSize; } addTexCoords(mesh, nwi, nei, sei, swi); } } } vboMesh = mesh; }
//---------------------------------------------------------- void ofTexture::unbind(int textureLocation){ disableTextureTarget(textureLocation); if(texData.alphaMask){ ofGetGLRenderer()->disableAlphaMask(); } if(texData.useTextureMatrix || ofGetUsingNormalizedTexCoords()) { ofSetMatrixMode(OF_MATRIX_TEXTURE); ofPopMatrix(); ofSetMatrixMode(OF_MATRIX_MODELVIEW); } texData.isBound = false; }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(0); ofSetFrameRate(30); ofEnableAlphaBlending(); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glEnable(GL_DEPTH_TEST); glPointSize(1.0); drawFBO = false; autoRotate = true; drawEQ = false; //not really needed // glEnable(GL_ALPHA_TEST); // glAlphaFunc(GL_GREATER, 0.10f); //generate the mesh points buildSphereMesh(rad, res, vm); cout << "nverts: " << vm.getNumVertices() << endl; cout << "arb: " << ofGetUsingArbTex() << ", norm: " << ofGetUsingNormalizedTexCoords() << endl; //load the texture shader shader.load("tex.vert", "tex.frag"); //fft init fftSmoothed = new float[8192]; memset(fftSmoothed, 0x00, sizeof(float) * 8192); //map the frequencies to bark bands float freq_spc = FREQ_MAX / (float)SPECTRAL_BANDS; for (int i = 0; i < SPECTRAL_BANDS; i++) { int bidx = bark(i * freq_spc); barkmap[i] = bidx; } //load the position updating frag shader pos_shader.load("", "position.frag"); //for the sphere we set this to the resolution which = #of verts along each axis fbo_res = res; //init the fbo's with blank data vector<ofVec3f> fbo_init_data; fbo_init_data.assign(fbo_res * fbo_res, ofVec3f(0.0, 0.0, 0.0)); posbuf.allocate(fbo_res, fbo_res, GL_RGB32F); posbuf.src->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB); posbuf.dst->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB); //reuse fbo_init_data for no real reason, it just needs to be blank eq_tex.allocate(fbo_res, 1, GL_RGB32F_ARB); eq_tex.loadData((float *)&fbo_init_data[0], fbo_res, 1, GL_RGB); axis_loc = fbo_res; angincr = 180.0/(float)fbo_res; player.loadSound("jhfd.mp3"); player.play(); //go }