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

Re : PGL getting started

$
0
0
For Processing 2.0xx there have been many changes, so I don't know. Even the example on the wiki seems to work no longer. So only andres knows.

For Processing 1.5.1 that would be:
  1. import javax.media.opengl.*;
  2. import processing.opengl.*;
  3.  
  4. void setup() {
  5.   size(800, 600, OPENGL);
  6. }
  7.  
  8. void draw() {
  9.   background(0);
  10.  
  11.   PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
  12.   GL gl = pgl.beginGL();
  13.  
  14.   gl.glBegin(GL.GL_POLYGON);
  15.   gl.glColor4f(1, 0, 0, 1);
  16.   gl.glVertex2d(100, 100);
  17.   gl.glColor4f(0, 1, 0, 1);
  18.   gl.glVertex2d(100, 200);
  19.   gl.glColor4f(0, 0, 1, 1);
  20.   gl.glVertex2d(200, 200);
  21.   gl.glEnd();
  22.   gl.glFlush();
  23.  
  24.   pgl.endGL();
  25. }
For full clarity. Of course the same shape could be drawn through the Processing API (but I assume you want to use low-level OpenGL calls for a reason):
  1. import processing.opengl.*;
  2.  
  3. void setup() {
  4.   size(800, 600, OPENGL);
  5. }
  6.  
  7. void draw() {
  8.   background(0);
  9.  
  10.   beginShape();
  11.   fill(255, 0, 0);
  12.   vertex(100, 100);
  13.   fill(0, 255, 0);
  14.   vertex(100, 200);
  15.   fill(0, 0, 255);
  16.   vertex(200, 200);
  17.   endShape();
  18. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles