I've got two models in my openGL. I'm trying to set a line thickness of these models. I tried to do it by glLineWidth but it does not work. How can I set line thickness of this models individually? Is it a good way to adjust the line thickness by glLineWidth or Is there a better way to do so?
Here is my code:
vector<float> vertices1 = {};
vector<float> vertices2;
ShaderProgram sp(BASIC_VERTEX, BASIC_FRAGMENT);
sp.bind();
sp.setUniform4f("color", 1.0f, 1.0f, 1.0f, 1.0f);
VertexBuffer VBO1(vertices1);
//VBO_task1.setAttribute(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), NULL);
VBO1.setAttribute(0, 2, GL_FLOAT, 2 * sizeof(float), 0);
//VBO_task1.bind();
int resolution = 1000;
for (int i = 0; i < resolution; i++)
{
float t = (float(i) / float(resolution)) * (2 * 3.14159);
vertices_task2.push_back((4.0 * cos(t) + cos(4 * t)) / 5.0);
vertices_task2.push_back((4.0 * sin(t) - sin(4 * t)) / 5.0);
}
VertexBuffer VBO2(vertices2);
VBO2.setAttribute(0, 2, GL_FLOAT, 2 * sizeof(float), 0);
VBO2.bind();
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float angle = ((fmod(glfwGetTime(), 5.0f)) / 5.0f) * 360.0;
//sp.setUniform4f("input_color",1, 1, 0, 1);
//glDrawArrays(GL_TRIANGLES, 0, vertices_task1.size() / 6);
glm::mat4 projection(1.f);
glm::mat4 model(1.f);
glm::mat4 view(1.f);
glm::mat4 model1 = glm::mat4(1.0f);
//proj = glm::perspective(glm::radians(90.f), 800.f / 600.f, 1.0f, 10.f);
model = glm::rotate(model, glm::radians(-angle++), glm::vec3(0.0f, 0.0f, 1.0f));
//view = glm::lookAt(glm::vec3(-1.f, 2.f, 1.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f));
//sp.setUniformMatrix4fv("projection", proj);
sp.setUniformMatrix4fv("model", model);
//view = glm::lookAt(glm::vec3(1.f, 2.f, 2.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f));
//view = glm::rotate(view, glm::radians(0.1f), glm::vec3(0.0f, 1.0f, 0.0f));
sp.setUniformMatrix4fv("proj", projection);
sp.setUniformMatrix4fv("model", model);
sp.setUniformMatrix4fv("view", view);
//model = glm::rotate(model, glm::radians(30.f), glm::vec3(0.f, 1.f, 0.f));
// sp.setUniformMatrix4fv("model", model);
VBO1.bind();
sp.setUniform4f("color", 0, 1, 0, 1);
//
//view = glm::rotate(view, glm::radians(angle++), glm::vec3(0.0f, 0.0f, 1.0f));
glDrawArrays(GL_LINE_LOOP, 0, vertices_task1.size() / 2);
VBO_task2.bind();
sp.setUniform4f("color", 0.7, 0.5, 0.9, 1);
//proj = glm::ortho(-2.f, 2.f, -2.f, 2.f);
//sp.setUniformMatrix4fv("proj", proj);
model1 = glm::scale(model1, glm::vec3(0.5f, 0.5f, 0.5f));
model1 = glm::translate(model1, glm::vec3(1.f, 0.f, 0.f));
model1 = glm::rotate(model1, glm::radians(angle++), glm::vec3(0.0f, 0.0f, 1.0f));
sp.setUniformMatrix4fv("model", model1);
glDrawArrays(GL_LINE_LOOP, 0, vertices_task2.size() / 2);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}