hekeus@0: #include "testApp.h" hekeus@0: hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::setup(){ hekeus@0: counter = 0; hekeus@0: ofSetCircleResolution(50); hekeus@0: ofBackground(255,255,255); hekeus@0: bSmooth = false; hekeus@0: ofSetWindowTitle("graphics example"); hekeus@0: hekeus@0: ofSetFrameRate(60); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps. hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::update(){ hekeus@0: counter = counter + 0.033f; hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::draw(){ hekeus@0: hekeus@0: //--------------------------- circles hekeus@0: //let's draw a circle: hekeus@0: ofSetColor(255,130,0); hekeus@0: float radius = 50 + 10 * sin(counter); hekeus@0: ofFill(); // draw "filled shapes" hekeus@0: ofCircle(100,400,radius); hekeus@0: hekeus@0: // now just an outline hekeus@0: ofNoFill(); hekeus@0: ofSetColor(0xCCCCCC); hekeus@0: ofCircle(100,400,80); hekeus@0: hekeus@0: // use the bitMap type hekeus@0: // note, this can be slow on some graphics cards hekeus@0: // because it is using glDrawPixels which varies in hekeus@0: // speed from system to system. try using ofTrueTypeFont hekeus@0: // if this bitMap type slows you down. hekeus@0: ofSetColor(0x000000); hekeus@0: ofDrawBitmapString("circle", 75,500); hekeus@0: hekeus@0: hekeus@0: //--------------------------- rectangles hekeus@0: ofFill(); hekeus@0: for (int i = 0; i < 200; i++){ hekeus@0: ofSetColor((int)ofRandom(0,255),(int)ofRandom(0,255),(int)ofRandom(0,255)); hekeus@0: ofRect(ofRandom(250,350),ofRandom(350,450),ofRandom(10,20),ofRandom(10,20)); hekeus@0: } hekeus@0: ofSetColor(0x000000); hekeus@0: ofDrawBitmapString("rectangles", 275,500); hekeus@0: hekeus@0: //--------------------------- transparency hekeus@0: ofSetColor(0x00FF33); hekeus@0: ofRect(400,350,100,100); hekeus@0: // alpha is usually turned off - for speed puposes. let's turn it on! hekeus@0: ofEnableAlphaBlending(); hekeus@0: ofSetColor(255,0,0,127); // red, 50% transparent hekeus@0: ofRect(450,430,100,33); hekeus@0: ofSetColor(255,0,0,(int)(counter * 10.0f) % 255); // red, variable transparent hekeus@0: ofRect(450,370,100,33); hekeus@0: ofDisableAlphaBlending(); hekeus@0: hekeus@0: ofSetColor(0x000000); hekeus@0: ofDrawBitmapString("transparency", 410,500); hekeus@0: hekeus@0: //--------------------------- lines hekeus@0: // a bunch of red lines, make them smooth if the flag is set hekeus@0: hekeus@0: if (bSmooth){ hekeus@0: ofEnableSmoothing(); hekeus@0: } hekeus@0: hekeus@0: ofSetColor(0xFF0000); hekeus@0: for (int i = 0; i < 20; i++){ hekeus@0: ofLine(600,300 + (i*5),800, 250 + (i*10)); hekeus@0: } hekeus@0: hekeus@0: if (bSmooth){ hekeus@0: ofDisableSmoothing(); hekeus@0: } hekeus@0: hekeus@0: ofSetColor(0x000000); hekeus@0: ofDrawBitmapString("lines\npress 's' to toggle smoothness", 600,500); hekeus@0: hekeus@0: } hekeus@0: hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::keyPressed (int key){ hekeus@0: if (key == 's'){ hekeus@0: bSmooth = !bSmooth; hekeus@0: } hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::keyReleased (int key){ hekeus@0: hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::mouseMoved(int x, int y ){ hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::mouseDragged(int x, int y, int button){ hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::mousePressed(int x, int y, int button){ hekeus@0: } hekeus@0: hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::mouseReleased(int x, int y, int button){ hekeus@0: hekeus@0: } hekeus@0: hekeus@0: //-------------------------------------------------------------- hekeus@0: void testApp::windowResized(int w, int h){ hekeus@0: hekeus@0: }