Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Forked from kylemcdonald/lineart.h
Created October 5, 2012 19:14
Show Gist options
  • Save atduskgreg/3841784 to your computer and use it in GitHub Desktop.
Save atduskgreg/3841784 to your computer and use it in GitHub Desktop.
lineart rendering for openFrameworks
#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