c# - OpenGL/SharpGL - Points only on -near surface of Ortho projection? -


when create points using 3 dimensions each point , use ortho projection view points, there reason points on -near surface appear? example, if use (the sharpgl method) gl.ortho(0, width, height, 0, -10, 10), points @ z=10 (because near surface @ -10) show up.

i'm using sharpgl - i'm hoping issue i'm having isn't particular implementation/library.

edit: i'm adding code below demonstrates issue. note example requires sharpgl , in fact modification of wpf sample project comes current sharpgl source code (the original sample project called twodsample).

the project requires mainwindow.xaml , mainwindow.xaml.cs. here's xaml:

<window x:class="twodsample.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525"     xmlns:my="clr-namespace:sharpgl.wpf;assembly=sharpgl.wpf">     <grid>         <my:openglcontrol name="openglcontrol1" opengldraw="openglcontrol1_opengldraw" openglinitialized="openglcontrol1_openglinitialized"                           resized="openglcontrol1_resized"/>     </grid> </window> 

here code behind:

using system; using system.collections.generic; using system.linq; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; using sharpgl.enumerations;  namespace twodsample {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();         }          // note: use restrict openglcontrol1_opengldraw method          // drawing once after m_drawcount set zero;         int m_drawcount = 0;         private void openglcontrol1_opengldraw(object sender,     sharpgl.scenegraph.opengleventargs args)         {             // note: draw once after m_drawcount set 0             if (m_drawcount < 1)             {                 //  opengl instance.                 var gl = args.opengl;                  gl.color(1f, 0f, 0f);                 gl.pointsize(2.0f);                  //  draw 10000 random points.                 gl.begin(beginmode.points);                 random random = new random();                 (int = 0; < 10000; i++)                 {                     double x = 10 + 400 * random.nextdouble();                     double y = 10 + 400 * random.nextdouble();                     double z = (double)random.next(-10, 0);                      // color point according z value                     gl.color(0f, 0f, 1f);  // default blue                     if (z == -10)                         gl.color(1f, 0f, 0f);   // red z = -10                     else if (z == -1)                         gl.color(0f, 1f, 0f);   // green z = -1                      gl.vertex(x, y, z);                 }                      gl.end();                     m_drawcount++;                 }             }              private void openglcontrol1_openglinitialized(object sender,     sharpgl.scenegraph.opengleventargs args)         {          }          private void openglcontrol1_resized(object sender,     sharpgl.scenegraph.opengleventargs args)         {             // note: force draw routine happen again when resize occurs             m_drawcount = 0;             //  opengl instance.             var gl = args.opengl;              //  create orthographic projection.             gl.matrixmode(matrixmode.projection);             gl.loadidentity();              // note: no matter do, points see @             // "near" surface (with z = -znear)--in case, see green points             gl.ortho(0, openglcontrol1.actualwidth, openglcontrol1.actualheight, 0, 1, 10);              //  modelview.             gl.matrixmode(matrixmode.modelview);         }     } } 

thanks madcoretom's comment depth buffer , bit of googling, think found (or @ least "a") solution. if clear depth buffer @ start of drawing routine, (and color points red if z == -9 rather z == -10 since random.next(-10,0) not give value of -10), things seem work expected.

to see points @ z values (within ortho limits) replaced openglcontrol1_opengldraw method following:

    private void openglcontrol1_opengldraw(object sender,     sharpgl.scenegraph.opengleventargs args)     {         // note: draw once after m_drawcount set 0         if (m_drawcount < 1)         {             //  opengl instance.             var gl = args.opengl;              // added line             gl.clear(sharpgl.opengl.gl_depth_buffer_bit);              gl.color(1f, 0f, 0f);             gl.pointsize(2.0f);              //  draw 10000 random points.             gl.begin(beginmode.points);             random random = new random();             (int = 0; < 10000; i++)             {                 double x = 10 + 400 * random.nextdouble();                 double y = 10 + 400 * random.nextdouble();                 double z = (double)random.next(-10, 0);                  // color point according z value                 gl.color(0f, 0f, 1f);  // default blue                 if (z == -9)                     gl.color(1f, 0f, 0f);   // red z = -10                 else if (z == -1)                     gl.color(0f, 1f, 0f);   // green z = -1                  gl.vertex(x, y, z);             }                  gl.end();                 m_drawcount++;             }         } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -