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 fragSource C style string with NULL termination
*/
ShaderProgram::ShaderProgram(Base base, string vertexSource,
string fragSource) {
ShaderProgram::ShaderProgram(Base base, string vertexSource, string fragSource,
bool wireframe /* = false */) {
int success;
char infoLog[512];
const char *vertexSource_c = vertexSource.c_str();
const char *fragSource_c = fragSource.c_str();
this->base = base;
this->wireframe = wireframe;
BOOST_LOG_TRIVIAL(info) << "With base program \"" << this->baseName() << "\"";
// NOTE: char arrays and char pointers are not actually the same.
// 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.
glBindVertexArray(0);
// uncomment this call to draw in wireframe polygons.
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (this->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) {
// input
// -----
@ -168,7 +170,8 @@ int ShaderProgram::run(GLFWwindow *window) {
// draw our first triangle
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
// keep things a bit more organized
glDrawArrays(GL_TRIANGLES, 0, 3);
@ -235,8 +238,9 @@ int ShaderProgram::run(GLFWwindow *window) {
// VBOs) when it's not directly necessary.
glBindVertexArray(0);
// uncomment this call to draw in wireframe polygons.
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (this->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) {
// input
// -----
@ -277,6 +281,9 @@ int ShaderProgram::run(GLFWwindow *window) {
{
// use the compiled shader
glUseProgram(this->program);
if (this->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
while (!glfwWindowShouldClose(window)) {
processInput(window);

View File

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

View File

@ -18,7 +18,8 @@ int main(int argc, char **argv) {
po::options_description desc("Available options");
desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")(
"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");
/* unused for now */
@ -82,11 +83,11 @@ int main(int argc, char **argv) {
string buf;
string vert;
string frag;
while(!fvert.eof()) {
while (!fvert.eof()) {
getline(fvert, buf);
vert.append(buf + "\n");
}
while(!ffrag.eof()) {
while (!ffrag.eof()) {
getline(ffrag, buf);
frag.append(buf + "\n");
}
@ -104,7 +105,7 @@ int main(int argc, char **argv) {
BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram";
// 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 */
BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow";
@ -117,7 +118,8 @@ int main(int argc, char **argv) {
void help(char *prog, po::options_description desc) {
cout << "Usage:" << endl
<< 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
<< "return values:" << endl
@ -132,6 +134,7 @@ void help(char *prog, po::options_description desc) {
<< "base programs:" << endl
<< "Empty\t\t-\tEmpty window with colored background" << endl
<< "Triangle\t-\tA static Triangle" << endl
<< "Polygons\t-\tA small amount of polygons" << endl
<< endl
<< endl
<< desc << endl;