thanks for the reply man. but still now work. following is the complete code:
ofApp.h
#pragma once
#include "ofMain.h"
#include "MSAOpenCL.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
int camw_, camh_;
ofVideoGrabber cam_;
ofImage img_;
ofImage img2_,img3_;
ofPixels resultPixels_;
msa::OpenCL openCL_;
msa::OpenCLImage clImage_[2]; // two OpenCL images
unsigned char *pixels_;
};
ofApp.cpp
#include “ofApp.h”
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);
camw_ = 640;
camh_ = 480;
cam_.initGrabber(camw_,camh_);
img_.allocate(camw_,camh_,OF_IMAGE_COLOR);
img2_.allocate(camw_, camh_, OF_IMAGE_COLOR_ALPHA);
img3_.allocate(camw_, camh_, OF_IMAGE_COLOR_ALPHA);
pixels_ = new unsigned char[camw_*camh_*4];
openCL_.setupFromOpenGL(0);
clImage_[0].initWithTexture(camw_, camh_, GL_RGBA);
clImage_[1].initWithTexture(camw_, camh_, GL_RGBA);
openCL_.loadProgramFromFile("ImageProcessing.cl");
openCL_.loadKernel("msa_flipx");
}
//--------------------------------------------------------------
void ofApp::update(){
cam_.update();
if (cam_.isFrameNew()) {
img_.setFromPixels(cam_.getPixels());
int pixelIdx = 0;
for (int i = 0; i < camh_; i++) {
for (int j = 0; j < camw_; j++) {
int rgbIdx = 3 * pixelIdx;
int rgbaIdx = 4 * pixelIdx;
pixels_[rgbaIdx] = cam_.getPixels()[rgbIdx];
pixels_[rgbaIdx+1] = cam_.getPixels()[rgbIdx+1];
pixels_[rgbaIdx+2] = cam_.getPixels()[rgbIdx+2];
pixels_[rgbaIdx+3] = 255;
pixelIdx++;
}
}
clImage_[0].write(pixels_);
shared_ptr<msa::OpenCLKernel>(kernel) = openCL_.kernel("msa_flipx");
kernel->setArg(0, clImage_[0]);
kernel->setArg(1, clImage_[1]);
kernel->run2D(camw_, camh_);
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255);
img_.draw(0,0,320,240);
openCL_.finish();
clImage_[1].getTexture().draw(320,0,320,240);
img2_.setFromPixels(pixels_, camw_, camh_, OF_IMAGE_COLOR_ALPHA);
cam_.getTexture().readToPixels(img3_.getPixels());//this works
//clImage_[1].getTexture().readToPixels(img3_.getPixels());//this just show a complete blank image
img3_.update();
img2_.draw(0,240,320,240);
img3_.draw(320, 240, 320, 240);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}