Opengl display model and triangle mesh wireframe at the same time

Opengl display model and triangle mesh wireframe at the same time

glPolygonMode function and related parameters

glPolygonMode(参数1, 参数2);
Parameter 1 can be: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
Parameter 2 can be: GL_LINE (note the distinction between GL_LINES), GL_FILL
The effect is as follows:
for the 3D triangular mesh model
First use glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);the obtained mesh model as follows:
insert image description here
use glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);the obtained mesh model As follows:
insert image description here

Simultaneous display of model and triangulated wireframe

Specific steps are as follows:

  1. First draw the triangle mesh in the way of patch filling
  2. Then draw the triangle mesh in wireframe

insert image description here
Implementation code:

//渲染循环的代码如下:
  		 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);//填充面
        ourModel[2].Draw(ourShader);
       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);//将绘制模式改为线
        glEnable(GL_POLYGON_OFFSET_POINT);//开启多边形偏移
        glPolygonOffset(-1.0, -1.0);//设置偏移量,一般-1,1即可
        ourModel[2].Draw(ourShader);
        glDisable(GL_POLYGON_OFFSET_POINT);//关闭多边形偏移

Guess you like

Origin blog.csdn.net/weixin_44478077/article/details/124991397