jogl - GL_LINES is not visible inside a cube -
what draw parallelepiped (using gl_quads) , edges (using gl_lines). parallelepiped supposed squash field, , camera inside it. problem when use gl_lines, line drawn not visible when camera inside parallelepiped.
couple of screenshots understand better :
inside - line not visible : http://i.stack.imgur.com/ozky5.png
outside - line visible : http://i.stack.imgur.com/ah40o.png
this what's inside init method :
gl2 gl = drawable.getgl().getgl2(); // opengl graphics context glu = new glu(); // gl utilities gl.glclearcolor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color gl.glcleardepth(1.0f); // set clear depth value farthest gl.glenable(gl_depth_test); // enables depth testing gl.glenable(gl_blend); gl.glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); gl.gldepthfunc(gl_lequal); // type of depth test gl.glhint(gl_perspective_correction_hint, gl_nicest); // best perspective correction gl.glshademodel(gl_smooth); // blends colors nicely, , smoothes out lighting gl.glenable(gl_line_smooth);
and display method :
gl2 gl = drawable.getgl().getgl2(); // opengl 2 graphics context gl.glclearcolor(0.55f, 0.55f, 0.55f, 1.0f); gl.glclear(gl_color_buffer_bit | gl_depth_buffer_bit); // clear color , depth buffers gl.glloadidentity(); // reset model-view matrix gl.gltranslated(-3.2, -2.82, -10); // translate screen gl.glbegin(gl_quads); // start drawing quad gl.glcolor4ub(r,g,b, alpha); gl.glvertex3d(0, 0, 0); gl.glvertex3d(0, 5.640, 0); gl.glvertex3d(6.400, 5.640, 0); gl.glvertex3d(6.400, 0, 0); gl.glvertex3d(0, 0, 0); gl.glvertex3d(0, 5.640, 0); gl.glvertex3d(0, 5.640, 9.750); gl.glvertex3d(0, 0, 9.750); gl.glvertex3d(6.400, 0, 0); gl.glvertex3d(6.400, 5.640, 0); gl.glvertex3d(6.400, 5.640, 9.750); gl.glvertex3d(6.400, 0, 9.750); gl.glvertex3d(0, 0, 9.750); gl.glvertex3d(0, 5.640, 9.750); gl.glvertex3d(6.400, 5.640, 9.750); gl.glvertex3d(6.400, 0, 9.750); gl.glvertex3d(0, 0, 0); gl.glvertex3d(0, 0, 9.750); gl.glvertex3d(6.400, 0, 9.750); gl.glvertex3d(6.400, 0, 0); gl.glvertex3d(0, 5.640, 0); gl.glvertex3d(0, 5.640, 9.750); gl.glvertex3d(6.400, 5.640, 9.750); gl.glvertex3d(6.400, 5.640, 0); gl.glend(); // done drawing quad gl.gllinewidth(2); gl.glbegin(gl_lines); gl.glcolor4ub((byte)0,(byte)0,(byte)0, (byte)255); gl.glvertex3d(0, 0, 0); gl.glvertex3d(0, 5.640, 0); gl.glend();
thank help.
lines draw using same z-buffer quads. when outside, lines closer camera edges of quads , draw. when inside, surface of quads closer , line not draw. because of numerical errors lines can appear or disappear time time. turn of depth test , lines should draw.
Comments
Post a Comment