User Tools

Site Tools


Sidebar



openframeworks

Table of Contents

openFrameworks

cannot convert parameter 1 from 'char' to 'LPCWSTR'

stackoverflow: in Visual Studio project properties set 'Character Set' to 'not set'.

recent problem with ofVideoPlayer

cheap tricks video

read 16bit raw image into ofImage

ofImage heightmap;
ofFile file("terra8M.raw", ofFile::ReadOnly, true);
ofBuffer raw(file);
 
int w = 4096, h = 2048, wxh = w*h;    
heightmap.allocate(w, h, OF_IMAGE_COLOR_ALPHA);
 
int i = 0;
for (int y = 0; y < h; y++) {
  for (int x = 0; x < w; x++) {
    int r = raw.getData()[i++];
    int a = raw.getData()[i++];
    heightmap.setColor(x, y, ofColor(r,0,0,a));
  }
}
 
heightmap.update();
heightmap.save("output.png");

openFrameworks code style guide

loading 16 bits grayscale images seems to be broken after version 008x

https://github.com/openframeworks/openFrameworks/issues/3249 I modified some code in putBmpIntoPixels to be able to load 16 bits grayscale images:

snippet.cpp
	if(sizeof(PixelType)==1 &&
		(FreeImage_GetColorType(bmp) == FIC_PALETTE || FreeImage_GetBPP(bmp) < 8
		||  imgType!=FIT_BITMAP)) {
		if(FreeImage_IsTransparent(bmp)) {
			bmpConverted = FreeImage_ConvertTo32Bits(bmp);
////////////////////////////////////////////
// added this to support 16 bit grayscale images
		} else if (FreeImage_GetBPP(bmp)==16) {                     
			bmpConverted = FreeImage_ConvertToType(bmp,FIT_UINT16); 
////////////////////////////////////////////
		} else {
			bmpConverted = FreeImage_ConvertTo24Bits(bmp);
		}
		bmp = bmpConverted;

enable errors to force checking return values

-Werror=return-type

ofSetupScreenOrtho

snippet.cpp
//--------------------------------------------------------------
void ofApp::draw(){
	ofSetupScreenOrtho(ofGetWidth(),ofGetHeight(),-1000,1000);
	ofTranslate(mouseX,mouseY);
	ofDrawSphere(ofGetHeight()/2);
}

Projectgenerator on Linux: error projectgenerator not found

first run compilePG.sh

Projectgenerator on Linux: terminate called after throwing an instance of std::regex_error

Command failed: /bin/sh -c "projectGenerator"  -o"/home/globe4d/Documents/of0092" -a" " -p"linux64" "/home/globe4d/Documents/of0092/apps/myApps/mySketch"
terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)

solution? https://github.com/openframeworks/openFrameworks/issues/4575

ipv 'test' kan ik beter 'ppa' doen zegt peter. daar staat gcc-4.9 ook bij.

sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa   # this one worked for me: ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
sudo apt-get remove g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
gcc -v

then run compilePG.sh again.

Logitech C920 with IR blocker removed and red filter added. OpenCV code using BackgroundSubtractorMOG2

see logitech

projectGenerator

cmdline command:

"/Users/rick/Documents/openFrameworks/of0092/projectGenerator-osx/projectGenerator.app/Contents/Resources/app/app/projectGenerator"  -o"/Users/rick/Documents/openFrameworks/of0092" -a"ofxCv,ofxOpenCv" -p"osx" "/Users/rick/Documents/openFrameworks/of0092/apps/myApps/cvBgTest2"

Segmentation Fault 11 with projectGenerator

I got a Segmentation Fault 11 when I changed the scripts/templates/osx Xcode project. I removed ofApp.cpp and ofApp.h but that resulted in a lot of recursive calls in the xcodeProject.cpp::addInclude function.
I worked around this by manually removing the xml elements of ofApp.h and ofApp.cpp in project.pbxproj within the emptyExample.xcodeproject folder.

extending ofBaseVideoDraws in of009

inherit from ofBaseDrawsVideo class

In XCode when pressing Cmd+8 then click on Clock icon on bottom you get detailed info about build error message. It shows which functions you need to implement:

what means 'const' after method definition?

When you define a method like this in your class:

bool isReady() const

It means that it “will return a bool but it will not change the logic state of your object. So this is your getter.” So by supplying const you promise the compiler you won't change any data inside your class instance.

Member function '...' not viable:

Member function 'drawGlobe' not viable: 'this' argument has type 'const Globe', but function is not marked const

???

Field type '...' is an abstract class

In openFrameworks 009 the declarations of some ofBase classes has changed. For example when your class inherits from ofBaseDraws you need to add the const term after your function definition:

  float getWidth() const { return 640; }
  float getHeight() const { return 480; }
  void draw(float x, float y) const { /*...*/ }
  void draw(float x, float y, float w, float h) const { /*...*/ }

opencv2/opencv.hpp file not found

When you add ofxCv to your openFrameworks project make sure to also add ofxOpenCv. Because this adds the opencv2 folder to your project.

openFrameworks 009 on ElementaryOS

ArcText (curved text on circular path) with openFrameworks 009

make Debug openFrameworks 009

make Debug

then:

make RunDebug

or:

cd bin
gdb Project_debug
r

openframeworks 009

  • installing MSYS2 for openFrameworks 009.
    • you might need to set the HOME environment variable to your home folder (C:\Users\YOURUSERNAME) to be able to access your files from the MSYS2 shell.
      * there's a typo in the line cd your_oF_directory/scripts/win_cb/msys2. Remove the win
      cb part.
  • when the tutorial says: “Open a MINGW32 shell” it means run the following batch file (from the Start Menu):
C:\Windows\System32\cmd.exe /A /Q /K C:\msys64\mingw32_shell.bat
  • add c:\msys64\mingw32\bin;c:\msys64\usr\bin to the start of the PATH.
  • OF recommends K-Lite codec for video support.

main.cpp template

#include "ofMain.h"
 
class ofApp : public ofBaseApp {
public:
 
  void setup() {
  }
 
  void update() {
  }
 
  void draw() {
  }
};
 
int main( ){
  ofSetupOpenGL(1024,768,OF_WINDOW);
  ofRunApp(new ofApp());
}

tools and templates by Gene Kogan

mouse rotating globe with conversion from quaternions to latitude longitude

render and rotate a globe in openFrameworks

good old alpha trail with two FBO's

utf8

somehow certain characters 'recently' added to ISO885915 are shown as their predecessor in ISO88591 by openFrameworks ofTrueTypeFont. It looks like the Latin9Encoding::convert function called by ofTrueTypeFont::drawString is causing this problem. Read here about the differences. The only solution I've been able to find so far is to not use ofTrueTypeFont but to use the ofxTrueTypeFontUC addon: See solution below.
The loaded text-file is encoded as UTF-8 by notepad with the BOM character removed.

https://docs.google.com/spreadsheets/d/1uqJEke-ywsWAwTqaO_qOTicfBaonQfJZfWBRQoDxgKA/edit?usp=sharing

Nejhmotnejší objekt v naší...
#include "ofxTrueTypeFontUC.h"
 
class ofApp : public ofBaseApp {
public:
 
  ofxTrueTypeFontUC font;
 
  void setup() {
    font.loadFont("arial.ttf",13,true,true);
  }
 
  void draw() {
    string s = ofBufferFromFile("UTF8-without-BOM.txt").getText();
    font.drawString(s,20,50);
  }
};

my fork of ofxTrueTypeFontUC

- In 2014 I made a fork of ofxTrueTypeFontUC and added some functions to access the character meshes.
- June 22th 2015: I can't get the original ofxTrueTypeFontUC to compile on of0084 (and some older versions) codeblocks 12.11: fatal error: codecvt: No such file or directory. More people seem to have a similar problem. My 'old' fork of ofxTrueTypeFontUC works but is 15 commits behind at this moment.

Update: ofTrueTypeFont ISO-8859-15

“ In 1999, ISO needed to make the Euro currency symbol available. There were also a few other characters that were desired. So ISO created ISO-8859-15, which is identical to ISO-8859-1 except for 8 characters.” source: http://www.i18nqa.com/debug/table-iso8859-1-vs-iso8859-15.html

ofTrueTypeFont shows the characters as they were in ISO-8859-1. A fix was added by @kylemcdonald at Jun 15, 2013 to support the euro sign but the other 7 characters that were introduced can be supported the same way by using the following code in ofTrueTypeFont::loadFont.

if (glyph == 0xA4) glyph = 0x20AC;   //  Currency Sign -> Euro Sign
if (glyph == 0xA6) glyph = 0x0160;   //  Broken Bar -> Latin Capital Letter S With Caron
if (glyph == 0xA8) glyph = 0x0161;   //  Diaeresis -> Latin Small Letter S With Caron
if (glyph == 0xB4) glyph = 0x017D;   //  Acute Accent -> Latin Capital Letter Z With Caron
if (glyph == 0xB8) glyph = 0x017E;   //  Cedilla -> Latin Small Letter Z With Caron
if (glyph == 0xBC) glyph = 0x0152;   //  Vulgar Fraction One Quarter -> Latin Capital Ligature OE
if (glyph == 0xBD) glyph = 0x0153;   //  Vulgar Fraction One Half -> Latin Small Ligature OE
if (glyph == 0xBE) glyph = 0x0178;   //  Vulgar Fraction Three Quarters -> Latin Capital Letter Y With 

more characters: http://doc.infosnel.nl/extreme_utf-8.html

there were more characters with problems but these problems were 'deeper' (probably in the Poco convert from UTF8 to Latin9. We solved it this way:

ě	[
ů	]
č	{
Č	}
ř	<
ň	>
ť	_
 
if (glyph == '[') glyph = 0x11B;       // e met dakje op de kop
if (glyph == ']') glyph = 0x16F;       // u met rondje
if (glyph == '{') glyph = 0x10D;       // c met dakje op de kop
if (glyph == '}') glyph = 0x10C;       // C met dakje op de kop
if (glyph == '<') glyph = 0x159;       // r met dakje op de kop
if (glyph == '>') glyph = 0x148;       // n met dakje op de kop
if (glyph == '_') glyph = 0x165;       // t met accentje er naast

ftgl font

tr1/memory error

Set 'Buid Settings → Base SDK' to a lower version, for example 10.8

write to a file

ofFile file("tmp.txt",ofFile::WriteOnly);
file << "A" << endl;
file << "B" << endl;
file.close();

read text file

ofBufferFromFile("file.txt").getText();

gamuza

fbo depthbuffer

nog uitzoeken

stringify

Multiline syntax highlighted hardcoded strings in je code.

#define STRINGIFY(A) #A
 
 
static string myString = STRINGIFY(
				 bla die bla1
				 bla die bla2
				 bla die bla3
				 bla die bla4
				 bla die bla5);

blending crosshair/bullseye

ofPushMatrix(); //bullseye
ofTranslate(0,0,radius);
ofSetColor(255);
ofNoFill();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
ofCircle(0,0,5);
ofLine(0,1,0,6);
ofLine(0,-1,0,-6);
ofLine(1,0,6,0);
ofLine(-1,0,-6,0);
ofPopMatrix(); //bullseye

fbo's / ortho projection with WIDTH,HEIGHT

fbo.allocate(1200,1200);
 
void drawMainScreen() {
    fbo.begin();
    ofClear(255,0,0,255);
 
    ofSetupScreenOrtho(1200,1200,OF_ORIENTATION_UNKNOWN,true,-700,0);
    ofScale(1,-1);
    ofTranslate(fbo.getWidth()/2,-fbo.getHeight()/2);
 
    ofPushMatrix();
    ofRotate(angle,axis.x,axis.y,axis.z);
    bg.getTextureReference().bind();
    ofxEnableDepthTest();
    ofxQuadricSphere(600,128);
    ofPopMatrix();
 
    ofxDisableDepthTest();
    menu.draw();
 
    fbo.end();
 
    ofScale(.5,.5);
    fbo.draw(0,0);
}

params

int main(int argc, const char** argv){
    for (int i=0; i<argc; i++) {
        vector<string> keyvalue = ofSplitString(argv[i], "=");
        if (keyvalue.size()==2) params[keyvalue[0]] = keyvalue[1];
    }
   // ...
}

'old' codeblocks version: 10.05

splines

warping

debugging with gdb

see also lldb

You can also running the gcc debugger from terminal:
view plaincopy to clipboardprint?

gdb myFolder/openFrameworksDebug.app/Contents/MacOS/openFrameworksDebug   
>run  

personal note:

in ofxBlobsManager::update()

//remember prev pos for existing blobs
for( int i = 0; i < blobs.size(); i++ ) {
	ofxStoredBlobVO& b = blobs.at(i);
	b.pCentroid = b.centroid;
	b.pTip = b.tip;
	b.pTail = b.tail;
}

CL-Eye Test

draggable earth with easing

#include "ofMain.h"
#include "ofAppGlutWindow.h"
 
class testApp : public ofBaseApp {
public:
 
    ofImage earth;
    ofQuaternion qTo;
 
    void setup() {
        ofBackground(0);
        glEnable(GL_DEPTH_TEST);
        ofDisableArbTex();
        earth.loadImage("earth2k.jpg");
        earth.bind();
    }
 
    void draw() {
        static ofVec3f fromAxis,toAxis;
        static float fromAngle=0,toAngle;
 
        qTo.getRotate(toAngle,toAxis);
 
        fromAxis += (toAxis-fromAxis) * .1;
        fromAngle += (toAngle-fromAngle) * .1;
 
        ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
        ofRotate(fromAngle, fromAxis.x, fromAxis.y, fromAxis.z);
        quadricSphere(ofGetHeight()/3,32);
    }
 
    void mouseDragged(int x, int y, int button){
        ofPoint from(ofGetPreviousMouseX(), ofGetPreviousMouseY());
        ofPoint to(ofGetMouseX(), ofGetMouseY());
 
        from = toSphere(from / ofGetWidth() - 0.5f);
        to = toSphere(to / ofGetWidth() - 0.5f);
        ofPoint axis = from.crossed(to);
 
        qTo *= ofQuaternion(axis.x,axis.y,axis.z,from.dot(to));
    }
 
    ofPoint toSphere(ofPoint v) {  //-0.5 ... +0.5
        float mag = v.x*v.x + v.y*v.y;
        if (mag>1.0f) v.normalize();
        else v.z = sqrt(1.0f - mag);
        return v;
    }
 
    void quadricSphere(float radius, int resolution) {
        static GLUquadricObj *quadric = gluNewQuadric(); //because it's static, it's created only once
        gluQuadricTexture(quadric, GL_TRUE);
        gluQuadricNormals(quadric, GLU_SMOOTH);
        gluSphere(quadric, radius, resolution, resolution);
    }
};
 
//--------------------------------------------------------------
int main(){
	ofAppGlutWindow window;
	ofSetupOpenGL(&window, 500, 500, OF_WINDOW);
	ofRunApp(new testApp());
}

possible bug in ofxCvGrayScaleImage with ofSaveImage or img.saveImage()

work around: convert the ofxCvGrayScaleImage to ofxCvColorImage and then save the color image.

ofImage img;
ofxCvColorImage tmp;
tmp = bg; //bg is the ofxCvGrayScaleImage 
img.setFromPixels(tmp.getPixelsRef());
img.saveImage("cam_bg.png");

the same for load:

ofImage img;
img.loadImage("cam_bg.png");
ofxCvColorImage tmp;
tmp.setFromPixels(img.getPixelsRef());
bg = tmp;  //bg is the ofxCvGrayScaleImage 

install_name_tool usage on commandline

install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib libfmodex.dylib

to get .app running:

install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib emptyExample.app/Contents/MacOS/emptyExample 

openframeworks program crashes on glActiveTexture

Check if glActiveTexture is available:

if(glActiveTexture==NULL) {
      printf("glActiveTexture not supported\n");
      std::exit(1);
}

This was the case with me running Windows through Parallels on a Mac.

ofSetupScreenOrtho

ofSetupScreenOrtho(0,0,OFORIENTATIONUNKNOWN,true,-100,100); ofSetupScreenOrtho();

ofSetupScreenOrtho(-1,-1,-ofGetScreenHeight(),ofGetScreenHeight());

serial 250000 / 250K baudrate

some nice std::vector functions in ofUtils.h

template<class T>
void ofRandomize(vector<T>& values) {
	random_shuffle(values.begin(), values.end());
}
 
template<class T, class BoolFunction>
void ofRemove(vector<T>& values, BoolFunction shouldErase) {
	values.erase(remove_if(values.begin(), values.end(), shouldErase), values.end());
}
 
template<class T>
void ofSort(vector<T>& values) {
	sort(values.begin(), values.end());
}
 
template <class T>
unsigned int ofFind(const vector<T>& values, const T& target) {
	return distance(values.begin(), find(values.begin(), values.end(), target));
}
 
template <class T>
bool ofContains(const vector<T>& values, const T& target) {
	return ofFind(values, target) != values.size();
}

main.cpp

#include "ofAppGlutWindow.h"
#include "testApp.h"
 
int main() {
    ofAppGlutWindow window; 
    window.setGlutDisplayString("rgba double samples>=4"); 
    ofSetupOpenGL(&window, 500, 500, OF_WINDOW);
    ofRunApp(new testApp()); 
}

Ugly ofTrueTypeFont text after rotation

Use drawStringAsShapes instead of drawString

ofImage problems

exiftool -all= image.jpg

notes

openframeworks.h

#pragma once
 
#include "ofMain.h"
#include "ofAppGlutWindow.h"
 
class ofGlutApp : public ofBaseApp {
public:
 
    ofGlutApp() {
        ofSetupOpenGL(new ofAppGlutWindow(), 500, 500, OF_WINDOW);
    }
 
};
openframeworks.txt · Last modified: 2016/07/20 13:56 by rick