How to stop faces from covering vertices when drawing faces and it's vertices at the same time?

Started by
6 comments, last by taby 3 years, 7 months ago

I want to draw some faces together with it's vertices by changing draw type from GL_TRIANGLES to GL_POINTS, but the faces will cover up the vertices because the vertices lay on these faces,disable depth test isn't a solution because I want faces cover up vertices if they are behind the faces.how to achieve this, thanks.

Advertisement

Sounds like you might need glPolygonOffset?

This page looks great: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php

Sorry late to reply,because I am struggling to make glPolygonOffset to work,I believe this function is what I need,but cannot make it to work,here is my rendering code

glUseProgram(m_pShader->m_nProgram);

glBindTexture(GL_TEXTURE_2D, g_nTex);

glBindVertexArray(g_pWinEffect->m_pCurEffect->m_nVao);

glUniform1i(m_pShader->m_nPosDrawingPoint, false);

glDrawElements(GL_TRIANGLES, g_pWinEffect->m_pCurEffect->m_nNumFace * 3, GL_UNSIGNED_SHORT, 0);

glUniform1i(m_pShader->m_nPosDrawingPoint, true);

glEnable(GL_POLYGON_OFFSET_POINT);

//glPolygonOffset(0.0f, 0.1f);

//glPolygonOffset(-0.1f, 0.2f);

glPolygonOffset(-1.f, -1.f);

glPointSize(2.f);

glDrawArrays(GL_POINTS, 0, g_pWinEffect->m_pCurEffect->m_nNumVert);

glPolygonOffset(0.0f, 0.0f);

glDisable(GL_POLYGON_OFFSET_POINT);

I have tried all the parameters,none worked.

As shown in the image,some vertices are still covered up.

Though I don't know why,but this code works,thanks a lot taby.

glEnable(GL_POLYGON_OFFSET_FILL);

glPolygonOffset(0.f, 1.f);

glDrawElements(GL_TRIANGLES, g_pWinEffect->m_pCurEffect->m_nNumFace * 3, GL_UNSIGNED_SHORT, 0);

glDisable(GL_POLYGON_OFFSET_FILL);

glPointSize(2.f);

glDrawArrays(GL_POINTS, 0, g_pWinEffect->m_pCurEffect->m_nNumVert);

Good deal.

Check out: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml

P.S. I took your advice. I could disable depth testing in my app, so that is what I did. Plus I enabled anti-aliasing. ?

This topic is closed to new replies.

Advertisement