smooth line with openGL
in
Core Library Questions
•
1 years ago
Hey everyone,
Using an ipad and the mrmr interface protocol, I'm trying to build a sort of drawing machine. Without openGL, everything works perfect and the line is smooth and nice. (see 1st screen)
But, as this will be played on a very large screen, I have to use openGL, otherwise will be very laggy.
As soon as I use openGL, the line becomes very strange (see 2nd screen). It's like the line would be made of rectangles.
When the line is very this, it wont go in diagonal, but just moves on the x axis and then on the y and on the x again and so on.
The strokeJoin and strokeCap function doesn't work with openGL, and I tryed to change my drawing method, use points, ellipse, vertex...! Nothing works
Has anyone a idea?
Thanks a lot!
Gaëlle
///
Here is my code, I don't know if it will be really helpfull as I use it with an ipad
- import fhnw.matrixrenderer.*;
- import fullscreen.*;
- import processing.opengl.*;
- import oscP5.*;
- import netP5.*;
- // the instance of our matrix renderer
- MatrixRenderer render;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- float lastX, lastY;
- //int weight;
- int mySwitch = 0;
- int x ;
- int y ;
- int z;
- int previousZ;
- int starttime;
- int delaytime = 2000; // delay in miliseconds
- boolean timer = false;
- boolean hover = false;
- int counter = 0;
- boolean touched = false;
- boolean xNew = false;
- boolean yNew = false;
- boolean clear = false;
- void init()
- {
- // generate MatrixRenderer
- render = new MatrixRenderer (this, 2*1920, 1*1080, 1);
- render.doInit();
- super.init();
- }
- void setup()
- {
- render.doSetup();
- // size( render.getActualWidth(), render.getActualHeight() );
- // frameRate(60);
- render.showGrid(false);
- // size (1000, 400);
- smooth();
- background(0);
- strokeWeight(z);
- stroke(255);
- frameRate(60);
- /* start oscP5, listening for incoming messages at port 12000 */
- oscP5 = new OscP5(this, 12000);
- myRemoteLocation = new NetAddress("192.168.0.2", 31337);
- clearStroke();
- }
- void draw()
- {
- render.beforeDraw();
- // do your drawing stuff just here, it is OPENGL by the way
- // background(random(255));
- if (clear == true) {
- clear = false;
- background(0);
- }
- // only draw if at least one x/y pair has been received, otherwise, strange first line
- if (xNew == true && yNew == true && counter > 6) {
- if (touched == true) {
- lastX = x;
- lastY = y;
- touched = false;
- }
- line(lastX, lastY, x, y);
- strokeWeight(z/20);
- z = abs(z);
- xNew = yNew = false;
- }
- lastX = x;
- lastY = y;
- // println(frameRate);
- render.afterDraw();
- }
- ////// OSC SETUP
- void oscEvent(OscMessage theOscMessage) {
- if (theOscMessage.checkAddrPattern("/mrmr/tactile3DY/0/manor"))
- {
- // println(theOscMessage.get(0).intValue());
- x = theOscMessage.get(0).intValue();
- x = (int) map(x, 0, 1000, render.getActualWidth() * 2, 0);
- // x=floor(map(theOscMessage.get(0).intValue(), 0, screen.height, 2000, -500));
- xNew = true;
- counter++;
- }
- if (theOscMessage.checkAddrPattern("/mrmr/tactile3DX/0/manor"))
- {
- // println(theOscMessage.get(0).intValue());
- y=theOscMessage.get(0).intValue();
- y = (int) map(y, 0, 1000, 0, render.getActualHeight() * 2);
- // y=floor(map(theOscMessage.get(0).intValue(), 0, screen.width, 0, screen.height));
- yNew = true;
- counter++;
- }
- if (theOscMessage.checkAddrPattern("/mrmr/tactile3DZ/0/manor"))
- {
- int tmp = theOscMessage.get(0).intValue();
- if ( tmp != previousZ) {
- z = tmp;
- }
- // println(theOscMessage.get(0).intValue());
- }
- if (theOscMessage.checkAddrPattern("/mrmr/tactilezoneTouchDown/0/manor"))
- {
- lastX = x;
- lastY = y;
- // println("touched");
- touched = true;
- }
- /// SAVEFRAME
- if (theOscMessage.checkAddrPattern("/mrmr/pushbutton/1/manor"))
- {
- println("saved");
- saveFrame();
- }
- /// CLEAR THE BACKGROUND
- if (theOscMessage.checkAddrPattern("/mrmr/pushbutton/2/manor"))
- {
- println("clear button is pushed");
- clear = true;
- clearStroke();
- }
- /// WHITE STROKE
- if (theOscMessage.checkAddrPattern("/mrmr/pushbutton/3/manor"))
- {
- println("draw with a white stroke");
- stroke(255);
- }
- /// BLACK STROKE
- if (theOscMessage.checkAddrPattern("/mrmr/pushbutton/4/manor"))
- {
- println("draw with a black stroke");
- stroke(0);
- }
- // println(theOscMessage.addrPattern());
- }
- void clearStroke() {
- previousZ = z;
- z = 1;
- }
1