Skip to content

Instantly share code, notes, and snippets.

@jnsdbr
Created January 29, 2016 10:13
Show Gist options
  • Save jnsdbr/9cc56f54ca303e7b5110 to your computer and use it in GitHub Desktop.
Save jnsdbr/9cc56f54ca303e7b5110 to your computer and use it in GitHub Desktop.
ofx DirectionalLight example
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
ofBackground(255);
ofSetSmoothLighting(true);
// Box size
box.set(100);
// Set directional
light.setDirectional();
ofEnableDepthTest();
ofEnableLighting();
// Can be deleted I guess
light.setPosition(ofGetWidth() / 2, ofGetHeight()/2, 500);
// There will be dragons!
light.rotate(180, 1, 0, 0);
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
light.enable();
// Show me teh light!
//light.draw();
// Box color
ofSetColor(255, 0, 0);
ofFill();
// Position, rotation & draw
box.setPosition(ofGetWidth() / 2, ofGetHeight() / 2, 0);
box.rotate(0.1, 1.0, 0.0, 0.0);
box.rotate(0.1, 0.0, 1.0, 0.0);
box.draw();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofBoxPrimitive box;
ofLight light;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment