我试图在它顶部渲染一个物体轮廓,但我遇到了一些困难。我对OpenGL不太好,所以大部分内容来自以下教程。期望的效果应该是这样的:
但这是目前的结果:
我用来执行此操作的代码是:
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glClearStencil(0);
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
GL11.glEnable(GL11.GL_STENCIL_TEST);
GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFFFF);
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL11.glColor3f(0.0f, 0.0f, 0.0f);
// Render original.
this.doRender((AbstractClientPlayer) par1Entity, par2, par4, par6, par8, par9);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, 0xFFFF);
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
GL11.glLineWidth(3.0f );
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glColor4f(1.0F, 0, 0, 0.5F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
// Render stencil.
this.doRender((AbstractClientPlayer) par1Entity, par2, par4, par6, par8, par9);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1.0F, 1, 1, 1F);
GL11.glPopAttrib();
而doRender
是已经存在渲染玩家的方法。
对此有所帮助。