Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Error regarding unknown OF pixel format

$
0
0

@Gil_Fuser wrote:

Hi everyone.

I'm getting errors with the following code, that although not critical, since the code runs, I would like to understand and correct what is causing it, if possible.

Every running frame gives me one of those:
[ error ] ofGLUtils: ofGetGLFormatFromPixelFormat(): unknown OF pixel format-1, returning GL_LUMINANCE

The code is making circular buffers and layering them.
Here is the code:

ofApp.h

#pragma once
#include "ofMain.h"
class circularPixelBuffer{
public:
    circularPixelBuffer(){
        currentIndex = 0;
    }
    void setup(int numFrames){
        frames.resize(numFrames);
        currentIndex = numFrames -1;
    }
    void pushPixels(ofPixels& pix){
        currentIndex--;
        if (currentIndex < 0) {
            currentIndex = frames.size() -1;
        }
        frames[currentIndex] = pix;
    }
    ofPixels& getDelayedPixels(size_t delay){
        if(delay < frames.size()){
            return frames[ofWrap(delay + currentIndex, 0, frames.size())];
        }
        return frames[0];
    }
protected:
    int currentIndex;
    deque<ofPixels> frames;
};
class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();
        ofVideoGrabber vidGrabber;
        unsigned char* myVideo;
        deque<ofPixels> frames0;
        deque<ofPixels> frames1;
        deque<ofPixels> frames2;
        float yoff;  // 2nd dimension of perlin noise
        int delayTime;
        int nDelayFrames;
        int currFrame0;
        int currFrame1;
        int currFrame2;
        int camWidth;
        int camHeight;
        circularPixelBuffer buffer0;
        circularPixelBuffer buffer1;
        circularPixelBuffer buffer2;
        ofTexture tex0;
        ofTexture tex1;
        ofTexture tex2;
};

ofApp.cpp

#include "ofApp.h"
//-------------------------------------------------------------
void ofApp::setup(){
    camWidth = 640;  // try to grab at this size.
    camHeight = 480;
    vidGrabber.setDeviceID(0);
    vidGrabber.setDesiredFrameRate(30);
    vidGrabber.setPixelFormat(OF_PIXELS_BGRA);
    vidGrabber.initGrabber(camWidth, camHeight);
    ofSetVerticalSync(true);
    nDelayFrames = 720; //Set buffer size
    buffer0.setup(nDelayFrames);
    buffer1.setup(nDelayFrames);
    buffer2.setup(nDelayFrames);
    yoff = 50.0;
    currFrame0 = nDelayFrames-1;
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    tex0.allocate(vidGrabber.getPixels());
    tex1.allocate(vidGrabber.getPixels());
    tex2.allocate(vidGrabber.getPixels());
}
//-------------------------------------------------------------
void ofApp::update(){
    ofBackground(0);
    vidGrabber.update();
    if(vidGrabber.isFrameNew()){
        buffer0.pushPixels(vidGrabber.getPixels());
        buffer1.pushPixels(vidGrabber.getPixels());
        buffer2.pushPixels(vidGrabber.getPixels());
    }
    //review ofNoise to ajust that propperly
    yoff = fmod((yoff + 0.01), nDelayFrames);
    delayTime = int(ofClamp(ofMap(ofNoise(yoff)*10, 1, 7.1, 1, 480, 1), 1, 480));
    nDelayFrames = int(delayTime);
    currFrame0 = ( currFrame0 + nDelayFrames - 1 ) % nDelayFrames;
    currFrame1 = ( currFrame0 + 80 ) % nDelayFrames;
    currFrame2 = ( currFrame0 + 160 ) % nDelayFrames;
}
//-------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(255, 255, 255, 255);
    vidGrabber.draw(0, 0, 1920, 1080);
    ofSetColor(255, 255, 255, 85);
    tex0.loadData(buffer0.getDelayedPixels(currFrame0));
    tex0.draw(1920, 1080, -1920, -1080);
    tex1.loadData(buffer1.getDelayedPixels(currFrame1));
    tex1.draw( 0, 1080, 1920, -1080);
    tex2.loadData(buffer2.getDelayedPixels(currFrame2));
    tex2.draw( 1920, 0, -1920, 1080);
}

that's all.
Thank you in advance and best regards,
Gil

edit: some more information: I'm using Linux Ubuntu 16.10, OF 0.9.8 and QT Creator.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles