Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ofMain.cpp
- #include "ofMain.h"
- #include "testApp.h"
- #include "ofAppGlutWindow.h"
- //========================================================================
- int main( ){
- ofAppGlutWindow window;
- ofSetupOpenGL(&window, 1680 ,680, OF_WINDOW); // <-------- setup the GL context
- // this kicks off the running of my app
- // can be OF_WINDOW or OF_FULLSCREEN
- // pass in width and height too:
- ofRunApp( new testApp());
- }
- //testApp.h
- #pragma once
- #include "ofMain.h"
- #define VIDWIDTH 640 // Video width
- #define VIDHEIGHT 480 // Video Height
- class testApp : public ofBaseApp{
- public:
- void setup();
- void update();
- void draw();
- ofVideoGrabber vidGrabber; // Video Grabber Object
- ofVbo ptsVbo; // VBO that stores points
- int numPixels; // Number of pixels in image
- ofVec3f pts[307200]; // This sucks
- ofFloatColor col[307200]; // This sucks
- };
- //testApp.cpp
- #include "testApp.h"
- //--------------------------------------------------------------
- void testApp::setup(){
- ofSetLogLevel(OF_LOG_NOTICE);
- //ofLogToFile("log.txt", true);
- vidGrabber.listDevices();
- vidGrabber.initGrabber(VIDWIDTH, VIDHEIGHT); // Setup vidGrabber
- numPixels = VIDWIDTH * VIDHEIGHT;
- }
- //--------------------------------------------------------------
- void testApp::update(){
- ofBackground(0, 0, 0);
- vidGrabber.grabFrame(); // Grab a frame
- if (vidGrabber.isFrameNew()){ // Check if frame is actually new
- unsigned char * pixels = vidGrabber.getPixels();
- // Cycle through pixels
- for (int y = 0; y < VIDHEIGHT; y++) {
- for (int x = 0; x < VIDWIDTH; x++) {
- int red = pixels[((y * VIDWIDTH) + x) * 3]; // Get the red data
- int green = pixels[((y * VIDWIDTH) + x) * 3 + 1]; // Get the green data
- int blue = pixels[((y * VIDWIDTH) + x) * 3 + 2]; // Get the blue data
- int brightness = (red+green+blue)/3; // Calculate brightness
- int px = x;
- int py = y;
- int pz = brightness;
- pts[x*y].set(px,py,pz); // Add values to pts array
- col[x*y].set(red,green,blue); // Add colour values to col array
- }
- }
- ptsVbo.setVertexData(pts, numPixels , GL_DYNAMIC_DRAW); // Add points to VBO
- ptsVbo.setColorData(col, numPixels, GL_DYNAMIC_DRAW); // Add colours to VBO
- }
- }
- //--------------------------------------------------------------
- void testApp::draw(){
- ofTranslate(200, 100); // Move a little bit
- ptsVbo.draw(GL_POINTS, 0, numPixels); // Draw VBO
- vidGrabber.draw(640+100, 0); // Draw the camera input
- }
Add Comment
Please, Sign In to add comment