在iOS上的OpenFrameworks中使用videoGrabber和ofMesh

时间:2012-11-02 20:18:54

标签: ios openframeworks

首次在iOS上潜入OF ...令人兴奋!作为第一次运行,我正在尝试将我之前制作的应用程序移植到iOS应用程序中。它对视频摄像机的视频产生了非常简单的rutt etra效果。我有它作为一个Mac应用程序工作,但我似乎无法在我的iPhone上正确显示它。网格正在绘制,但我不认为我从我的相机获取像素值到vidPixels以改变网格的颜色。我基于iOS 0072中的videoGrabberExample。我使用的是MacBook Pro,10.7.5,运行Xcode 4.5.2。

任何人都可以看看,如果我做错了,请告诉我? :)非常感谢提前。

代码:

testApp.mm

#include "testApp.h"
#include "ofGLUtils.h"
#include "ofGLRenderer.h"

//--------------------------------------------------------------
void testApp::setup(){  
ofxiPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofSetFrameRate(30);

grabber.initGrabber(480, 360);

yStep = 5;
xStep = 5;

  //  drawRuttEtra = false;

ofBackground(0, 0, 0);

}

//--------------------------------------------------------------
void testApp::update(){
//ofBackground(255,255,255);

grabber.update();

if(grabber.isFrameNew()){
vidPixels = grabber.getPixelsRef();
}

}

//--------------------------------------------------------------
void testApp::draw(){   

glEnable(GL_DEPTH_TEST);

    ofMesh mesh;

    int rowCount = 0;
    for (int y = 0; y<grabber.height; y+=yStep){
        ofNoFill();
        mesh.setMode(OF_PRIMITIVE_LINE_STRIP);

        if (rowCount % 2 == 0) {
            for (int x = 0; x < grabber.width; x += xStep){
                ofColor curColor = vidPixels.getColor(x, y);
                mesh.addColor(ofColor(curColor));
                mesh.addVertex(ofVec3f(x,y, curColor.getBrightness() * 0.3));
            }
        } else {
            for (int x = grabber.width-1; x >= 0; x -= xStep){
                ofColor curColor = vidPixels.getColor(x, y);
                mesh.addColor(ofColor(curColor));
                mesh.addVertex(ofVec3f(x,y, curColor.getBrightness() * 0.3));                    }
        }
        rowCount++;
    }
    mesh.draw();
   // grabber.draw(0,0);
}

testApp.h

#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp{

public:
    void setup();
    void update();
    void draw();
    void exit();

    void touchDown(ofTouchEventArgs & touch);
    void touchMoved(ofTouchEventArgs & touch);
    void touchUp(ofTouchEventArgs & touch);
    void touchDoubleTap(ofTouchEventArgs & touch);
    void touchCancelled(ofTouchEventArgs & touch);

    void lostFocus();
    void gotFocus();
    void gotMemoryWarning();
    void deviceOrientationChanged(int newOrientation);

    ofVideoGrabber grabber;
    ofTexture tex;
    unsigned char * pix;

    //rutt etra effect

    int yStep;
    int xStep;
    bool drawRuttEtra;

    ofPixels vidPixels;

};

main.mm

#include "ofMain.h"
#include "testApp.h"

int main(){
ofSetupOpenGL(1024,768, OF_FULLSCREEN);         // <-------- setup the GL context
ofRunApp(new testApp);
}

我尝试做一些调试,看看可能会发生什么。

我想确保ifFrameNew()有效。尝试:

if(grabber.isFrameNew()){  
   cout<< "i'm grabbing new pixels!" << endl;  
vidPixels = grabber.getPixelsRef();  
} 

打印“我正在抓取新的像素!”,这样如果块正在运行。

在我的double for循环中,如果我输入vidPixels.getColor(x,y)的值

cout<<vidPixels.getColor(x,y) << endl;

我得到全部255 ...这让我觉得grabber.getPixelsRef()不起作用,我认为它应该如何。

有什么想法吗?

0 个答案:

没有答案