Part of the Khronos Group
OpenGL.org

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

Threaded View

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

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

Posting Permissions

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