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";
}