Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

frameRate() can crash 2.0b7

$
0
0
If you use advanced OpenGL, frameRate can crash the sketch.  Wanted to post here before I submit a bug report.  Maybe it's something simple I'm not doing.  I put the frameRate change on the keyEvent.
  1. import javax.media.opengl.GL2;
  2.  
  3. float a;
  4. GL2 gl;
  5. PGraphicsOpenGL pgl;
  6. float[] projMatrix;
  7. float[] mvMatrix;
  8.  
  9. void setup() {
  10.   size(800, 600, OPENGL);
  11.   pgl = (PGraphicsOpenGL) g;  // g may change
  12.   gl = pgl.beginPGL().gl.getGL2();
  13.   projMatrix = new float[16];
  14.   mvMatrix = new float[16];
  15. }
  16.  
  17. void draw() {
  18.  
  19. background(255);
  20.  
  21.   pgl.beginPGL();
  22.  
  23.   gl.glColor4f(0.7, 0.7, 0.7, 0.8);
  24.   gl.glTranslatef(width/2, height/2, 0);
  25.   gl.glRotatef(a, 1, 0, 0);
  26.   gl.glRotatef(a*2, 0, 1, 0);
  27.   gl.glRectf(-200, -200, 200, 200);
  28.   gl.glRotatef(90, 1, 0, 0);
  29.   gl.glRectf(-200, -200, 200, 200);
  30.  
  31.   pgl.endPGL();
  32.   loadMatrix();
  33.   a += 0.5;
  34. }
  35.  
  36. void loadMatrix() {
  37.  
  38.   gl.glMatrixMode(GL2.GL_PROJECTION);
  39.   projMatrix[0] = pgl.projection.m00;
  40.   projMatrix[1] = pgl.projection.m10;
  41.   projMatrix[2] = pgl.projection.m20;
  42.   projMatrix[3] = pgl.projection.m30;
  43.  
  44.   projMatrix[4] = pgl.projection.m01;
  45.   projMatrix[5] = pgl.projection.m11;
  46.   projMatrix[6] = pgl.projection.m21;
  47.   projMatrix[7] = pgl.projection.m31;
  48.  
  49.   projMatrix[8] = pgl.projection.m02;
  50.   projMatrix[9] = pgl.projection.m12;
  51.   projMatrix[10] = pgl.projection.m22;
  52.   projMatrix[11] = pgl.projection.m32;
  53.  
  54.   projMatrix[12] = pgl.projection.m03;
  55.   projMatrix[13] = pgl.projection.m13;
  56.   projMatrix[14] = pgl.projection.m23;
  57.   projMatrix[15] = pgl.projection.m33;
  58.  
  59.   gl.glLoadMatrixf(projMatrix, 0);
  60.  
  61.   gl.glMatrixMode(GL2.GL_MODELVIEW);
  62.   mvMatrix[0] = pgl.modelview.m00;
  63.   mvMatrix[1] = pgl.modelview.m10;
  64.   mvMatrix[2] = pgl.modelview.m20;
  65.   mvMatrix[3] = pgl.modelview.m30;
  66.  
  67.   mvMatrix[4] = pgl.modelview.m01;
  68.   mvMatrix[5] = pgl.modelview.m11;
  69.   mvMatrix[6] = pgl.modelview.m21;
  70.   mvMatrix[7] = pgl.modelview.m31;
  71.  
  72.   mvMatrix[8] = pgl.modelview.m02;
  73.   mvMatrix[9] = pgl.modelview.m12;
  74.   mvMatrix[10] = pgl.modelview.m22;
  75.   mvMatrix[11] = pgl.modelview.m32;
  76.  
  77.   mvMatrix[12] = pgl.modelview.m03;
  78.   mvMatrix[13] = pgl.modelview.m13;
  79.   mvMatrix[14] = pgl.modelview.m23;
  80.   mvMatrix[15] = pgl.modelview.m33;
  81.   gl.glLoadMatrixf(mvMatrix, 0);
  82. }
  83. void keyPressed() {
  84.   frameRate(2000);
  85. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles