Изменение отображения точек и линий в opengl 4x

Ранее для точек в opengl 2.1 я использовал следующие методы:

  • glPointSize(size) - изменение размера отображения для точек;
  • glEnable(GL_SMOOTH) - изменение формы отображения для точек;

Для линий:

  • glLineWidth(width) - толщина для отрисовки линий;

  • glLineStipple(1, 0x3333); glEnable(GL_LINE_STIPPLE) - для отображения прирывистой линии;

    void Mesh::Draw() {
     unsigned int diffuseNr = 1;
     unsigned int specularNr = 1;
     unsigned int normalNr   = 1;
     unsigned int heightNr   = 1;
    
     for(unsigned int i = 0; i < textures.size(); i++) {
         QString number;
         QString name = textures[i]->type;
         if(name == "texture_diffuse")
             number = QString::number(diffuseNr++);
         else if(name == "texture_specular")
             number = QString::number(specularNr++);
         else if(name == "texture_normal")
             number = QString::number(normalNr++);
         else if(name == "texture_height")
             number = QString::number(heightNr++);
         ShaderProgram->setUniformValue((name + number).toStdString().c_str(), i);
         textures[i]->texture.bind(i);
     }
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
     VAO.bind();
    
     ShaderProgram->setUniformValue("PointColor", QColor(0, 0, 0, 0).toHsl());
     glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
    }
    
    void Mesh::DrawEdge(QColor &color, GLfloat width, GLuint type) {
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
     VAO.bind();
    
     ShaderProgram->setUniformValue("PointColor", color.toHsl());
     glLineWidth((GLfloat)40.0f);
     glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
    }
    
    void Mesh::DrawVertex(QColor &color, GLfloat size, GLuint type) {
     glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
     glEnable(GL_PROGRAM_POINT_SIZE);
    
     VAO.bind();
    
     ShaderProgram->setUniformValue("PointColor", color.toHsl());
     ShaderProgram->setUniformValue("PointSize", size);
     glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
    }
    

Вопрос в следующем, каким образом я могу получить подобный результат в opengl 4.1, методы выше не работают. Для отрисовки моделей использую шейдер, в котором отображаю модель с текстурами.

#version 410 core
out vec4 FragColor;

in vec2 TexCoords;

uniform sampler2D texture_diffuse1;

void main()
{
    FragColor = texture(texture_diffuse1, TexCoords);
}


#version 410 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;

out vec2 TexCoords;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

uniform float PointSize;

void main()
{
    TexCoords = aTexCoords;
    gl_Position = projection * view * model * vec4(aPos, 1.0);
    gl_PointSize = PointSize;
}

Необходимо реализовать отображение граней и точек поверх модели с текстурами. Большое желание реализовать в будующем, что когда мышью выбираю модель отображался её каркас

Я так понимаю что мне придётся писать шейдер где для точки я буду отрисовывать сферу, а для линии параллепипед?


#version 410

uniform float   THICKNESS;      // the thickness of the line in pixels
uniform vec2    resolution;     // the size of the viewport in pixels

layout( triangles ) in;
layout( triangle_strip, max_vertices = 4 ) out;

in vec2 gTexCoords[];

out vec2 TexCoords;


vec2 toScreenSpace( vec4 vertex ) {
  return vec2( vertex.xy / vertex.w ) * resolution;
}

void main( void ) {
  // get the two vertices passed to the shader:
  vec2 p0 = toScreenSpace(gl_in[0].gl_Position);
  vec2 p1 = toScreenSpace(gl_in[1].gl_Position);

  // perform naive culling
  vec2 area = resolution * 1.2;
  if( p1.x < -area.x || p1.x > area.x ) return;
  if( p1.y < -area.y || p1.y > area.y ) return;

  // determine the direction of the segment
  vec2 v = normalize( p1 - p0 );

  // determine the normal of the segment
  vec2 n = vec2( -v.y, v.x );

  // generate the triangle strip
  TexCoords = gTexCoords[0];
  gl_Position = vec4( ( p0 - n * THICKNESS ) / resolution, 0.0, 1.0 );
  EmitVertex();

  TexCoords = gTexCoords[0];
  gl_Position = vec4( ( p0 + n * THICKNESS ) / resolution, 0.0, 1.0 );
  EmitVertex();

  TexCoords = gTexCoords[0];
  gl_Position = vec4( ( p1 - n * THICKNESS ) / resolution, 0.0, 1.0 );
  EmitVertex();

  TexCoords = gTexCoords[0];
  gl_Position = vec4( ( p1 + n * THICKNESS ) / resolution, 0.0, 1.0 );
  EmitVertex();

  EndPrimitive();
}

Как преобразовать следующий код для того чтобы закрасить получившиеся треугольники, имея следующие параметры:

введите сюда описание изображения


Ответы (0 шт):