openGL ES cube

hi

in the hope it will save anyone else the time figuring this stuff out

& if anyone who does know what they doing would like to comment please feel free

Mark

  
#include "glCubeApp.h"  
#include "ofxMSAShape3D.h"  
  
  
ofxMSAShape3D myFront;  
ofxMSAShape3D myRight;  
ofxMSAShape3D myLeft;  
ofxMSAShape3D myBack;  
ofxMSAShape3D myTop;  
ofxMSAShape3D myBottom;  
  
  
#define USE_DEPTH_BUFFER 1  
  
  
void glCubeApp::setup(){  
	  
	  
	//this is to scale down the example for the iphone screen  
	appIphoneScale = 1.0;  
	  
	ofBackground(255,255,255);	  
	ofSetFrameRate(60);  
	  
	  
	xOffset = 0;  
	yOffset = 0;  
	  
	  
	glEnable(GL_DEPTH_TEST);  
	  
	  
	// six sides of cube  
	  
	myFront.begin(GL_TRIANGLE_FAN);  
	myFront.setColor(1, 0, 0);	// red  
	myFront.addVertex(0, 100, 100);  
	myFront.addVertex(100, 100, 100);  
	myFront.addVertex(100, 0, 100);  
	myFront.addVertex(0, 0, 100);  
	myFront.end();  
	  
	  
	myRight.begin(GL_TRIANGLE_FAN);	  
	myRight.setColor(0,1, 0);	// green  
	myRight.addVertex(0, 0, 0);  
	myRight.addVertex(0, 100, 0);  
	myRight.addVertex(0, 100, 100);  
	myRight.addVertex(0, 0, 100);	  
	myRight.end();  
	  
	  
	myLeft.begin(GL_TRIANGLE_FAN);	  
	myLeft.setColor(1,0, 1);  
	myLeft.addVertex(100, 0, 0);  
	myLeft.addVertex(100, 0, 100);  
	myLeft.addVertex(100, 100, 100);  
	myLeft.addVertex(100, 100, 0);  
	myLeft.end();  
	  
	  
	myTop.begin(GL_TRIANGLE_FAN);  
	myTop.setColor(0,1,1);  
	myTop.addVertex(0, 0, 0);  
	myTop.addVertex(0, 0, 100);  
	myTop.addVertex(100, 0, 100);  
	myTop.addVertex(100, 0, 0);	  
	myTop.end();  
	  
	  
	myBottom.begin(GL_TRIANGLE_FAN);  
	myBottom.setColor(1,1,0);  
	myBottom.addVertex(100, 100, 100);  
	myBottom.addVertex(0, 100, 100);  
	myBottom.addVertex(0, 100, 0);  
	myBottom.addVertex(100, 100, 0);  
	myBottom.end();  
	  
	  
	myBack.begin(GL_TRIANGLE_FAN);	  
	myBack.setColor(0, 0, 1);	// blue	  
	myBack.addVertex(0, 0, 0);  
	myBack.addVertex(100, 0, 0);  
	myBack.addVertex(100, 100, 0);  
	myBack.addVertex(0, 100, 0);  
	myBack.end();  
	  
	  
	// end cube  
	  
}  
  
  
void glCubeApp::update(){ }  
  
  
void glCubeApp::draw() {  
	  
	ofScale(appIphoneScale, appIphoneScale, 1.0);  
	  
	xOffset = 110;  
	yOffset = 150;  
	  
	  
	glPushMatrix();  
	  
	  
	glTranslatef(xOffset, yOffset, 0);  
	  
	  
	glRotatef(rquad, 1, 1, 1);  // rotates everything  
	  
	  
	// these draw a cube  
	// ------------------------------------------------------------------------  
	myFront.draw();  
	myRight.draw();  
	myLeft.draw();	  
	myTop.draw();  
	myBottom.draw();  
	myBack.draw();  
	  
	  
	// or like thus  
	//myCube();  
	  
	  
	glPopMatrix();  
	  
	  
	rquad += 0.2f;	  
	  
}  
  
// draws a cube  
// ----------------------------------------------------------------------------  
void glCubeApp::myCube() {  
	myFront.draw();  
	myRight.draw();  
	myLeft.draw();	  
	myTop.draw();  
	myBottom.draw();  
	myBack.draw();  
}