Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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