First OpenGL program

import processing.opengl.*;
import javax.media.opengl.*; 
 
void setup()
{
   size(600, 600, OPENGL); 
 
}
 
void draw()
{
   background(255);
   strokeWeight(5);
 
    // camera control
  beginCamera();
  if (keyPressed)
  {
    if (key == 'w')
      translate(0, 0, -1);
    if (key == 's')
      translate(0, 0, 1);
    if (key == 'a')
      translate(-1, 0, 0);
    if (key == 'd')
      translate(1, 0, 0);
 
 
  }
  if (mousePressed)
  {
    // pitch
    rotateX((PI/16)*float(mouseY-pmouseY)/300);
    // yaw
    rotateY(-(PI/16)*float(mouseX-pmouseX)/300);
  }
  endCamera();
 
 
 
  PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  // g may change
  GL gl = pgl.beginGL();  // always use the GL object returned by beginGL
 
  gl.glColor3f(1, 0, 0);
 
  gl.glBegin(GL.GL_TRIANGLES);
  gl.glVertex2i(400, 200);
  gl.glVertex2i(300, 400);
  gl.glVertex2i(500, 400);
  gl.glEnd();
 
  pgl.endGL();
 
}
PDF Creator    Send article as PDF to