<p>I'm learning OpenGL for a personal project. I need to draw a triangle mesh as a wireframe. From what I've read, I can do this using glPolygonMode. However, the program always draws my polygons filled. Is is a bad driver? I'm using the linux subsystem on a chromebook. It's basically debian in a container. How do I get an wireframe triangle?</p>
<p>Here is my program, with all the windowing functions and the shader compilation pulled into their own .cpp file.</p>
<pre><code>#include &lt;glad/glad.h&gt;
#include &lt;GLFW/glfw3.h&gt;
#include &lt;glm/glm.hpp&gt;
#include &lt;iostream&gt;
#include &quot;ah_graphics.h&quot;
#include &quot;ah_window.h&quot;

const char *vertexShaderSource();

const char *fragmentShaderSource();


// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float positions[] = {
        -1.0f, 1.0f, 0.0f, // left
        -1.0f, 0.0f, 0.0f, // right
        0.0f, 1.0f, 0.0f // top
};


int main() {
    GLFWwindow *window = ahCreateWindow(800, 600);
    ahLoadGlFunctionPointers();
    GLuint program = ahCreateGlProgram(vertexShaderSource(), fragmentShaderSource());
    unsigned int VBO_pos, VAO;
    glGenVertexArrays(1, &amp;VAO);
    glBindVertexArray(VAO);
    glGenBuffers(1, &amp;VBO_pos);
    glBindBuffer(GL_ARRAY_BUFFER, VBO_pos);
    glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
    int numComponents = 3; // (x,y,z) and (r,g,b)
    std::size_t stride = numComponents * sizeof(float);
    glVertexAttribPointer(0, numComponents, GL_FLOAT, GL_FALSE, stride, (void *) 0);
    glEnableVertexAttribArray(0);

    while (!glfwWindowShouldClose(window)) {
        // input
        ahProcessInput(window);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glUseProgram(program);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    return 0;
}

const char *vertexShaderSource() {
    return &quot;#version 330 core\n&quot;
           &quot;layout (location = 0) in vec3 aPos;\n&quot;
           &quot;void main()\n&quot;
           &quot;{\n&quot;
           &quot;  gl_Position = vec4(aPos, 1.0);\n&quot;
           &quot;}\0&quot;;
}

const char *fragmentShaderSource() {
    return &quot;#version 330 core\n&quot;
           &quot;void main()\n&quot;
           &quot;{\n&quot;
           &quot; gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n&quot;
           &quot;}\n\0&quot;;
}
</code></pre>
<p>And this is the scene it renders:
<a href="https://i.sstatic.net/u4YIk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/u4YIk.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-01-25T13:34:03.303Z
I don't know the "ah" library, but please take a look at the shader compiling and linking section. Maybe there comes an error... in that case OpenGL can act very strange... 
The code you posted looks good, so I don't see the problem there
Thomas
CC BY-SA 4.0
2022-01-25T13:36:03.233Z
What you can do is to use the "GLenum glGetError(void);" function to check for errors
Thomas
CC BY-SA 4.0
2022-01-25T18:35:41.187Z
polygon mode is an OpenGL state, so once it is set it stays set until something else changes it. It would typically be set outside the main loop and/or changed by a something like a key press in the process keys function.  Also, setting it after glUseProgram could have strange effects (but begs the question since this is a loop) I recommend moving the set polygon mode out of the main loop. Or at the very least put it before glUseProgram.
pmw1234
CC BY-SA 4.0
2022-01-28T10:40:37.800Z
How about drawing lines instead as a workaround?
Panda Pajama
<opengl>
OpenGL ignores glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
ahoffer
# OpenGL ignores glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

(Asked by: username_0 on 2022-01-18)

I'm learning OpenGL for a personal project. I need to draw a triangle mesh as a wireframe. From what I've read, I can do this using glPolygonMode. However, the program always draws my polygons filled. Is is a bad driver? I'm using the linux subsystem on a chromebook. It's basically debian in a container. How do I get an wireframe triangle?

Here is my program, with all the windowing functions and the shader compilation pulled into their own .cpp file.

```
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <iostream>
#include "ah_graphics.h"
#include "ah_window.h"

const char *vertexShaderSource();

const char *fragmentShaderSource();

// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float positions[] = {
        -1.0f, 1.0f, 0.0f, // left
        -1.0f, 0.0f, 0.0f, // right
        0.0f, 1.0f, 0.0f // top
};

int main() {
    GLFWwindow *window = ahCreateWindow(800, 600);
    ahLoadGlFunctionPointers();
    GLuint program = ahCreateGlProgram(vertexShaderSource(), fragmentShaderSource());
    unsigned int VBO_pos, VAO;
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
    glGenBuffers(1, &VBO_pos);
    glBindBuffer(GL_ARRAY_BUFFER, VBO_pos);
    glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
    int numComponents = 3; // (x,y,z) and (r,g,b)
    std::size_t stride = numComponents * sizeof(float);
    glVertexAttribPointer(0, numComponents, GL_FLOAT, GL_FALSE, stride, (void *) 0);
    glEnableVertexAttribArray(0);

    while (!glfwWindowShouldClose(window)) {
        // input
        ahProcessInput(window);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glUseProgram(program);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    return 0;
}

const char *vertexShaderSource() {
    return "#version 330 core\n"
           "layout (location = 0) in vec3 aPos;\n"
           "void main()\n"
           "{\n"
           "  gl_Position = vec4(aPos, 1.0);\n"
           "}\0";
}

const char *fragmentShaderSource() {
    return "#version 330 core\n"
           "void main()\n"
           "{\n"
           " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
           "}\n\0";
}

```

And this is the scene it renders:
[![enter image description here](https://i.sstatic.net/u4YIk.png)](https://i.sstatic.net/u4YIk.png)

**Tags:** opengl

> **Comments:**
> **username_1**: I don't know the "ah" library, but please take a look at the shader compiling and linking section. Maybe there comes an error... in that case OpenGL can act very strange...  The code you posted looks good, so I don't see the problem there  
> **username_1**: What you can do is to use the "GLenum glGetError(void);" function to check for errors  
> **username_2**: polygon mode is an OpenGL state, so once it is set it stays set until something else changes it. It would typically be set outside the main loop and/or changed by a something like a key press in the process keys function.  Also, setting it after glUseProgram could have strange effects (but begs the question since this is a loop) I recommend moving the set polygon mode out of the main loop. Or at the very least put it before glUseProgram.  
> **username_3**: How about drawing lines instead as a workaround?  

---

## 0 answers

