本文整理汇总了C++中ofTexture::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ ofTexture::allocate方法的具体用法?C++ ofTexture::allocate怎么用?C++ ofTexture::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofTexture
的用法示例。
在下文中一共展示了ofTexture::allocate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
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;
}
示例2: prepareBitmapTexture
//---------------------------------------------------------------------
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);
}
}
示例3: ofLoadImage
//----------------------------------------------------------------
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;
}
示例4: ofLoadImage
//----------------------------------------------------------------
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;
}
示例5: ofxCreateGaussianMapTexture
//--------------------------------------------------------------
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);
}
示例6: copy
void copy(S& src, ofTexture& tex) {
Mat mat = toCv(src);
int glType;
Mat buffer;
if(mat.depth() != CV_8U) {
copy(mat, buffer, CV_8U);
} else {
buffer = mat;
}
if(mat.channels() == 1) {
glType = GL_LUMINANCE;
} else {
glType = GL_RGB;
}
int w = buffer.cols;
int h = buffer.rows;
tex.allocate(w, h, glType);
tex.loadData(buffer.ptr(), w, h, glType);
}
示例7: prepareBitmapTexture
//---------------------------------------------------------------------
static void prepareBitmapTexture(){
if (!bBitmapTexturePrepared){
myLetterPixels.allocate(16*16, 16*16, 4); // letter size:8x14pixels, texture size:16x8letters, gl_rgba: 4bytes/1pixel
myLetterPixels.set(0);
bitmappedFontTexture.allocate(16*16, 16*16, GL_RGBA, 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)*4] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 255;
}else{
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 0;
}
}
}
}
bitmappedFontTexture.loadData(myLetterPixels);
bitmappedFontTexture.setTextureMinMagFilter(GL_LINEAR,GL_NEAREST);
charMesh.setMode(OF_PRIMITIVE_TRIANGLES);
}
}
示例8: receive
//----------
bool Receiver::receive(ofTexture & texture) {
try {
//check if we're initialised
if (!this->isInitialized()) {
throw("Not initialized");
}
//prepare the channel name, allow it to be changed if different channels are available
char mutableName[256];
unsigned int mutableWidth, mutableHeight;
strcpy_s(mutableName, this->channelName.size() + 1, this->channelName.c_str());
//check if the texture is allocated correctly, if not, allocate it
if (texture.getWidth() != this->width || texture.getHeight() != this->height) {
int format = texture.isAllocated() ? texture.getTextureData().glInternalFormat : this->defaultFormat;
texture.allocate(width, height, format);
}
//pull data into the texture (keep any existing fbo attachments)
GLint drawFboId = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
if (!this->spoutReceiver->ReceiveTexture(mutableName, mutableWidth, mutableHeight, texture.getTextureData().textureID, texture.getTextureData().textureTarget, false, drawFboId)) {
throw("Can't receive texture");
}
//update our local settings incase anything changed
this->channelName = mutableName;
this->width = mutableWidth;
this->height = mutableHeight;
return true;
}
catch (const char * e) {
ofLogError("ofxSpout::Receiver::receive") << e;
return false;
}
}
示例9: endFrame
bool fboRecorder::endFrame(bool _showBuffer){
if(!isRecording()) return false;
if(!useGrabScreen){
if(!bFrameStarted) return false;
fbo.end();
//fbo.getTexture().getTextureData().bFlipTexture = false;
bFrameStarted=false;
}
static ofTexture tmpTex;
int w = ofGetWidth();
int h = ofGetHeight();
if(!tmpTex.isAllocated()){
tmpTex.allocate( w, h, GL_RGBA );
}
switch(fboRecMode){
case VIDEOREC_MODE_FILE_H264 :
case VIDEOREC_MODE_FILE_PNG : {
ofPixels pix;
pix.allocate(fbo.getWidth(),fbo.getHeight(), ofGetImageTypeFromGLType(GL_RGB));
if(useGrabScreen){
tmpTex.loadScreenData(0, 0, w, h);
tmpTex.readToPixels(pix);
}
else {
fbo.readToPixels(pix);
}
ofxVideoRecorder::addFrame(pix);
break;
}
#ifdef KM_ENABLE_SYPHON
case VIDEOREC_MODE_SYPHON: {
//fbo.updateTexture( fbo.getTexture().texData.textureID );
if( useGrabScreen ){
//syphonServer.publishScreen();
tmpTex.loadScreenData(0, 0, ofGetWidth(), ofGetHeight());
//tmpTex = fbo.getTexture();
syphonServer.publishTexture( &tmpTex );
}
else {
//tmpTex = fbo.getTexture();
syphonServer.publishTexture( &fbo.getTexture() );
}
break;
}
#endif
default:
return false;
break;
}
// flush
tmpTex.clear();
if(_showBuffer){
if(!useGrabScreen){
#ifdef KM_ENABLE_SYPHON
if( fboRecMode==VIDEOREC_MODE_SYPHON ){
#else
if(false){
#endif
fbo.draw(0, 0, fbo.getWidth(), fbo.getHeight()); // show recorded image
}
else {
fbo.draw(0, fbo.getHeight(),fbo.getWidth(), -fbo.getHeight()); // show recorded image
}
}
}
return true;
}
// LISTENERS
void fboRecorder::beforeDraw( karmaControllerDrawEventArgs& _args ){
beginFrame();
}
void fboRecorder::afterDraw( karmaControllerDrawEventArgs& _args ){
endFrame(videoRecShowOutput);
}
示例10: setup
//--------------------------------------------------------------
void testApp::setup(){
// ofSetFrameRate(60);
ofBackground(0, 0, 0);
glDisable(GL_DEPTH_TEST);
float w = 720; //ofGetWidth();
float h = 720; //ofGetHeight();
// renderFbo.allocate(ofGetWidth() * 0.75, ofGetHeight() * 0.75, GL_RGBA32F);
renderFbo.allocate(w, h, GL_RGBA32F);
renderFbo.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
// renderFbo.getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
parts_res = (int)sqrt((float)numParticles);
numParticles = parts_res * parts_res;
float * parts_buf = new float[numParticles * 4];
for (int x = 0; x < parts_res; x++) {
for (int y = 0; y < parts_res; y++) {
int i = x * parts_res + y;
parts_buf[i * 4 + 0] = ofRandom(0.0, w-1);
parts_buf[i * 4 + 1] = ofRandom(0.0, h-1);
parts_buf[i * 4 + 2] = ofRandom(0.0, part_life);
parts_buf[i * 4 + 3] = 0.0;
/* pos is now an index into the postion map fbo */
pos[i][0] = x;
pos[i][1] = y;
pos[i][2] = 0;
}
}
parts_vbo.setVertexData((ofVec3f *)&pos[0], numParticles, GL_STATIC_DRAW);
randtex.allocate(parts_res, parts_res, GL_RGBA32F);
randtex.setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
randtex.loadData(parts_buf, parts_res, parts_res, GL_RGBA);
partsFbo.allocate(parts_res, parts_res, GL_RGBA32F);
partsFbo.src->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
partsFbo.dst->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
partsFbo.src->getTextureReference().loadData(parts_buf, parts_res, parts_res, GL_RGBA);
partsFbo.dst->getTextureReference().loadData(parts_buf, parts_res, parts_res, GL_RGBA);
// partsFbo.src->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
// partsFbo.dst->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
delete[] parts_buf;
colorFbo.allocate(parts_res, parts_res, GL_RGBA32F);
colorFbo.src->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
colorFbo.dst->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
// colorFbo.src->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
// colorFbo.dst->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
colorShader.load("", "color.frag");
velFbo.allocate(parts_res, parts_res, GL_RGBA32F);
velFbo.src->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
velFbo.dst->getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST);
// velFbo.src->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
// velFbo.dst->getTextureReference().setTextureWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
velshader.load("", "velocity.frag");
partshader.load("particle.vert", "");
posshader.load("", "position.frag");
debugShader.load("", "debug.frag");
debugFbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA32F);
w = h = renderFbo.getHeight();//720;//ofGetHeight();
dja.setup(w, h, 200);
dja.logmaxd = 5.0;
dja.setZoom(zoom);
dja.setParam(0.5 * PI, 0.5 * PI, -0.5 * PI, -0.5 * PI);
dja.update();
randmap_rebuild(-1.0, 1.0);
needDraw = true;
blur = new ofxBlur();
// blur->setup(ofGetWidth(), ofGetHeight());
blur->setup(renderFbo.getWidth(), renderFbo.getHeight());
blur->setScale(blur_scale);
// printf("setup: blur dim %.0f %.0f\n", blur.getTextureReference().getWidth(), blur.getTextureReference().getHeight());
cf.setup(renderFbo.getWidth(), renderFbo.getHeight());
cf.setScale(0.5);
cf.build(dja.getTextureReference());
// cf.setScale(curl_scale);
//at some stage set inital vels cause atm it looks not so good when it starts
velFbo.src->begin();
ofClear(ofFloatColor(0.0, 0.0, -1.0, 1.0));
velFbo.src->end();
width_offset = (int)((renderFbo.getWidth() - dja.getWidth()) / 2.0);
//.........这里部分代码省略.........
示例11: setup
//--------------------------------------------------------------
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
}