# How To Display the Graph Of a Function In All 4 Quadrants

I am using OpenGL in C++ language and Visual Studio 2013 as my IDE

Consider the function sin(pi*x/pi)

ranging from x=-4 to +4

i have the following code

``````
gluOrtho2D(-5.0, 5.0, -0.3, 1.0);

``````

and

``````
glBegin(GL_LINE_STRIP);

for (GLfloat x = -4.0; x<4.0; x += 0.1)
{
glVertex2f(x, sin(3.14159*x) / 3.15159);

}
glEnd();
glFlush();

``````

it draws the function fine

Consider the following statement
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);

e.g

gluOrtho2D(0.0, 640.0, 0.0,480.0);

contrast it with

gluOrtho2D(-5.0, 5.0, -0.3, 1.0);

i do not understand at all the negative values used in Ortho2D

my question is how would i set values in glOrtho2D function so that the function is drawn in the entire 4 quadrants of a graph and origin is at the center of screen
and also how would i display the axes as well in the output … with X-cordinates and Y-coordinates also being marked on the screen ?

You said it draws the function fine… where does it draw the function?

If it’s in the top left, then simply add half the screen coordinates to your drawing function:

``````glVertex2f(x+(1/2 screenWidth), (sin(3.14159*x) / 3.15159) + (1/2 screenHeight) )
``````

would that work?

Jeff