   Fitting view to screen
  Hello, I am working on a plotting program, one that will plot 2 dimensional points. The plotting isn''t the hard part for me; it is the fact that if the user wants to only see from -1 to 1 on the x axis, then -1 to 1 should fill the *entire* window across. Basically, I want my program to make the graph as large as possible and still show the specified region. I don''t care if it isn''t a 1:1 ratio of x to y. I have been trying various things, but I can''t get it to work. Any help would be greatly appreciated. Thanks a lot.   ~Evlich 
  Use glOrtho(...); you can specify inside it the range of your view. it is used to do 2d in opengl. if you are uncertain how to use it look it up, in the red book which can be found as a pdf in the (Articles & Resources)->(OpenGl) section.   "I seek knowledge and to help those who also seek it" ;  OK, I did this:---------------------------------------------------------GLfloat dimensions[4];glGetFloatv(GL_VIEWPORT, dimensions);pWidth = dimensions[2];pHeight = dimensions[3];glPushMatrix();glOrtho(minX, maxX, minY, maxY, 1, -1);glTranslatef(0, 0, -1); /* this because I didn''t see anything without it*/glBegin(GL_LINES);glColor3f(defColor[0], defColor[1], defColor[2]); //X-axis glVertex3f(minX, 0.0f, 0.0f); glVertex3f(maxX, 0.0f, 0.0f); //Y-axis glVertex3f(0.0f, minY, 0.0f); glVertex3f(0.0f, maxY, 0.0f);for( long double iter = scaleX; iter <= maxX; iter += scaleX ){ /* I wanted the tick marks exactly 5 pixels */ glVertex3f(iter, 5*(maxY-minY)/pHeight, 0.0f); glVertex3f(iter, -5*(maxY-minY)/pHeight, 0.0f);}for( iter = -1*scaleX; iter >= minX; iter -= scaleX ){ /* I wanted the tick marks exactly 5 pixels */ glVertex3f(iter, 5*(maxY-minY)/pHeight, 0.0f); glVertex3f(iter, -5*(maxY-minY)/pHeight, 0.0f);}for( iter = scaleY; iter <= maxY; iter += scaleY ){ /* I wanted the tick marks exactly 5 pixels */ glVertex3f(5*(maxX-minX)/pWidth, iter, 0.0f); glVertex3f(-5*(maxX-minX)/pWidth, iter, 0.0f);}for( iter = -1*scaleY; iter >= minY; iter -= scaleY ){ /* I wanted the tick marks exactly 5 pixels */ glVertex3f(5*(maxX-minX)/pWidth, iter, 0.0f); glVertex3f(-5*(maxX-minX)/pWidth, iter, 0.0f);}glEnd();glPopMatrix();----------------------------------------------------------minX, maxX, minY, maxY are the values -10, 10, -10, 10 respectively, but I don''t see any of the tick marks. I think that it is because they are not in my field of view, but I might be wrong. Does anyone see a problem with this? Thanks a lot.   ~Evlich ;  Yes, You need to call glMatrixMode(GL_PROJECTION); before glOrtho and glMatrixMode(GL_MODELVIEW); after you call glOrtho. because glOrtho is the projection type, you use it instead of gluPerspective(...) or glFrustrum(...).    "I seek knowledge and to help those who also seek it" ;  OK, I did that, but it didn''t seem to do anything. I still only see from roughly -.5 to .5 on both axis rather than from -10 to 10. Even if I put in glOrtho(-100, 100, -100, 100, 1, 1); I still see the same thing. It seems like I am going to have to do a glScalef or something like that to scale the axis; however, I don''t know what values I should use. Thanks a lot.   ~Evlich ;  Did you use glLoadIdentity(); in projection mode or are you useing any other projection mode? from earlier?   "I seek knowledge and to help those who also seek it" ;  OK, this is what the top looks like now:-------------------------------------------glLoadIdentity();glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(minX, maxX, minY, maxY, 0,0);glMatrixMode(GL_MODELVIEW);//This is so that we are looking at the center of the graphglTranslatef(-(maxX+minX)/2., -(maxY+minY)/2., -1);//the Ortho ony showed from -1 to 1, so I scaled the axisglScalef(2/(maxX-minX),2/(maxY-minY),1);------------------------------------------And it seems to work fine, except that when I move left and right (by altering minX and maxX) or up and down (by altering minY and maxY), the axis don''t move. So I end up with the x-axis only going halfway across the screen. Also, when I move my view to xmin = 0 xmax = 6.28 xscale = 1, ymin = -5, ymax = 20, yscale = 5, I see nothing at all. I really don''t know what could be causing this problem. Thanks for your help so far.   ~Evlich ;quote:Original post by Evlich  OK, this is what the top looks like now:-------------------------------------------glLoadIdentity();glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(minX, maxX, minY, maxY, 0,0);glMatrixMode(GL_MODELVIEW);//This is so that we are looking at the center of the graphglTranslatef(-(maxX+minX)/2., -(maxY+minY)/2., -1);//the Ortho ony showed from -1 to 1, so I scaled the axisglScalef(2/(maxX-minX),2/(maxY-minY),1);------------------------------------------ok, pretty good, but that translate should not be required, you can make minX a negitive number, just use it to make the center the average of the minx, maxx, miny, maxy. it shouldn''t be much of a problem.glOrtho(-1,1,-1,1,1,-1);will make the center of the screen 0,0.quote:Original post by Evlich  And it seems to work fine, except that when I move left and right (by altering minX and maxX) or up and down (by altering minY and maxY), the axis don''t move. So I end up with the x-axis only going halfway across the screen. Also, when I move my view to xmin = 0 xmax = 6.28 xscale = 1, ymin = -5, ymax = 20, yscale = 5, I see nothing at all. I really don''t know what could be causing this problem. Thanks for your help so far.   ~Evlich   Hmm, well heres starters, when you change your glOrtho you need to move those tick mark things too. as to keep them in range of sight, I don''t know if you already took this into consideration or not. Im not understanding the problem very much nor am I very awake. Try playing with the values. turning some things on and off, and experiment. See what you can come up with.  "I seek knowledge and to help those who also seek it" 