Skip to content

Instantly share code, notes, and snippets.

@elliotwoods
Created June 10, 2014 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotwoods/a66163a9fa3f0d8db838 to your computer and use it in GitHub Desktop.
Save elliotwoods/a66163a9fa3f0d8db838 to your computer and use it in GitHub Desktop.
#include "ofApp.h"
#include "ofAppGLFWWindow.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
ofBackground(0);
auto result = ofSystemLoadDialog("Select mesh bin");
if (!result.bSuccess) {
ofSystemAlertDialog("Quitting");
ofExit();
}
ifstream load(ofToDataPath(result.filePath).c_str(), ios::binary);
if (!load.is_open()) {
ofLogError() << "failed to load file " << result.fileName;
return;
}
auto numVertices = (uint32_t) this->mesh.getNumVertices();
load.read((char *) & numVertices, sizeof(numVertices));
this->mesh.getVertices().resize(numVertices);
load.read((char *) this->mesh.getVerticesPointer(), sizeof(ofVec3f) * numVertices);
auto numTexCoords = (uint32_t) this->mesh.getNumTexCoords();
load.read((char *) & numTexCoords, sizeof(numTexCoords));
this->mesh.getTexCoords().resize(numTexCoords);
load.read((char *) this->mesh.getTexCoordsPointer(), sizeof(ofVec2f) * numTexCoords);
auto numColors = (uint32_t) this->mesh.getNumColors();
load.read((char *) & numColors, sizeof(numColors));
this->mesh.getColors().resize(numColors);
load.read((char *) this->mesh.getColorsPointer(), sizeof(ofColor) * numColors);
load.close();
this->image.allocate(1280, 800, OF_IMAGE_COLOR_ALPHA);
this->image.getPixelsRef().set(0.0f);
auto & pixels = this->image.getPixelsRef();
for(int i=0; i<numVertices; i++) {
auto & vertexPosition = this->mesh.getVerticesPointer()[i];
auto & projectorCoordinate = this->mesh.getTexCoordsPointer()[i];
auto & outputVertex = (ofVec4f &) pixels[projectorCoordinate.x, projectorCoordinate.y];
outputVertex = vertexPosition * 255.0f;
outputVertex.w = 1.0f;
cout << projectorCoordinate << endl;
}
this->image.update();
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
this->image.draw(0, 0);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == 'f') {
ofToggleFullscreen();
}
}
//--------------------------------------------------------------
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::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment