Inconsistent rendering of triangles

Hi,
Using Dev-Cpp, Win32,OGL to build 3D world. I am drawing a wall with 1000 triangles (on 4 rows). Displaying lines only. As I operate the keys on the keyboard I am deliberately manipulating gluLookAt() function.

What happens is that as I move around, I loose 1 row, 2 rows or most of the triangles. Another keystroke later and all is well.

Is this what all the posting call ‘flicker’ related to the vertical sync? Is there something with depth or viewport or some other aspect that I can look at?

Any help would be appreciated.

Here is a link to an image showing the problem.

](‘http://www.putfile.com’)[/IMG]

Here is the initialization code.

    RECT rcl;
    GLfloat fAspect;
    GLsizei w, h;
    GetClientRect(g_hWnd, &rcl);
    h=rcl.bottom - rcl.top;
    w = rcl.right - rcl.left;
    if(h==0)
      h = 1;
    glViewport(0,0,w,h);
    fAspect = (GLfloat)w/(GLfloat)h;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0f, fAspect, 0.0, -20.0);
  

Here is the drawing code.

void DrawWorld(HDC hMyDC)
{
  int iPolyCount =0;
  float eyex,eyey,eyez,lookx,looky,lookz;

  //Initialization
  glClearColor(0.0f, 0.0f,0.0f,0.0f);
  glShadeModel(GL_SMOOTH);
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();
    eyex=con.getTranslateX();
    eyey=con.getTranslateY();
    eyez=con.getTranslateZ();
    lookx=eyex;//sin(con.getRotateZ() * 3.14159/180)*eyex;
    looky=eyey + 5;//cos(con.getRotateZ() * 3.14159/180)*eyey;
    lookz=-9.5;//eyez;  

    gluLookAt(eyex, eyey, eyez,//eye
              lookx,looky,lookz, //look at point
              0,0,1);

    //100 x 100 m, each cell is 5 x 5 m
    glBegin(GL_LINES);
    glColor3f(0.0f, 0.4f, 0.0f);

    for(int i=-10;i<11;i++){
      glVertex3f(i,-10,-10);
      glVertex3f(i,10,-10);
      glVertex3f(-10, i,-10);
      glVertex3f(10,i,-10);
    }

    //triaxial coordinate reference
    glLineWidth(3);
    glColor3d(255,0,0);          //red line +X axis
    glVertex3f(0.0f,0.0f,-10.0f);
    glVertex3f(1.0f,0.0f,-10.0f);
    glColor3d(0,255,0);          //green line +Y axis
    glVertex3f(0.0f,0.0f,-10.0f);
    glVertex3f(0.0f,1.0f,-10.0f);
    glColor3d(0,0,255);          //blue line +Z axis
    glVertex3f(0.0f,0.0f,-10.0f);
    glVertex3f(0.0f,0.0f,-9.0);
    glEnd();
    glLineWidth(1);
    
    //north wall 100 x 5 m
    glPolygonMode(GL_FRONT, GL_LINE);
    texture3.select();
    glEnable(GL_TEXTURE_2D);

    glColor3d(255,255,255);
    glBegin(GL_TRIANGLES);
    for(int i=-50;i<50;i++){
      for(int j=0;j<5;j++){   
        
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(i * .2 ,10,-9 - j * .2);   //top-left triangle CCW
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(i *.2,10,-9 - (j * .2) - .2);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(i * .2 + .2,10,-9 - j * .2);
        
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(i * .2,10,-9 - (j * .2) - .2);   //bottom-right triangle CCW
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f(i * .2 + .2,10,-9 - (j * .2) - .2);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(i * .2 + .2,10,-9 - j * .2);
        iPolyCount += 2;
      }
    }
    glEnd();

    char szWindowTitle[30];
    sprintf(szWindowTitle, "Polygon Count: %d", iPolyCount);
    SetWindowText(g_hWnd, szWindowTitle);
  glPopMatrix ();
  
  SwapBuffers (hMyDC);
}
  

Regards,
Chuck

Here is a clearer link to the image above.

Thanks,
Chuck

“gluPerspective(60.0f, fAspect, 0.0, -20.0);”
Two errors in one line:
In a perspective view you must specify zNear and zFar so that 0.0 < zNear < zFar.

Relic,
You rock!! Thanks for finding the problem so quickly.

Regards,
Chuck