Question about OpenGL-Syntax
in
Core Library Questions
•
1 year ago
Hi,
i have a problem with the correct use of OpenGL-Syntax ( glBegin(), glEnd();).
The Sketch is running, but the glRects are not drawing. Its simply a white Space.
At the start of the Sketch Processing prints out an error: OpenGL error 1282 at top endDraw(): invalid operation.
I hope you can help me with the correct OpenGl-Syntax.
i have a problem with the correct use of OpenGL-Syntax ( glBegin(), glEnd();).
The Sketch is running, but the glRects are not drawing. Its simply a white Space.
At the start of the Sketch Processing prints out an error: OpenGL error 1282 at top endDraw(): invalid operation.
I hope you can help me with the correct OpenGl-Syntax.
- import SimpleOpenNI.*;
import processing.opengl.*;
import javax.media.opengl.*;
import processing.video.*;
import ddf.minim.*;
Minim minim;
AudioInput in;
MovieMaker mm;
PImage handtracked;
SimpleOpenNI context;
float soundin ;
float xoff = 0.0;
float zoomF =1.5f;
float rotX = radians(180);
float rotY = radians(0);
boolean handsTrackFlag = false;
PVector handVec = new PVector();
ArrayList handVecList = new ArrayList();
int handVecListSize = 30;
String lastGesture = "";
boolean freeze = false;
int freezetimer = 0;
float alphawert = 0.0;
ArrayList frameVecList = new ArrayList();
ArrayList<Float> abgreifen_x = new ArrayList<Float>();
ArrayList<Float> abgreifen_y = new ArrayList<Float>();
ArrayList<Float> abgreifen_z = new ArrayList<Float>();
//--------------------------------------------------------- SETUP
void setup()
{
background(255);
frameRate(30);
size(640, 480, OPENGL);
hint(DISABLE_OPENGL_2X_SMOOTH);
mm = new MovieMaker(this, width, height, "drawing###.mov", 8, MovieMaker.VIDEO, MovieMaker.HIGH);
context = new SimpleOpenNI(this);
context.enableDepth();
context.enableRGB();
context.alternativeViewPointDepthToImage();
context.enableGesture();
context.enableHands();
context.addGesture("Wave");
context.addGesture("Click");
context.addGesture("RaiseHand");
context.setMirror(true);
if (context.enableDepth() == false)
{
println("Can't open the depthMap, maybe the camera is not connected!");
exit();
return;
}
smooth();
perspective(radians(50),
float(width)/float(height),
10, 150000);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO, 512);
}
//____________________________________________________ DRAW
void draw()
{
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
int sekunde = second();
for (int i = 0; i < in.bufferSize() - 1; i++)
{
soundin = in.left.get(i)*40;
}
background(255);
context.update();
PImage rgbImage = context.rgbImage();
rgbImage.resize(1024, 768);
translate(width/2, height/2, 0);
rotateX(rotX);
rotateY(rotY);
scale(zoomF);
int[] depthMap = context.depthMap();
int steps = 3;
int index;
PVector realWorldPoint;
translate(0, 0, -1000);
PVector[] realWorldMap = context.depthMapRealWorld();
for (int y=0;y < context.depthHeight();y+=steps)
{
for (int x=0;x < context.depthWidth();x+=steps)
{
index = x + y * context.depthWidth();
noFill();
realWorldPoint = realWorldMap[index];
color c = rgbImage.pixels[index];
int helligkeit = int(brightness(c));
if (depthMap[index] > 1000 && depthMap[index] < 2250 )
{
frameVecList.add(realWorldPoint);
//_______________________________________________________IF-Sound-Abfrage für Lines
// if (soundin >= 1) {
// }
if (dist(realWorldPoint.x, realWorldPoint.y, realWorldPoint.z, handVec.x, handVec.y, handVec.z) < 200 ) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(realWorldPoint.x, realWorldPoint.y-10, realWorldPoint.z);
gl.glColor4f(map(helligkeit, 1, 255, 0.0, 1.0)*2, map(helligkeit, 1, 255, 0.0, 1.0)*4, map(helligkeit, 1, 255, 0.0, 1.0)*4, 1.0);
gl.glRectf(0, 0, 3+(map(helligkeit, 1, 255, 1, 2.5)), 20+(map(helligkeit, 1, 255, 1, 2.5)));
gl.glEnd();
}
//_____________________________________________________ Basis-Look + Sound-Effekt
xoff=xoff+0.01;
float n = (noise(xoff) * 250)*soundin;
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(realWorldPoint.x+n/10, realWorldPoint.y+(n/2)/10, realWorldPoint.z);
gl.glColor4f(map(helligkeit, 1, 255, 0.0, 1.0)*2, map(helligkeit, 1, 255, 0.0, 1.0)*2, map(helligkeit, 1, 255, 0.0, 1.0)*2, 1.0);
gl.glRectf(0, 0, 1.5+(map(helligkeit, 1, 255, 1, 4.5))+random(2), 4+(map(helligkeit, 1, 255, 1, 2.5)));
gl.glEnd();
//__________________________________________________ Depth-Random-Effekt
if (depthMap[index] > random(250, 1000)) {
if (depthMap[index] % 4 <= 0) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(realWorldPoint.x, realWorldPoint.y-5, realWorldPoint.z);
gl.glColor4f(map(helligkeit, 1, 255, 0.0, 1.0), map(helligkeit, 1, 255, 0.0, 1.0)*8, map(helligkeit, 1, 255, 0.0, 1.0)*5, 1.0);
gl.glRectf(0, 0, 1.5+(map(helligkeit, 1, 255, 1, 2.5)), 10+(map(helligkeit, 1, 255, 1, 2.5)));
gl.glEnd();
}
}
}
}
}
//______________________________________________________________ Freeze-Effekt
if (frameCount%45==0) {
freeze = true;
for (int i = 0; i <= frameVecList.size()-1; i++) {
PVector f = (PVector) frameVecList.get(i);
abgreifen_x.add(f.x);
abgreifen_y.add(f.y);
abgreifen_z.add(f.z);
}
}
if (freeze == true) {
freezetimer++;
alphawert = alphawert+0.025;
for (int i = abgreifen_x.size()-1; i >= 0; i--) {
stroke(0);
strokeWeight(5);
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(abgreifen_x.get(i)+10, abgreifen_y.get(i)-10, abgreifen_z.get(i)-freezetimer*15);
gl.glColor4f(0.0, 0.8, 0.65, 1.0-alphawert);
gl.glRectf(0, 0, 1.5, 10);
gl.glEnd();
}
if (freezetimer == 3) {
for (int i = abgreifen_x.size()-1; i >= 0; i--) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(abgreifen_x.get(i)-10, abgreifen_y.get(i)+10, abgreifen_z.get(i)-freezetimer*25);
gl.glColor4f(0.0, 0.65, 0.8, 1.0-alphawert);
gl.glRectf(0, 0, 1.5, 10);
gl.glEnd();
}
}
if (freezetimer == 20) {
abgreifen_x.clear();
abgreifen_y.clear();
abgreifen_z.clear();
freezetimer = 0;
alphawert = 0.0;
freeze = false;
}
}
//_______________________________________________________ Background-Rects
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(width), random(height), random(1800, 2250));
gl.glColor4f(0.0, 0.8, 0.65, 1.0-random(0.85, 0.975));
gl.glRectf(0, 0, 10+random(5, 10), 25+random(20, 25));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(-width), random(-height), random(1800, 2250));
gl.glColor4f(0.0, 0.8, 0.65, 1.0-random(0.85, 0.975));
gl.glRectf(0, 0, random(3, 9)+random(5, 10), random(25, 42)+random(20, 35));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(-width), random(height), random(1800, 2250));
gl.glColor4f(0.0, 0.8, 0.65, 1.0-random(0.85, 0.975));
gl.glRectf(0, 0, random(5, 12)+random(5, 10), random(20, 40)+random(20, 27));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(width), random(-height), random(1800, 2250));
gl.glColor4f(0.0, 0.8, 0.65, 1.0-random(0.85, 0.975));
gl.glRectf(0, 0, random(4, 10)+random(5, 10), random(20, 35)+random(10, 15));
gl.glEnd();
}
//__________________________________________________________ Zweite Background-Rect Ebene (schwarz)
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(width), random(height), random(1800, 2250));
gl.glColor4f(0.0, 0.0, 0.0, 1.0-random(0.05, 0.45));
gl.glRectf(0, 0, random(1, 4), random(5, 10));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(-width), random(-height), random(1800, 2250));
gl.glColor4f(0.0, 0.0, 0.0, 1.0-random(0.05, 0.45));
gl.glRectf(0, 0, random(1, 4), random(5, 10));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(-width), random(height), random(1800, 2250));
gl.glColor4f(0.0, 0.0, 0.0, 1.0-random(0.05, 0.45));
gl.glRectf(0, 0, random(2, 4), random(5, 15));
gl.glEnd();
}
for (int i = 0; i <= random(10,50); i++) {
gl.glBegin(gl.GL_LINES);
gl.glTranslatef(random(width), random(-height), random(1800, 2250));
gl.glColor4f(0.0, 0.0, 0.0, 1.0-random(0.05, 0.45));
gl.glRectf(0, 0, random(2, 4), random(5, 10));
gl.glEnd();
}
frameVecList.clear();
mm.addFrame();
pgl.endGL();
}
1