Drawing a line problem

Why does the following code not work. Want to draw a simple line when the mouse is pressed and dragged.

void ofApp::mouseDragged(int x, int y, int button){
button = OF_MOUSE_BUTTON_LEFT;
if (button)
{
ofSetColor(255);
ofDrawLine(x,y, ofGetPreviousMouseX(), ofGetPreviousMouseY());
}

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
button = OF_MOUSE_BUTTON_LEFT;
if (button)
{
ofSetColor(255);
ofDrawLine(x, y, ofGetPreviousMouseX(), ofGetPreviousMouseY());
}
}

you don’t have anything that’s set in the draw which would show things on screen.
so you should have something in draw that takes what you input in the mouse that would then draw something on screen

here is a handy tutorial that can help & hopefully explain. there is a newer ones to come soon :wink:

also a good pointer for posting code is using ``` at the start & end of the code. you can use a single one such as this `draw` for single word/line things.
it just makes it easier to read in the end :wink:

Hi Lewis, thanks for your reply!!

I’ve edited the code and am drawing in the Void draw area. I am simply not able to store the polyline. It keeps adding vertices to the initial polyline. How to end a polyline? polyline.end() doesnt seem to work. I want to draw fresh polylines everytime i release the mouse but want the previous polyline to remain on screen.

polyline.clear() on the mouse pressed