Created
November 4, 2011 08:44
-
-
Save kylemcdonald/1338941 to your computer and use it in GitHub Desktop.
lineart rendering for openFrameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
void drawModel(ofMesh& mesh) { | |
glEnableClientState(GL_VERTEX_ARRAY); | |
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &mesh.getVerticesPointer()->x); | |
glEnableClientState(GL_NORMAL_ARRAY); | |
glNormalPointer(GL_FLOAT, sizeof(ofVec3f), &mesh.getNormalsPointer()->x); | |
if(mesh.getNumIndices()){ | |
glDrawElements(ofGetGLPrimitiveMode(mesh.getMode()), mesh.getNumIndices(), GL_UNSIGNED_INT, mesh.getIndexPointer()); | |
}else{ | |
glDrawArrays(ofGetGLPrimitiveMode(mesh.getMode()), 0, mesh.getNumVertices()); | |
} | |
glDisableClientState(GL_NORMAL_ARRAY); | |
} | |
void drawLineArt(ofMesh& mesh, float weight = 3, ofColor fill = ofColor(255), ofColor stroke = ofColor(0)) { | |
glPushAttrib(GL_ALL_ATTRIB_BITS); | |
glEnable(GL_DEPTH_TEST); | |
glEnable(GL_CULL_FACE); | |
glPolygonMode(GL_FRONT,GL_FILL); | |
glDepthFunc(GL_LESS); | |
glCullFace(GL_BACK); | |
ofSetColor(fill); | |
drawModel(mesh); | |
glLineWidth(weight); | |
glPolygonMode(GL_BACK,GL_LINE); | |
glDepthFunc(GL_LEQUAL); | |
glCullFace(GL_FRONT); | |
ofSetColor(stroke); | |
drawModel(mesh); | |
glPopAttrib(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment