Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Newbie Newbie
    Join Date
    Nov 2017

    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

    Code :
    gluOrtho2D(-5.0, 5.0, -0.3, 1.0);
    Code :
    	for (GLfloat x = -4.0; x<4.0; x += 0.1)
    		glVertex2f(x, sin(3.14159*x) / 3.15159);
    it draws the function fine

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


    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 ?
    Last edited by umartariq; 11-07-2017 at 01:26 AM.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2016
    Ocean Shores, WA USA
    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:

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

    would that work?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts