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

Easy StencilTest

$
0
0

@UmiKOMPnMI4QrmG wrote:

I wrote a simple code, but the result was different from what I thought.

    glEnable(GL_STENCIL_TEST|GL_DEPTH_TEST);
	glClearStencil(0);
	glClearDepth(0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);


	float sabun = -10;

	glColor3f(1, 0, 0);
	glStencilFunc(GL_ALWAYS, 1, 0);
	glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE);
	planecreate(ofVec3f(0,0, sabun));

	sabun =0;

	glColor3f(0, 1,0);
	glStencilFunc(GL_ALWAYS, 0, 0);
	glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
	planecreate(ofVec3f(10, 10, sabun));

	sabun = 10;

	glColor3f(0, 0, 1);
	glStencilFunc(GL_EQUAL,2, 0);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	planecreate(ofVec3f(15, 15, sabun));


	glDisable(GL_STENCIL_TEST);

//

void  testApp::planecreate(ofVec3f v) {
	glBegin(GL_POLYGON);
	float x = 40;
	float y = 40;
	float z = v.z;

	glVertex3d(-x+ v.x,-y+v.y,z);
	glVertex3d(-x+ v.x, y + v.y,z);
	glVertex3d( x+ v.x, y + v.y, z);
	glVertex3d( x+ v.x,-y + v.y, z);
	glEnd();
}

I expected that the blue panel had been scraped off...

Posts: 1

Participants: 1

Read full topic


oF: share ofFbo between classes

$
0
0

@nvassalo wrote:

Hi I'm trying to create an fbo instance that is shared with a constructor class and my main ofApp.cpp I've tried declaring it in either .h file, with no success so far in having it recognized in both files…

Posts: 1

Participants: 1

Read full topic

Info download tar armv7 9.8

Adding pixel data from two ofxCvFloatImage instances

$
0
0

@elliot wrote:

I am trying to combine two ofxCvFloatImage instances from some optical flow with the ofxOpenCv built in addon.

I have the split the flow into separate images flowX describing the motion of each pixel in the x-axis and flowY describing the motion in the y-axis.

From the documentation in ofxCvColorImage this shows you can add pixel data from one to another:

first += second; // both are ofxCvFloatImage instances

However, I am unable to do this and get and error: "Invalid operands to binary expression ('ofxCvFloatImage' and 'ofxCvFloatImage')"

Any help on adding pixel data from two ofxCvFloatImage instances would be great.
Here is the code I'm working with.

        Mat img1( gray1.getCvImage() );  //Create OpenCV images
        Mat img2( gray2.getCvImage() );
        Mat flow;                        //Image for flow
        calcOpticalFlowFarneback( img1, img2, flow, 0.7, 3, 11, 5, 5, 1.1, 0 );

        //Split flow into separate images
        //describing the motion of each pixel in the x-axis and one describing the motion in the y-axis

        vector<Mat> flowPlanes;

        split( flow, flowPlanes );
        //Copy float planes to ofxCvFloatImage images flowX and flowY
        IplImage iplX( flowPlanes[0] );
        flowX = &iplX;
        IplImage iplY( flowPlanes[1] );
        flowY = &iplY;

        //Need to combine flowX and flowY which are of type ofxCvFloatImage
        //Or convert the flow into one CVimage.

Posts: 2

Participants: 1

Read full topic

Crash on SendMessageTimeout with ofGLFWWindowSettings

$
0
0

@Regi wrote:

Hi,

I'm trying to perform a command in setup
SendMessageTimeout(hwnd, 0x052C, 0, NULL, SMTO_NORMAL, 1000, result);

This works with ofSetupOpenGL(200,200,OF_WINDOW);
but unfortunately crashes if I use the ofGLFWWindowSettings renderer.

Perhaps I'm missing something specific here? I've tried SMTO_BLOCK and the hwnd is found.

Thanks for any help or pointers!

Posts: 1

Participants: 1

Read full topic

Text in an ofFBo is transparent

$
0
0

@jeffrey9700 wrote:

Does anyone know why my text in an fbo is transparent. If I clear it to black and draw the string it seems that everything but the text goes black, but transparent where the string is...

Posts: 2

Participants: 2

Read full topic

Shaded lighting rather than full on/off

$
0
0

@asabanapal wrote:

Hi
this should be straightforward but I can't seem to be able to get a lighting/material combination that has shading (i.e. with angle between mesh normals and light source)
I'm using the programmable renderer (4.3) and have setup a really basic scene with a cube in the center, a camera, a light which rotates around the cube and a basic diffuse material.

As the light rotates around the cube the faces of the cube are either fully lit (100% of the diffuse color) or not lit at all (0% diffuse color) there is no fading in between as you would expect. They just switch on then off.

The following's in my setup, along with setting up the basic positions and parameters of camera, material diffuse color etc:

ofEnableLighting();
ofEnableDepthTest();
ofSetSmoothLighting(true);

The in my update call I'm changing the position of the light:

light.setPosition(ofVec3f(cos(ofGetElapsedTimef()*lightSpeed)*lightRadius, 0, sin(ofGetElapsedTimef()*lightSpeed)*lightRadius))

My draw() call:

camera.begin();
light.enable();
material.begin();
cube.draw();
material.end();
light.disable();
camera.end();

This produces either fully on or off shading on my cube.

Is this to do with per-fragment lighting? I'm sure I've had this working on other OF projects I've worked on but even after stripping it back to the basic elements I can't seem to find the right setting for shading with lights/materials.

Anyone know how to fix this please?

Posts: 1

Participants: 1

Read full topic

ofShader: how to only load fragment shader? (not vertex)

$
0
0

@sinedied wrote:

According to the doc, I need both a fragment and vertex shader to setup an ofShader.
OpenGL should not require both, so is there a way to only load a fragment shader? (having passthrough vertex shaders to make it work is not a solution for me)

Posts: 2

Participants: 2

Read full topic


Best practices for treating MIDI as non-musical data?

$
0
0

@aaa wrote:

Working on a commission, was suggested via the forums here to use MIDI instead of a straight serial connection from the Arduino. This is due to serial's habit of dropping a connection randomly, which is only rectified by restarting the app or implementing a heartbeat system.

In any case, I've got my Leonardo with the MIDIUSB library and it seems to be working. I'm curious if there is a best method to send simple data. All I need my Arduino to do is send a couple bytes depending on how some switches are at any moment. Is it okay to simply use NoteOn, without ever doing a NoteOff? Is there a different method altogether that makes more sense? And I'm asking this in terms of what OpenFrameworks would like to interpret.

Posts: 2

Participants: 1

Read full topic

3d face scanning for interactive installation?

$
0
0

@AndreasRef wrote:

Hi

What would be a good approach to performing 3D scans of peoples faces and mapping the meshes to head models on screens at an interactive installation? It does not need to to be super accurate, and speed + real time is more important than getting a lot of details in the scans.

Should I look into Kinect, RealSense, webcams or something else?

Might be a lot to ask for, but perhaps somebody has done/seen a similar thing at some point?

Best
Andreas

Posts: 5

Participants: 3

Read full topic

Difficulty getting ofTexture into ofxCvImage

$
0
0

@autr wrote:

Hi, I'm pulling my hair out trying to get ofTexture into ofxCvImage (either ofxCvColorImage or ofxCvGrayscaleImage) without unsynchronised output. I've tried permutations of cv::Mat, IplImage, ofImage etc.

It seems the fourth parameter on ofxCvImage seems to be depreciated?

// Setup ...

int w = 640;
int h = 480;
ofxCvGrayscaleImage cvimage;
ofFbo fbo;
ofPixels pixels;
ofImage img;

fbo.allocate(w,h);
pixels.allocate(w,h,1); // I've tried 0 - 4
cvimage.allocate(w, h); // There is no third parameter available?

// Draw ...

img.setFromPixels(pixels);
img.draw(0,0,w,h); // This is fine

fbo.readToPixels(pixels);
cvimage.setFromPixels(pixels);
cvimage.draw(0,0,w,h); // Here the channels are unsynchronised

What am I missing?

Posts: 3

Participants: 2

Read full topic

AutoComplete in qt Creator on Linux

$
0
0

@dasoe wrote:

Hi List,

On openframeworks.cc/setup/qtcreator/ it seems easy to get qt creator to work. I have to admit I had some problems and still have. Most I will be able to sort out myself.
But I utterly failed each time/approach to get auto completion to run for the OF native functions. Tried on different machines, on ubuntu 16.04 and 14.04, qt creator from QTs site as proposed, actual versions from half a year ago and yesterday (qt-opensource-linux-x64-5.6.2.run). Tried with the OF templates as well as with emptyExample as well as with importing a project through qt creator native process. No auto completion for OF functions. For functions of the App itself (ofApp Class) it does work, though.

Other people do seem to have the same problem, but I don't know if all, most or just some. . Only concrete solution I found is to import the generated Projects in qt creator (native process, not OF template). Then to add all pathes to folders containing the OF classes in XX.files and all XX.h files in XX.includes (both of which do not exist before importing the project that way). Seems improbable that all people using auto completion on Linux are doing it like this?

So could you please help me sort this out:

  • Is auto-completion supposed to work out of the box with qt creator on linux or do I have to take manual steps?
  • In case of the latter: can you give me a hint to a smart(er) approach?

If there should still be something to do I am willing to help with providing scripts or stuff - as long as I can help with my limited skills.

Thanks for any hint
oe

Posts: 2

Participants: 2

Read full topic

drawStringAsShapes() different looking to original

$
0
0

@cuinjune wrote:

Hi, I just figured out some font's character can look different when drawing with drawStringAsShapes()
I used sansation.ttf font and as you can see, the 'x' character looks different.
There's an empty area in the cross section when drawing 'x' with drawStringAsShapes()

Is this natural behavior or could this be a bug?
If drawStringAsShapes() is drawing as ofMesh, then could this be related to poly winding order?
I'm curious if the issue can be easily fixed.

Posts: 1

Participants: 1

Read full topic

Animation not showing

$
0
0

@Ha99 wrote:

Hello, I am new to OpenFrameworks. I have converted a processing sketch to OpenFrameworks. There is no errors however, the animation is not showing. Please Help Thanks!

code- header file

pragma once

include "ofMain.h"

class ofApp : public ofBaseApp{

public:
	void setup();
	void update();
	void draw();
void linePlot(int xPos, int yPos);

	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 x;
int y;
float move;
int tol;
float fac;
int lineOpa;
int stroke;



//int xPos; int yPos;
float angle;
float mouseDist;

include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

move= 0.05;
lineOpa= 150;
stroke= 10;
tol= 50;
fac= 0.0125;

ofEnableSmoothing();
ofHideCursor();

}

//--------------------------------------------------------------
void ofApp::update(){

}

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

//void linePlot(int xPos, int yPos);

ofBackground(255);
for (int i = 50; i< (ofGetWidth()-25); i += 25){
    for (int j= 50; j< ofGetHeight()-25; j +=25){
        ofMap(i, 0, 500, 0, 255), ofMap(j, 0, 500, 0, 255);
        linePlot(i,j);
    }

}

   void linePlot(int xPos, int yPos);

}

void ofApp::linePlot(int xPos, int yPos){

ofSetLineWidth(stroke);

ofPushMatrix();

ofTranslate(ofGetWidth()/2, ofGetHeight()/2); //xPos, yPos

angle= atan2(ofGetMouseX() - xPos, ofGetMouseY() - yPos);

mouseDist = ofDist(ofGetMouseX(), ofGetMouseY(), xPos, yPos);

ofRotate(angle - PI, 0, 0, 1);
//ofRotate(angle - PI);

if (ofDist(ofGetMouseX(), ofGetMouseY(), xPos, yPos)){
    ofDrawLine(0, 0, mouseDist, 0);
}
else{
    ofDrawLine(0, 0, tol/ (mouseDist * fac), 0);
}

ofPopMatrix();

}

Posts: 3

Participants: 2

Read full topic

3D models blink

$
0
0

@flik9999 wrote:

Hey so I have a 3D model which I have loaded into my game. However every frame they dissappear and reappear how can I fix this?

CODE:

ofap.h

pragma once

include "ofMain.h"

include "ofxAssimpModelLoader.h"

include "meteor.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);


	ofEasyCam cam;

	//ofxAssimpModelLoader Model1;

	std::vector<meteor> Comets;//comets

};

ofapp.cpp

include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(30);
ofSetVerticalSync(true);
ofEnableDepthTest();

cam.setDistance(120);

//Model1.loadModel("Models/asteroid.3ds", 20);

//Model1.setRotation(0, 90, 1, 0, 0);
//Model1.setRotation(1, 270, 0, 0, 1);
//Model1.setScale(0.1, 0.1, 0.1);

// Model1.setPosition(100, 100, 0);

for (int j = 0; j<Comets.size(); j++)
{
	Comets[j].setup(0, 0, 0, 0, 0 ,0, 0);
}

for (int i = 0; i < 10; i++) {
	meteor tempEnemy;
	tempEnemy.setup(ofRandom(0, 1024), ofRandom(0, 1024), 0, 1, 0, 0, 0);
	Comets.push_back(meteor(tempEnemy));
}

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(255, 0, 0);

cam.begin();


cam.end();

for (int j = 0; j < Comets.size(); j++)
{
	Comets[j].draw();
}

}

//--------------------------------------------------------------
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){

}

meteor.h

pragma once

include "ofxAssimpModelLoader.h"

class meteor
{
public:
meteor();

void setup(int _x, int _y, int _z, int _sx, int _sy, int _sz, int _model);
void draw();
int x;
int y;
int z;
int speedX;
int speedY;
int speedZ;
int model;
ofxAssimpModelLoader Model1;

};

meteor.cpp

include "meteor.h"

meteor::meteor()
{
}

void meteor::setup(int _x, int _y, int _z, int _sx, int _sy, int _sz, int _model) {
x = _x; // assignes x the value of _x which is assigned in setup
y = _y; // assignes y the value of _y which is assigned in setup
z = _z;
speedX = _sx; // assignes speedX the value of _sx which is assigned in setup
speedY = _sy; // assignes speedY the value of _sy which is assigned in setup
model = _model; //Assignes sprite the value of _sprite which is assigned in setup

				//Loads in the asteroid model
Model1.loadModel("Models/asteroid.3ds", 0);
Model1.setScale(0.1, 0.1, 0.1);

}

void meteor::draw() {
Model1.setPosition(x, y, z);
Model1.drawFaces();

x = x + speedX;
y = y + speedY;
z = z + speedZ;

}

Posts: 2

Participants: 2

Read full topic


Float from int divided by int

$
0
0

@ayruos wrote:

I'm trying to dynamically trying to generate a spacing value which depends on the window size and the number of elements in a vector.

This is what I'm doing:

spacing = ofGetWidth()/drawBuffer.size();

I have spacing declared as a float in my header file, but the results I keep getting is a int - how do I get the value of spacing as a float while dividing an int by an int?

Posts: 5

Participants: 2

Read full topic

ofxAssimpModelLoader not compiling

$
0
0

@StyxUdFuty wrote:

I'm trying to use 3d models, so i want a project with ofxAssimpModelLoader.
Unfortunately, the project wont build at all. I tried simply making a new project with the addon, and it won't build even before I touch anything . I get several "unresolved external symbol" errors. I tried adding assimp.lib in the linker options, but then I simply get "cannot open assimp.lib".

Posts: 2

Participants: 1

Read full topic

Multitouch addon for linux

$
0
0

@aletes67 wrote:

Hi Everyone,
I am seeking advice about multitouch addon, to study and / or develop on Linux. What do you recommend? thank you

Posts: 2

Participants: 2

Read full topic

Stretch problem in fullscreen

$
0
0

@nim4n wrote:

Hi
I'm using openframeworks 9.3 on raspbian. I used this config to set fullscreen for my app:
ofSetupOpenGL(1024, 768, OF_FULLSCREEN);

my problem is when I draw a circle It looks like an oval ! I think because of fullscreen openframeworks stretch the objects in my screen. how can I fix this?

Posts: 1

Participants: 1

Read full topic

MouseScrolled event - Win10, oF 0.9.3 doesn't work

$
0
0

@SebastianSobotka wrote:

Is there any example of mouseScrolled event?
I tried to show some messages in this method:

void ofApp::mouseScrolled(int x, int y, float scrollX, float scrollY)

or

void ofApp::mouseScrolled(ofMouseEventArgs &mouse)

And it doesn't work :frowning:

Posts: 1

Participants: 1

Read full topic

Viewing all 4929 articles
Browse latest View live