void setup() { if (bSetup) return; grayLineTex.allocate(1,3, GL_LUMINANCE_ALPHA); unsigned char gray_line_data[3*2] = { 255,0, 255,255, 255,0 // DARK BRIGHT DARK }; grayLineTex.loadData(gray_line_data, 1,3, GL_LUMINANCE_ALPHA); rgbLineTex.allocate(1,7, GL_RGBA); unsigned char rgb_line_data[7*4] = { 255,0,0,0, 255,0,0,255, //r DARK BRIGHT 0,255,0,0, 0,255,0,255, //g DARK BRIGHT 0,0,255,0, 0,0,255,255, //b DARK BRIGHT 0,0,255,0 // DARK }; rgbLineTex.loadData(rgb_line_data, 1,7, GL_RGBA); bSetup = true; cout << "Renderer textures initialized." << endl; }
void OpenCLImage::initFromTexture(ofTexture &tex, cl_mem_flags memFlags, int mipLevel) { ofLog(OF_LOG_VERBOSE, "OpenCLImage::initFromTexture"); init(tex.getWidth(), tex.getHeight(), 1); cl_int err; if(clMemObject) clReleaseMemObject(clMemObject); clMemObject = clCreateFromGLTexture2D(pOpenCL->getContext(), memFlags, tex.getTextureData().textureTarget, mipLevel, tex.getTextureData().textureID, &err); assert(err != CL_INVALID_CONTEXT); assert(err != CL_INVALID_VALUE); // assert(err != CL_INVALID_MIPLEVEL); assert(err != CL_INVALID_GL_OBJECT); assert(err != CL_INVALID_IMAGE_FORMAT_DESCRIPTOR); assert(err != CL_OUT_OF_HOST_MEMORY); assert(err == CL_SUCCESS); assert(clMemObject); texture = &tex; hasCorrespondingGLObject = true; }
void copy(S& src, ofTexture& tex) { imitate(tex, src); int w = tex.getWidth(), h = tex.getHeight(); int glType = tex.getTextureData().glTypeInternal; Mat mat = toCv(src); tex.loadData(mat.ptr(), w, h, glType); }
//--------------------------------------------------------------------- void ofDrawBitmapCharacterStart(int stringLength) { verts.clear(); coords.clear(); verts.assign(12 * (stringLength+1), 0); coords.assign(12 * (stringLength+1), 0); if(!bBitmapTexturePrepared) { prepareBitmapTexture(); } glesBitmappedFontTexture.bind(); #ifndef TARGET_OPENGLES // this temporarily enables alpha testing, // which discards pixels unless their alpha is 1.0f glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_EQUAL, 1.0f); #endif glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glTexParameterf(glesBitmappedFontTexture.getTextureData().textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); vC = 0; }
//--------------------------------------------------------------------- static void prepareBitmapTexture() { if (!bBitmapTexturePrepared) { glesBitmappedFontTexture.allocate(16*16, 16*16, GL_LUMINANCE_ALPHA, false); bBitmapTexturePrepared = true; for (int i = 0; i < 256; i++) { const unsigned char * face = bmpChar_8x13_Map[i]; for (int j = 1; j < 15; j++) { for (int k = 0; k < 8; k++) { if ( ((face[15-j] << k) & (128)) > 0 ) { myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2] = 255; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2+1] = 255; } else { myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2] = 0; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2+1] = 0; } } } } glesBitmappedFontTexture.loadData(myLetterPixels, 16*16, 16*16, GL_LUMINANCE_ALPHA); } }
//--------------------------------------------------------------------- void ofDrawBitmapCharacterEnd(){ if( vC > 0 ){ charMesh.getVertices().resize(vC); charMesh.getTexCoords().resize(vC); bitmappedFontTexture.bind(); ofPtr<ofGLProgrammableRenderer> programmableRenderer = ofGetGLProgrammableRenderer(); if (!programmableRenderer){ #ifndef TARGET_OPENGLES // this temporarily enables alpha testing, // which discards pixels unless their alpha is 1.0f glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0); #endif }else{ // glPush/PopAttrib is deprecated + we are doing the alpha test through a shader programmableRenderer->setAlphaBitmapText(true); } charMesh.draw(); if (!programmableRenderer){ #ifndef TARGET_OPENGLES glPopAttrib(); #endif }else{ programmableRenderer->setAlphaBitmapText(false); } bitmappedFontTexture.unbind(); } }
void LayoutVerticalStripes::render(ofTexture texture, ColorChannel *colorChannel, Layer layer) { float complexity = layer.complexity; int nrows = (complexity * 128) + 1; int ncols = 1; int xSize = ofGetWidth() / nrows; int ySize = ofGetHeight() / ncols; for (int row=0; row<nrows; row++) { for (int col=0; col<ncols; col++) { ofColor selectedColor = colorChannel->selectColor(nrows * col + row + layoutFrame); shader.begin(texture.getWidth(), texture.getHeight(), layer.masterScreenAlpha, layer.alpha, layer.contrast, layer.luminance, selectedColor.r, selectedColor.g, selectedColor.b); int xOffset = row * xSize; int yOffset = col * ySize; texture.draw(xOffset, yOffset, xSize, ySize); shader.end(); } } }
Obj(ofTexture & videoFrame) :pixelsChanged(false) ,createdTexPixels(false) { pixels.allocate(videoFrame.getWidth(),videoFrame.getHeight(),ofGetImageTypeFromGLType(videoFrame.texData.glInternalFormat)); updateTexture(videoFrame); total_num_frames++; }
void dpMarionette::drawBasicRibbon(ofTexture &tex, const ramNode &nodeA,const ramNode &nodeB, float width, int resolution, int A_Axis, int B_Axis, bool wired,int beginOffset, int endOffset, ofVec3f beginOffset3v,ofVec3f endOffset3v){ ofNode parent[2]; parent[0] = nodeA; parent[1] = nodeB; ofNode child[4]; child[0].setParent(parent[0]); child[1].setParent(parent[0]); child[2].setParent(parent[1]); child[3].setParent(parent[1]); ofVec3f aPos,bPos; if (A_Axis == DPM_AXIS_X) aPos.set(width/2.0, beginOffset, 0.0); if (A_Axis == DPM_AXIS_Y) aPos.set(0.0, width/2.0, 0.0); if (A_Axis == DPM_AXIS_Z) aPos.set(0.0, beginOffset, width/2.0); if (B_Axis == DPM_AXIS_X) bPos.set(width/2.0, endOffset, 0.0); if (B_Axis == DPM_AXIS_Y) bPos.set(0.0, width/2.0, 0.0); if (B_Axis == DPM_AXIS_Z) bPos.set(0.0, endOffset, width/2.0); child[0].setPosition(aPos.x * -1, aPos.y, aPos.z * -1); child[1].setPosition(aPos); child[2].setPosition(bPos.x * -1, bPos.y, bPos.z * -1); child[3].setPosition(bPos); child[0].setPosition(child[0].getPosition() + beginOffset3v); child[1].setPosition(child[1].getPosition() + beginOffset3v); child[2].setPosition(child[2].getPosition() + endOffset3v); child[3].setPosition(child[3].getPosition() + endOffset3v); ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight()); ofVec3f targA,targB; float sliceP; tex.bind(); glBegin(GL_TRIANGLE_STRIP); for (int i = 0;i < resolution + 1;i++){ sliceP = i/float(resolution); targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(), sliceP); targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(), sliceP); glTexCoord2d(0.0, texSize.y * sliceP); glVertex3d(targA.x, targA.y, targA.z); glTexCoord2d(texSize.x, texSize.y * sliceP); glVertex3d(targB.x, targB.y, targB.z); } glEnd(); tex.unbind(); }
//---------------------------------------------------------------- bool ofLoadImage(ofTexture & tex, const std::string& path, const ofImageLoadSettings &settings){ ofPixels pixels; bool loaded = ofLoadImage(pixels, path, settings); if(loaded){ tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels)); tex.loadData(pixels); } return loaded; }
//---------------------------------------------------------------- bool ofLoadImage(ofTexture & tex, string path){ ofPixels pixels; bool loaded = ofLoadImage(pixels,path); if(loaded){ tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels)); tex.loadData(pixels); } return loaded; }
//---------------------------------------------------------------- bool ofLoadImage(ofTexture & tex, const ofBuffer & buffer){ ofPixels pixels; bool loaded = ofLoadImage(pixels,buffer); if(loaded){ tex.allocate(pixels.getWidth(), pixels.getHeight(), ofGetGlInternalFormat(pixels)); tex.loadData(pixels); } return loaded; }
//-------------------------------------------------------------- void center(const ofTexture& texture, ofFbo& container, int angle) { if (angle % 2 == 0) { ofTranslate(container.getWidth() * 0.5f - texture.getWidth() * 0.5f, container.getHeight() * 0.5f - texture.getHeight() * 0.5f); } else { ofTranslate(container.getWidth() * 0.5f - texture.getHeight() * 0.5f, container.getHeight() * 0.5f - texture.getWidth() * 0.5f); } }
void GLTexture::initFromOFTexture(ofTexture &texture) { tex[0] = texture.getTextureData().textureID; type = texture.texData.glType; texTarget = texture.texData.textureTarget; //texTarget GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB, texInternalFormat = texture.texData.glTypeInternal; //GL_RGBA, GL_RGBA16F_ARB, GL_RGBA32F_ARB; minFilter = GL_LINEAR; //GL_NEAREST, GL_LINEAR magFilter = GL_LINEAR; //GL_NEAREST, GL_LINEAR width = texture.getWidth(); height = texture.getHeight(); }
//-------------------------------------------------------------- void ofxCreateGaussianMapTexture(ofTexture& texture, int resolution, int textureTarget) { ofTextureData textureData; textureData.width = resolution; textureData.height = resolution; textureData.glInternalFormat = GL_RGBA; textureData.textureTarget = textureTarget; unsigned char *data = createGaussianMap(resolution); texture.allocate(textureData); texture.loadData(data, resolution, resolution, GL_RGBA); }
void Puppet::setup(string paintingID, ofTexture tex, vector<ofPolyline> lines, ofPoint pos) { this->tex = tex; this->pos = pos; this->lines = lines; scale = 1.0; rot = 0.0; if (!lines.empty()) { ofPolyline line = lines.at(0); line = line.getResampledBySpacing(20); line.getVertices().erase(line.getVertices().begin()); if (line.size() > 5) { ofPolyline lineForTri = line; ofVec2f tweakForDeformer(tex.getWidth()/2, tex.getHeight()/2); ofVec2f centroid = lineForTri.getCentroid2D(); for (auto& p : lineForTri.getVertices()) { // enlarge from centroid // ofVec2f dir = (p - centroid).getNormalized(); // p += dir * 15; p -= tweakForDeformer; } mesh.triangulate(lineForTri, 28, -1); for (auto& v: mesh.triangulatedMesh.getVertices()) { mesh.triangulatedMesh.addTexCoord(tex.getCoordFromPoint(v.x + tweakForDeformer.x, v.y + tweakForDeformer.y)); } instance.setup(mesh.triangulatedMesh, lineForTri); vector<ofPoint> pts = line.getVertices(); b2dObj = ofPtr<ofxBox2dPolygon>(new ofxBox2dPolygon); b2dObj->addVertices(pts); b2dObj->setPhysics(1.0, 0.3, 0.3); b2dObj->triangulatePoly(); b2dObj->create(Globals::box2d->getWorld()); b2dObj->setPosition(pos); } } }
//---------------------------------------------------------- void of3dPrimitive::mapTexCoordsFromTexture( ofTexture& inTexture ) { bool bNormalized = true; #ifndef TARGET_OPENGLES bNormalized = (inTexture.getTextureData().textureTarget!=GL_TEXTURE_RECTANGLE_ARB); #endif ofTextureData& tdata = inTexture.getTextureData(); if(bNormalized) mapTexCoords( 0, 0, tdata.tex_t, tdata.tex_u ); else mapTexCoords(0, 0, inTexture.getWidth(), inTexture.getHeight()); ofVec4f tcoords = getTexCoords(); mapTexCoords(tcoords.x, tcoords.y, tcoords.z, tcoords.w); }
bool loadTexture(ofTexture & tex, const std::string & path, bool mipmap, float bias, int anisotropy){ bool ok = ofLoadImage(tex, path); if (ok){ tex.generateMipmap(); tex.enableMipmap(); tex.setTextureMinMagFilter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); tex.bind(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, bias); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); //TODO check for hw support! tex.unbind(); ofLogError("ofxApp") << "Failed to load texture at \"" << path << "\""; }else{ ofLogError("ofxApp") << "Failed to load texture at \"" << path << "\""; } return ok; }
//-------------------------------------------------------------- void testApp::preprocess(ofTexture &_text){ grayscale.setTexture( _text ); grayscale.update(); blur << grayscale; blur.update(); normals << blur; normals.update(); ofPixels normPixels; normPixels.allocate(normals.getWidth(), normals.getHeight(), 4); normals.getTextureReference().readToPixels(normPixels); _text.readToPixels(pixels); int scaledWidth = width/scale; int scaledHeight = height/scale; for(int x = 0; x <= scaledWidth; x++){ for(int y = 0; y <= scaledHeight; y++){ int scaledX = ofClamp(x*scale,0,width-1); int scaledY = ofClamp(y*scale,0,height-1); ofFloatColor normalColor = normPixels.getColor(scaledX, scaledY); int index = x + y * scaledWidth; ofPoint norm = ofPoint((normalColor.r - 0.5) * 2.0, (normalColor.g - 0.5) * 2.0, 0.0); float pct = 0.5; VF[index] = VF[index]*(1.0-pct) + norm * pct; } } }
void dfDisplacementMap::applyDisplaceMap(ofxCvColorImage& sourceImage,ofTexture& destTexture,float hscale=0.3, float vscale=0.3){ //apply displacement unsigned char * displacePixels = this->getPixels(); unsigned char * pixels = sourceImage.getPixels(); int displace,hdisplace,vdisplace; int totalPixels=height*width*3; unsigned char * videoDisplaced = new unsigned char[totalPixels]; for (int i = 0; i < totalPixels;i+=3){ hdisplace = (int)((displacePixels[i] - 127)*hscale); //x coord vdisplace = (int)((displacePixels[i+2] - 127) *vscale); //y coord if( i%(320*3)+hdisplace*3 >0 && i%(320*3)+hdisplace*3<320*3){ displace=hdisplace+vdisplace*320; }else{ displace = 0; } displace*= 3; if(i+displace>0 && i+displace<totalPixels){ videoDisplaced[i] = pixels[i+displace]; videoDisplaced[i+1] = pixels[i+displace+1]; videoDisplaced[i+2] = pixels[i+displace+2]; } } destTexture.loadData(videoDisplaced,width,height, GL_RGB); delete videoDisplaced; }
void FluidKinect::updateOpticalFlow(ofTexture & maskedKinect) { maskedKinect.readToPixels(maskPixels); blurImage.setFromPixels(maskPixels); blurImage.resize(opFlow.sizeSml.width, opFlow.sizeSml.height); blurImage.flagImageChanged(); opFlow.update(blurImage); }
void BulgeEffect::draw(ofTexture& tex, int x, int y) { applyBulgeShader.begin(); applyBulgeShader.setUniformTexture("bulge", blendBulge.getTextureReference(), 1); applyBulgeShader.setUniformTexture("tex", tex, 2); tex.draw(x, y); applyBulgeShader.end(); needToClear = true; }
void Clone::debugShader(ofTexture &tex, ofTexture &mask){ debugFbo.allocate(buffer.getWidth(), buffer.getHeight()); debugResultFbo.allocate(buffer.getWidth(), buffer.getHeight()); ofShader debugShader; debugShader.load("shader/maskBlurShader"); setStrength(16); debugFbo.begin(); // debugShader.begin(); // // //maskBlurShader.setUniformTexture("tex", tex, 1); // debugShader.setUniformTexture("tex0", tex, 1); // debugShader.setUniformTexture("mask", mask, 2); // debugShader.setUniform2f("direction", 0, 1); // debugShader.setUniform1i("k", strength); // mask.draw(0, 0); // // debugShader.end(); maskBlurShader.begin(); maskBlurShader.setUniformTexture("tex0", tex, 1); maskBlurShader.setUniformTexture("mask", mask, 2); //maskBlurShader.setUniform2f("direction", 0., 1./tex.getHeight()); maskBlurShader.setUniform2f("direction", 1./tex.getWidth(), 0.); maskBlurShader.setUniform1i("k", strength); tex.draw(0, 0); maskBlurShader.end(); debugFbo.end(); // debugResultFbo.begin(); // // maskBlurShader.setUniformTexture("tex0", debugFbo, 1); // maskBlurShader.setUniformTexture("mask", mask, 2); // maskBlurShader.setUniform2f("direction", 0., 1./tex.getHeight()); // maskBlurShader.setUniform1i("k", strength); // debugFbo.draw(0, 0); // // debugResultFbo.end(); }
void Output::publishTexture(ofTexture &tex) { assert(mutex); if (tex.getWidth() == uiFrameWidth && tex.getHeight() == uiFrameHeight) { ofPixels pix2; tex.readToPixels(pix2); mutex->lock(); if (!back_buffer->isAllocated() || back_buffer->getWidth() != tex.getWidth() || back_buffer->getHeight() != tex.getHeight()) { back_buffer->allocate(tex.getWidth(), tex.getHeight(), pix2.getNumChannels()); } memcpy(&back_buffer->getData()[1], pix2.getData(), pix2.size() - 1); if (back_buffer->getNumChannels() != 4) back_buffer->setNumChannels(4); has_new_frame = true; mutex->unlock(); } else ofLogError("ofxDeckLinkAPI::Output") << "invalid texture size"; }
void tricks::gl::effects::OutputFilter::draw(ofTexture &tex) { shader.begin(); shader.setUniformTexture("tex", tex, 0); shader.setUniform1f("brightness", brightness); shader.setUniform1f("contrast", contrast); shader.setUniform1f("saturation", saturation); tex.draw(0, 0, ofGetWidth(), ofGetHeight()); shader.end(); }
void ofxMask::drawEffect(ofTexture& maskedImage) { shader.begin(); shader.setUniformTexture("mask", fbo, 1); shader.setUniform1i("tex", 0); ofEnableAlphaBlending(); maskedImage.draw(0, 0); shader.end(); }
void ftParticleFlow::setObstacle (ofTexture& _tex) { ofPushStyle(); ofEnableBlendMode(OF_BLENDMODE_DISABLED); obstacleBuffer.clear(); obstacleBuffer.begin(); _tex.draw(0,0,simulationWidth,simulationHeight); obstacleBuffer.end(); ofPopStyle(); }
//-------------------------------------------------------------- void pbDrawRects( vector<ofPoint> &points, vector<ofVec2f> &texs, ofTexture &texture ) { if ( points.empty() ) { return; } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer( 3, GL_FLOAT, sizeof( ofPoint ), &points[0].x); glTexCoordPointer( 2, GL_FLOAT, sizeof( ofVec2f ), &texs[0].x ); texture.bind(); glDrawArrays(GL_QUADS, 0, points.size()); texture.unbind(); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); }
void Clone::update(ofTexture& src, ofTexture& dst, ofTexture& mask) { maskedBlur(src, mask, srcBlur); maskedBlur(dst, mask, dstBlur); buffer.begin(); ofPushStyle(); ofEnableAlphaBlending(); dst.draw(0, 0); cloneShader.begin(); cloneShader.setUniformTexture("src", src, 1); cloneShader.setUniformTexture("srcBlur", srcBlur, 2); cloneShader.setUniformTexture("dstBlur", dstBlur, 3); dst.draw(0, 0); cloneShader.end(); ofDisableAlphaBlending(); ofPopStyle(); buffer.end(); }
void dpMarionette::drawShoulderPoint(ofTexture &tex, const ramNode &nodeA, const ramNode &nodeB, const ramNode &nodeC,int width, int resolution){ //A is NECK! ofNode parent[3]; parent[0] = nodeA; parent[1] = nodeB; parent[2] = nodeC; ofNode child[4]; child[0].setParent(parent[0]); child[1].setParent(parent[0]); child[2].setParent(parent[1]); child[3].setParent(parent[2]); child[0].setPosition( width/2.0, 0.0, 0.0); child[1].setPosition(-width/2.0, 0.0, 0.0); child[2].setPosition( 12.0, 0.0, 0.0); child[3].setPosition(-12.0, 0.0, 0.0); ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight()); ofVec3f targA,targB; float sliceP; tex.bind(); glBegin(GL_TRIANGLE_STRIP); for (int i = 0;i < resolution + 1;i++){ sliceP = i/float(resolution); targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(), sliceP); targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(), sliceP); glTexCoord2d(0.0, texSize.y * sliceP); glVertex3d(targA.x, targA.y, targA.z); glTexCoord2d(texSize.x, texSize.y * sliceP); glVertex3d(targB.x, targB.y, targB.z); } glEnd(); tex.unbind(); }