wireframe

This commit is contained in:
Christoph J. Scherr 2023-10-24 10:01:10 +02:00
parent c804b558b3
commit bac3e7dc9b
3 changed files with 30 additions and 18 deletions

View File

@ -55,13 +55,14 @@ string ShaderProgram::baseName() {
* @param vertexSource C style string with NULL termination * @param vertexSource C style string with NULL termination
* @param fragSource C style string with NULL termination * @param fragSource C style string with NULL termination
*/ */
ShaderProgram::ShaderProgram(Base base, string vertexSource, ShaderProgram::ShaderProgram(Base base, string vertexSource, string fragSource,
string fragSource) { bool wireframe /* = false */) {
int success; int success;
char infoLog[512]; char infoLog[512];
const char *vertexSource_c = vertexSource.c_str(); const char *vertexSource_c = vertexSource.c_str();
const char *fragSource_c = fragSource.c_str(); const char *fragSource_c = fragSource.c_str();
this->base = base; this->base = base;
this->wireframe = wireframe;
BOOST_LOG_TRIVIAL(info) << "With base program \"" << this->baseName() << "\""; BOOST_LOG_TRIVIAL(info) << "With base program \"" << this->baseName() << "\"";
// NOTE: char arrays and char pointers are not actually the same. // NOTE: char arrays and char pointers are not actually the same.
// glShaderSource requires a char[] as it appears. We pass the // glShaderSource requires a char[] as it appears. We pass the
@ -154,8 +155,9 @@ int ShaderProgram::run(GLFWwindow *window) {
// VBOs) when it's not directly necessary. // VBOs) when it's not directly necessary.
glBindVertexArray(0); glBindVertexArray(0);
// uncomment this call to draw in wireframe polygons. if (this->wireframe) {
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
// input // input
// ----- // -----
@ -168,7 +170,8 @@ int ShaderProgram::run(GLFWwindow *window) {
// draw our first triangle // draw our first triangle
glUseProgram(this->program); glUseProgram(this->program);
glBindVertexArray(VAOTriangle); // seeing as we only have a single VAO there's no glBindVertexArray(
VAOTriangle); // seeing as we only have a single VAO there's no
// need to bind it every time, but we'll do so to // need to bind it every time, but we'll do so to
// keep things a bit more organized // keep things a bit more organized
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
@ -235,8 +238,9 @@ int ShaderProgram::run(GLFWwindow *window) {
// VBOs) when it's not directly necessary. // VBOs) when it's not directly necessary.
glBindVertexArray(0); glBindVertexArray(0);
// uncomment this call to draw in wireframe polygons. if (this->wireframe) {
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
// input // input
// ----- // -----
@ -277,6 +281,9 @@ int ShaderProgram::run(GLFWwindow *window) {
{ {
// use the compiled shader // use the compiled shader
glUseProgram(this->program); glUseProgram(this->program);
if (this->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
processInput(window); processInput(window);

View File

@ -10,16 +10,18 @@ public:
enum Base { Empty, Triangle, Polygons }; enum Base { Empty, Triangle, Polygons };
std::string baseName(); std::string baseName();
static Base baseFromName(std::string name); static Base baseFromName(std::string name);
ShaderProgram(Base base, std::string vertexSource, std::string fragSource); ShaderProgram(Base base, std::string vertexSource, std::string fragSource,
int run(GLFWwindow* window); bool wireframe = false);
int run(GLFWwindow *window);
protected: protected:
unsigned int vertex; unsigned int vertex;
bool wireframe;
unsigned int frag; unsigned int frag;
Base base; Base base;
unsigned int program; unsigned int program;
}; };
int mainWindow(ShaderProgram* shaderProgramm, GLFWwindow* window); int mainWindow(ShaderProgram *shaderProgramm, GLFWwindow *window);
GLFWwindow* initGl(); GLFWwindow *initGl();
void processInput(GLFWwindow *window); void processInput(GLFWwindow *window);
#endif #endif

View File

@ -18,7 +18,8 @@ int main(int argc, char **argv) {
po::options_description desc("Available options"); po::options_description desc("Available options");
desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")( desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")(
"vert", po::value<string>()->required(), "vertex shader file")( "vert", po::value<string>()->required(), "vertex shader file")(
"frag", po::value<string>()->required(), "fragment shader file")( "frag", po::value<string>()->required(),
"fragment shader file")("wire,w", "activate wireframe mode")(
"base,b", po::value<string>()->required(), "base program"); "base,b", po::value<string>()->required(), "base program");
/* unused for now */ /* unused for now */
@ -82,11 +83,11 @@ int main(int argc, char **argv) {
string buf; string buf;
string vert; string vert;
string frag; string frag;
while(!fvert.eof()) { while (!fvert.eof()) {
getline(fvert, buf); getline(fvert, buf);
vert.append(buf + "\n"); vert.append(buf + "\n");
} }
while(!ffrag.eof()) { while (!ffrag.eof()) {
getline(ffrag, buf); getline(ffrag, buf);
frag.append(buf + "\n"); frag.append(buf + "\n");
} }
@ -104,7 +105,7 @@ int main(int argc, char **argv) {
BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram"; BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram";
// TODO: determinde ShaderProgram::Base with a CLI arg // TODO: determinde ShaderProgram::Base with a CLI arg
ShaderProgram shaderProgram(base, vert, frag); ShaderProgram shaderProgram(base, vert, frag, !vm["wire"].empty());
/* Run our main program */ /* Run our main program */
BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow"; BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow";
@ -117,7 +118,8 @@ int main(int argc, char **argv) {
void help(char *prog, po::options_description desc) { void help(char *prog, po::options_description desc) {
cout << "Usage:" << endl cout << "Usage:" << endl
<< prog << prog
<< " [-vh] [--vert] shaders/vertex.glsl [--frag] shaders/fragment.glsl" << " [-vwh] \\\n\t--vert shaders/vertex.glsl \\\n\t--frag "
"shaders/fragment.glsl \\\n\t--base BASE_PROGRAM"
<< endl << endl
<< endl << endl
<< "return values:" << endl << "return values:" << endl
@ -132,6 +134,7 @@ void help(char *prog, po::options_description desc) {
<< "base programs:" << endl << "base programs:" << endl
<< "Empty\t\t-\tEmpty window with colored background" << endl << "Empty\t\t-\tEmpty window with colored background" << endl
<< "Triangle\t-\tA static Triangle" << endl << "Triangle\t-\tA static Triangle" << endl
<< "Polygons\t-\tA small amount of polygons" << endl
<< endl << endl
<< endl << endl
<< desc << endl; << desc << endl;