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

Random sized star

$
0
0

@Nuro wrote:

How would I get started making the size of this star (taken from the documentation) random?

//Draws a star
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
ofVertex(400,135);
ofVertex(215,135);
ofVertex(365,25);
ofVertex(305,200);
ofVertex(250,25);
ofEndShape();

Posts: 3

Participants: 2

Read full topic


ofRotate() question

$
0
0

@cuinjune wrote:

Hi, I don't understand why ofRotate(45, 0, 0, 0); rotates the object around the x-axis.
Here's my test code.

void ofApp::draw(){

    ofSetColor(ofColor::red);
    ofTranslate(100, 100);
    ofRotate(45, 0, 0, 0);
    ofDrawRectangle(0, 0, 100, 100);
}

And this is the result I get.

Shouldn't it not rotate at all since x,y,z is all set to 0?
It seems there's no difference even if I change the value of 'x' to 1.

Is this a bug? I'm using OF 0.9.8 on Mac OSX.
Thanks in advance!

Posts: 2

Participants: 2

Read full topic

Can the same install of OF be used for Desktop and Android?

$
0
0

@hamoid wrote:

Hi! So far I have built Desktop apps, but I would like to target Android too. I followed https://github.com/openframeworks/openFrameworks/blob/master/docs/android_studio.md without much luck.

I run
./projectGenerator -o"/home/funpro/src/openFrameworks" -a"" -p"linuxarmv6l,linuxarmv7l" "/home/funpro/src/openFrameworks/examples/android/androidEmptyExample"

which produces an empty .qbs file, a config.make, and a Makefile. If I load the project folder into Android Studio, no files are displayed.

Also, Android Studio did not ask for the NDK location, nor the option was visible inside the Project Settings window.

I then tried creating a new Android Studio project with C++, which triggered the downloading of NDK 15 and later of cmake (weird, because I already had cmake in my system). This new project successfully runs on a device.

Should I have two different copies of OF, one for Desktop and one for Android?

Posts: 4

Participants: 2

Read full topic

4Universe artnet control using ofxArtnet

$
0
0

@kangttto wrote:

Good morning
I am trying to control the led using 4universe artnet.
Addon is https://github.com/hiroyuki/ofxArtnet
Is in use.

the problem is

I manually set up artnet's ip on the Mac's network
You have specified "192.168.1.8".

By the way
The interface of 4universe artnet is confirmed on OF
Artnet.senddmx ("192.168.1.8")
Not found.

Can you solve the problem?
Here is the code I used:

pragma once

include "ofMain.h"

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

ofxArtnet anNode;

unsigned char dmxData [512];

ofColor color;

};

include "ofApp.h"

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

ofSetWindowShape( 800, 800);
ofSetFrameRate(60);
ofSetBackgroundAuto(true);
ofBackground(0 ,0 , 0);

color.set(0,0,0);

anNode.setup("192.168.1.8", 0x0 , 0    );

for(int i = 0; i<512 ; i ++){
    dmxData[i] = 0;
}

}

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

float r = ofMap(ofGetMouseX(), 0 , ofGetWidth() , 0 , 255);
float g = ofMap(ofGetMouseY(), 0 , ofGetWidth(), 0 , 255);
float b = 100;

color.set(r,g,b);

for(int i = 0; i<512; i+=1){
    dmxData[i] = r;
    dmxData[i+1] = g;
    dmxData[i+2] = b;



}
anNode.sendDmx("192.168.1.8", 0 , 0);

}

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

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
anNode.sendDmx("192.168.1.8" , dmxData , 512);
cout<<"DMX Message Sent"<<endl;
cout<<""<<endl;

}

Posts: 1

Participants: 1

Read full topic

Framerate vs drawing speed

$
0
0

@robotPatrol wrote:

is there a way to control the speed at which the screen draws that is not related to the framerate at which a program runs or related to refreshing the screen by resetting the background?
for instance, you have a static framerate of 24, but you want to draw at a slower rate for a specified duration of time.

thanks,
01

Posts: 3

Participants: 2

Read full topic

CLI graphical application

$
0
0

@Antharia_Jack wrote:

Hi there!

I would like to create kind of a simple graphical application with a command line interface, inspired by this.

Do you know how can i integrate a 'prompt' inside a OF application?

Thanks.

Posts: 1

Participants: 1

Read full topic

Comparing ofTexture, ofPixels, ofImage on iOS: how to get pixels from texture?

$
0
0

@Autofasurer wrote:

Hi all,

I keep on bumping into a problem when wanting to compare two images: 1 loaded into ofImage, the other being part of the screen; let's see if I can make it clear what I want to do:

  1. load a reference image into ofImage (ok)
  2. draw a number of polygons on the screen (ok)
  3. create a bounding box around all the polygons (ok)
  4. allocate an ofTexture the size of the bounding box (ok)
  5. loadScreenData of what's inside the bounding box into the texture (ok)
  6. scale that texture to the width and height of the ofImage (???)
  7. compare the images: in theory I know how, but:

If I want to compare the loaded image with the texture, I need to iterate through the pixels if I understood correctly so I need to get the texture into an instance of ofPixels.

This is supposed to run on an iPad, and ofTexture's documentation says:
readToPixels(...)
Read current texture data from the GPU into pixels.
Warning: This is not supported in OpenGL ES and does nothing

Am I going about this the wrong way? If so, how would one best go about to do this?

Posts: 1

Participants: 1

Read full topic

High resolution setting on Linux?

$
0
0

@cuinjune wrote:

Hi, I could successfully port my Mac OF app to Ubuntu today.
But it didn't look as good as it was in Mac. For example, when I draw a circle on Ubuntu I could clearly notice aliasing which I couldn't notice on Mac.

On Mac OSX, I could improve the resolution by enabling "High Resolution Capable".
I wonder if there's any similar setting like this on Ubuntu.

Thank you in advance!

Posts: 1

Participants: 1

Read full topic


How to write $HOME path in make file?

$
0
0

@cuinjune wrote:

Hi, I'm trying to add include path in config.make for my Linux app.

It works when I write full path like

PROJECT_CFLAGS = -I/home/cuinjune/myLib/src

But I wonder if I can replace "/home/cuinjune" which is the $HOME folder.

I tried replacing it with "$HOME" or "~/" but both didn't work.
I want to fix this so I can compile it on other Linux computers as well.

Thanks in advance!

Posts: 2

Participants: 1

Read full topic

Confused about window types

$
0
0

@clem wrote:

Is it necessary to include GLFWWindow in main.cpp or is that the default?
When should I choose one window type over another?

Posts: 2

Participants: 2

Read full topic

Sampling two textures at random fails for point sprites

$
0
0

@ilmenite wrote:

I'm trying to render two different textures, say, a star and a snowflake, to random points (point spites, where gl_PointSize is 20 - set in my vertex shader).

What I expect is simple: I have two points, A and B. Using some form of randomness, I want point A to be rendered as a star, and point B to be a snowflake.

As I understand, there's a variable called gl_PrimitiveID, which is provided to the fragment shader per primitive (in my case, a point). It would be different for every point. I should be able to use something as simple as a mod operation to decide which texture to use. Furthermore, I understand that the fragment shader is called multiple times per vertex, however, ideally each call to the fragment shader will have the same gl_PrimitiveID for one point sprite.

However, what renders on the screen is a square, instead of either of the textures. However, if I use just one texture, it works very well.

Here's how I'm binding the two textures:

    int locTex0 = shader.getUniformLocation("tex0");
    int locTex1 = shader.getUniformLocation("tex1");
    textures[0].bind(locTex0);
    textures[1].bind(locTex1);
    vboMesh.draw(ofPolyRenderMode::OF_MESH_POINTS);
    textures[0].unbind();
    textures[1].unbind();

In my fragment shader:

#version 400
uniform sampler2D tex0;
uniform sampler2D tex1;

out vec4 fragColour;

void main() {
    // Neon
    float r = 0.145, g =0.764, b=0.988;

    if (mod(gl_PrimitiveID, 2) == 0) {
        vec4 textureColour = texture(tex0, gl_PointCoord);
        fragColour = vec4(r, g, b, textureColour.a);
    } else {
        vec4 textureColour = texture(tex1, gl_PointCoord);
        fragColour = vec4(r, g, b, textureColour.a);
    }
}

If I use the same texture in both the conditional blocks (either tex0 or tex1), then the appropriate texture is rendered.

I'm unable to get it to render two different textures.

Any idea what I'm missing?

Posts: 1

Participants: 1

Read full topic

Update children of ofNode

$
0
0

@vollstock wrote:

Is ofNode only meant for 3D manipulation?
If I want to build a hierarchy of objects that will need an update method, how do I call it?
From what I see, ofNodes children are stored in a private std::set with no public acces methods to it.
If ofNode doesn't call the update and draw methods od its’ children, will I need to write additional code that does that?
That seems like whole separate structure organizing the scene hierarchy.

I'm a little confused :-/

Posts: 2

Participants: 1

Read full topic

Difference between OF_MATRIX_PROJECTION and GL_PROJECTION?

$
0
0

@clem wrote:

What's the difference between these?

ofMatrixMode(OF_MATRIX_PROJECTION);

and

ofMatrixMode(GL_PROJECTION);

and

glMatrixMode(GL_PROJECTION);

Posts: 2

Participants: 2

Read full topic

Setting indices to VBO: Can't seem to make it work

$
0
0

@ayruos wrote:

Hi!

So I'm trying to make a simple square using two GL_TRIANGLES using four vertices and can't seem to make it work. This is what I'm ending up with:

Code:
.h

ofVbo vbo;
ofShader shader;

.cpp

void ofApp::draw(){

    ofVec3f v0(0.5f,  0.5f, 0.0f);
    ofVec3f v1(0.5f, -0.5f, 0.0f);
    ofVec3f v2(-0.5f, -0.5f, 0.0f);
    ofVec3f v3( -0.5f,  0.5f, 0.0f);

    vector<ofVec3f> vertices;

    vertices.push_back(v0);
    vertices.push_back(v1);
    vertices.push_back(v2);
    vertices.push_back(v3);

    for(int i = 0; i<vertices.size(); i++){
        vertices[i].x *= ofGetWidth()/2;
        vertices[i].y *= ofGetHeight()/2;
    }

    const ofIndexType indices[] = {2, 3, 1, 0, 1, 2};

    vbo.setVertexData(&vertices[0], int(vertices.size()), GL_STATIC_DRAW);
    vbo.setIndexData(&indices[0], 6, GL_STATIC_DRAW);

    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

    shader.begin();
    vbo.draw(GL_TRIANGLES, 0, 6);
    shader.end();

    ofPopMatrix();
}

What am I doing wrong?

Posts: 12

Participants: 3

Read full topic

ofVideoPlayer when looping - performance loss

$
0
0

@dimitre wrote:

Hello I've recently noticed ofVideoPlayer slows down a bit when reaches the end of duration and start playing again.
I suppose it is maybe loading the videofile again, but not sure.
Any ideas on this or workarounds?
ofw 0.9.8 and OS X 10.11 / 10.12 here.

Posts: 1

Participants: 1

Read full topic


Kinect implementation

$
0
0

@Louisa wrote:

Hi all. I managed to connect XBox Kinect ONE to OF, and now looking for libraries and working examples that can achieve something like this:

or

Has anyone done anything similar? I don't mind learning and trying, but need a small help on which libraries/resources can start with that will definitely lead to a similar result. I have a powerful computer, so hardware is not an issue. So far I spent time trying various working examples, but either cannot compile them, or they do just very basic things that don't look like they can lead to the nice interactive project.

Any suggestions much appreciated!

Posts: 2

Participants: 2

Read full topic

Recursively add vertices to polyline?

$
0
0

@oseph wrote:

Hi everyone!

I'm working on a function that fills out a poly line with points. It compares PointA and PointB in a polyline, and if the distance between the two points is greater than X, adds a new PointC at the halfway point. Then, it recursively checks the distance of PointA and PointC, and PointC and PointB and so forth. My function "half-works" in a small test case. Code is below.

(Also, I'm trying to maintain index order in polyline so points are walkable, so PointA is index[0], new pointC is [1] and PointB is [2].)

void fillPolyline(ofPolyline &line, ofVec3f a, ofVec3f b) {
	if (a.distance(b) < 25) {
		return;
	} else {
		//std::cout << "Distance is "<< a.distance(b) << std::endl;
		ofVec3f middlePoint = a.getMiddle(b);
		int index = line.getIndexAtLength(a.distance(b));
		line.insertVertex(middlePoint, index);
		fillPolyline(line, a, middlePoint);
		fillPolyline(line, middlePoint, b);
	}
}

Test case -- let's make a test line with three points:

ofPolyline testLine;
testLine.begin();
testLine.addVertex(ofVec3f(100, 100));
testLine.addVertex(ofVec3f(400, 100));
testLine.addVertex(ofVec3f(400, 400));
testLine.end();

Calling the function once works:

fillPolyline(testLine, testLine.getVertices()[0], testLine.getVertices()[1]);

Calling the function twice in a row results in the first two points being filled:

fillPolyline(testLine, testLine.getVertices()[0], testLine.getVertices()[1]);
fillPolyline(testLine, testLine.getVertices()[1], testLine.getVertices()[2]);

And a for loop crashes :frowning:

for (int i = 0; i < testLine.size()-1; i++) {
	fillPolyline(testLine, testLine.getVertices()[i], testLine.getVertices()[i+1]);
}

Ugh, my noob recursion brain.

Maybe I'm approaching this wrong or making this unnecessarily tough ... is there a function/library that can fill an existing polyline with evenly-ish spaced points?

Thanks for your help :heart:

Posts: 1

Participants: 1

Read full topic

Resetting ofApp while program is still running

$
0
0

@robotPatrol wrote:

hi,

it may be a false memory, but i remember somewhere (maybe from processing?) that it is not good practice to call setup() from within a program. i have multiple interfaces that can be used and i want my program to reset to its original at run-time state if a new interface is chosen. may i do:

if(interfaceIschanged == true) ofApp::setup();

?

thanks in advance.
01

Posts: 1

Participants: 1

Read full topic

ofVideoPlayer setFrame question

$
0
0

@jlyjn wrote:

howdy,

i'm having some trouble with setFrame. in one instance it works fine but in another it does not-
the video jumps to the frame but then does not continue playing.

what am i doing wrong?

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

if (x ==2){
video2.load("2.mp4");

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

if (x == 2){

            video2.load("2.mp4");
            video2.play();

			video2.update();

}

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

if (x == 2){

video2.draw(0,0,5400,1920);

//working
if (video2.getCurrentFrame() == 200){

        video2.setFrame(450);
        video2.play();

		}

//not working
if( j == 10){
video2.setFrame(450);
video2.play();
}
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

switch (key) {
    case 'a':
        x = 1;
		break;

    case 'b':
        x = 2;
        break;

    case 'j':
        j = 10;
        break;
}

}

Posts: 1

Participants: 1

Read full topic

ofxGeoJSON problem parsing json files

$
0
0

@marcorexo wrote:

Openframeworks has an ofxGeoJSON addon for importing and rendering json files. However, I can't get the addon to visualise files other than the one in the addon directory.

I have a json file that I would like visualised and have checked its format using an online format corrector ( https://jsonformatter.curiousconcept.com ) which will format json into the compact version. Running the file in Openframeworks using ofxGeoJSON creates the message:

'parsingSuccessful to parse JSON
[notice ] index: 0 null

[notice ] Succeed to load geojson..'

But the map is not rendered. I'm not sure what 'index: 0 null' means. Is this a json file format issue? Thanks for your assistance.

Regards

Posts: 1

Participants: 1

Read full topic

Viewing all 4929 articles
Browse latest View live