Objectives

Setup

Setting up full build environment on ubuntu:

sudo apt-get update
sudo aptitude install build-essential
sudo apt-get install git-core
sudo apt-get install subversion
sudo apt-get install scons
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev

Lab01 js

function renderScene()
{
  Gl.clear( Gl.COLOR_BUFFER_BIT);

  Gl.color3f(1.0, 0.0, 0.0);

  Gl.rectf(-25.0, 25.0, 25.0, -25.0);

  Gl.flush();
}

function setupRC()
{
  Gl.clearColor(0, 0, 1, 1);

  Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}

function main()
{
  Glut.init();
  Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);

  Glut.createWindow("Lab 01 js");
  setupRC();
  Glut.displayFunc(renderScene);

  Glut.mainLoop();
}

main();

Lab03 js

function renderScene()
{
  Gl.clear( Gl.COLOR_BUFFER_BIT);

  Gl.color3f(1.0, 0.0, 0.0);

  Gl.rectf(-25.0, 25.0, 25.0, -25.0);

  Gl.flush();
}

function setupRC()
{
  Gl.clearColor(0, 0, 1, 1);

  Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}

function changeSize(w, h)
{
  Gl.viewport(0,0, w, h);

  Gl.matrixMode( Gl.PROJECTION);
  Gl.loadIdentity();

  var aspectRatio =   w / h;

  if (w <= h)
  {
    Glu.ortho2D(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio);
   }
  else
  {
    Glu.ortho2D(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0);
  }

  Gl.matrixMode(Gl.MODELVIEW);
  Gl.loadIdentity();

}
function main()
{
  Glut.init();
  Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);

  Glut.createWindow("Lab 03 js");
  setupRC();
  Glut.displayFunc(renderScene);
  Glut.reshapeFunc(changeSize);

  Glut.mainLoop();
}

main();

Lab04 js

var windowWidth;
var windowHeight;

var x = -25;
var y =  25;


function renderScene()
{
  Gl.clear( Gl.COLOR_BUFFER_BIT);

  Gl.color3f(1.0, 0.0, 0.0);

  Gl.rectf(x, y, x+50, y-50);

  Gl.flush();
}

function setupRC()
{
  Gl.clearColor(0, 0, 1, 1);

  Glu.ortho2D(-100.0, 100.0, -100, 100.0);
}

function changeSize(w, h)
{
  Gl.viewport(0,0, w, h);

  Gl.matrixMode( Gl.PROJECTION);
  Gl.loadIdentity();

  var aspectRatio =   w / h;

  if (w <= h)
  {
    windowWidth = 100;
    windowHeight = 100 / aspectRatio;
    Glu.ortho2D(-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
  }
  else
  {
    windowWidth = 100 * aspectRatio;
    windowHeight = 100;
    Glu.ortho2D(-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
  }

  Gl.matrixMode(Gl.MODELVIEW);
  Gl.loadIdentity();
}

var xstep = 1;
var ystep = 1;

function update()
{
  if (x > windowWidth - 50 || x < -windowWidth)
    xstep = -xstep;

  if (y > windowHeight || y < -windowHeight + 50)
    ystep = -ystep;

  x += xstep;
  y += ystep;
}

function timerFunction(value)
{
  update();
  Glut.postRedisplay();
  Glut.timerFunc(25, timerFunction, 1);
}

var lastTime = 0;

function idleFunction()
{
  var currentTime = new Date();
  //print(currentTime.getUTCMilliseconds());

  if (lastTime == 0)
    lastTime = currentTime.getMilliseconds();

  var currTime = currentTime.getMilliseconds();
  var deltaTime = currTime - lastTime;
//  print(deltaTime);
  if (deltaTime  > 100)
  {
    update();
    lastTime = currTime;
    Glut.postRedisplay();
  }

}
function main()
{
  Glut.init();
  Glut.initDisplayMode(Glut.SINGLE | Glut.RGB);

  Glut.createWindow("Lab 04 js");
  setupRC();
  Glut.displayFunc(renderScene);
  Glut.reshapeFunc(changeSize);

  //Glut.timerFunc(33, timerFunction, 1);
  Glut.idleFunc(idleFunction);
  Glut.mainLoop();
}

main();

Exercises

  void print (char * s)
  {
   pringf (s);
  }