PDA

View Full Version : Polygon offset



Don Gazon
04-09-2003, 02:16 AM
I'm tying to use polygon offset.
I'm using gl4java and what I do is:
- draw a GL_LINE_LOOP (the outline of the polygon)
- draw a GL_POLYGON
But even with offset enabled, the outline is still shown wrong
This is my code:

gl.glPolygonOffset(1.0f, 2.0f); // (this is in my init() code

gl.glEnable(GL_POLYGON_OFFSET_FILL);

gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glBegin(GL_LINE_LOOP);
gl.glVertex3f(-h/2, -b/2, 0.f);
gl.glVertex3f(h/2, -b/2, 0.f);
.glVertex3f(h/2, b/2, 0.f);
gl.glVertex3f(-h/2, b/2, 0.f);
gl.glEnd();

gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
gl.glMatrixMode( GL_TEXTURE );
gl.glLoadIdentity();
gl.glBegin(GL_POLYGON);
gl.glTexCoord2f(0.f, 0.f); gl.glVertex3f(-h/2, -b/2, 0.f);
gl.glTexCoord2f(0.f, y); gl.glVertex3f(h/2, -b/2, 0.f);
gl.glTexCoord2f(x, y); gl.glVertex3f(h/2, b/2, 0.f);
gl.glTexCoord2f(x, 0.f); gl.glVertex3f(-h/2, b/2, 0.f);
gl.glEnd();
gl.glMatrixMode( GL_MODELVIEW );

gl.glDisable(GL_POLYGON_OFFSET_FILL);

Does anyone know what is wrong?
Thx!

vincoof
04-09-2003, 02:23 AM
What do you mean by "it still shows wrong" ? How does it look like ?

I guess you either forget to disable TEXTURE_2D for the lines or you forget to enable TEXTURE_2D for the polygon.

Is texturing enabled ?

Don Gazon
04-09-2003, 03:53 AM
What I mean with wrong: the line was still not visible everywhere. The polygon's z-buffer values were still smaller at some places despite the polygon offset was turned on.

But the problem is solved now.
Thanks alot, you were right!!!
There was something wrong with my texture code. (the polygon is textured, but I messed up that code while trying the offset).

Thx!!!