Basiest Question

I have a windown (M,N).
For ex: 1000,800. (M=1000) wide, and N=800 (height)

I just need to draw points in it… So I did the glOrtho projection this way.


void reshape (int w, int h){
  //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // Prevent a divide by zero
  if(h == 0) h = 1;
  glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  glOrtho(0.0, (GLfloat)M, 0.0, (GLfloat)N ,-1.0,1.0);
  gluLookAt(M/10.0, N/10.0, 1.0 , 
            M/10.0, N/10.0, 0.0,  
                    0.0,1.0,0.0);
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity();

}

the complete code is:

void display(void){

//I MAKE THIS WINDOWS LIMITS TO SEE IT VISIBLE 
 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glColor3f(1.0,1.0,1.0);
 glLoadIdentity();
 glBegin(GL_LINES);
 glVertex2f(1.0,1.0);
 glVertex2f(M,1.0); 

 glVertex2f(M,1.0);
 glVertex2f(M,N);

 glVertex2f(M,N);
 glVertex2f(1.0,N);
 
 glVertex2f(1.0,N);
 glVertex2f(1.0,1.0);
 glEnd();

//after this I draw points
 glPushMatrix();
 for(j=0;j<N;j++){
	for(i=0;i<M;i++){
		glColor3f(1.0,1.0,0.0); 
	        glPointSize(2.0);
		glPushMatrix();
  		glBegin(GL_POINTS);
		glVertex2f((double)i,(double)j); 
		glEnd();
		glPopMatrix();
	}
 }
 glutSwapBuffers();

}


void reshape (int w, int h){
  //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // Prevent a divide by zero
  if(h == 0) h = 1;
  glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  glOrtho(0.0, (GLfloat)M, 5.0, (GLfloat)N ,-1.0,1.0);
  gluLookAt(M/10.0, N/10.0, 1.0 , M/10.0, N/10.0, 0.0,  0.0,1.0,0.0);
  //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
  
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity();


   
}
 
void keyboard(unsigned char key, int x, int y){
  switch (key) {
  case 27:
    exit(0);
    break;
  }
  x=0; y=0;

}

void mouse(int button, int state, int x, int y) 
{
 
  switch (button) {
  case GLUT_RIGHT_BUTTON:
    exit(0);
    break;
  default:
    break;
  }
  x=0;y=0;
}

int main(int argc, char** argv){
  
  glutInit(&argc, argv);
  //glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB);
  glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB);
  glutInitWindowSize (M,N);
  glutInitWindowPosition (20, 20);
  glutCreateWindow ("Simulation");
  init ();
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutReshapeFunc(reshape);
  glutMouseFunc(mouse);
  glutMainLoop();
  
  return 0;
}

It draws… but the origin (x,y) is offset down the visible area… :S and I dont know how to get it right…
What am I doing wrong? :s I have no idea.

I hope for the origing to be in (0,0) but it’s not in there…
How could I set a 1000x800 windows with the origing in 0.0 ?

PD: Anyone has and idea?

>> gluLookAt(M/10.0, N/10.0, 1.0 ,
M/10.0, N/10.0, 0.0,
0.0,1.0,0.0);

A/ watch out, due to how gluLookOut works having the same x,y, numbers in the from + at positions might cause math problems (invalid numbers)
B/ also playing the viewer at -1 which is on the edge of the near/far clip planes sounds dangerous
C/ stick gluLookAt in the modelview matrix + not the projection matrix