Java Using OpenGL Stencil to create Outline

风流意气都作罢 提交于 2019-12-10 20:02:52

问题


I'm trying to render an outline of an object over the top of it but I'm having some difficulties. I'm not too good with OpenGL so most of it was from following tutorials. The desired effect is supposed to be something like this:

But this is the outcome at the moment:

The code I'm using to do this is:

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();

And doRender is the method already there to render the player. Anything on this would be helpful.

来源:https://stackoverflow.com/questions/28008213/java-using-opengl-stencil-to-create-outline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!