Results 1 to 7 of 7

Thread: How to use openGL to plot a sine wave in C++ language

  1. #1
    Join Date
    Mar 2011
    Posts
    82

    How to use openGL to plot a sine wave in C++ language

    Last one month I use C++ programming language. This C++ will be completely based on the OOP's ( Object oriented Programming ) Language. Now, I need some code that help to plot a sine wave using a OpenGL between two points in a C++ program.

  2. #2
    Join Date
    Apr 2009
    Posts
    491

    Re: How to use openGL to plot a sine wave in C++ language

    For doing this complicated task you need to follow the below code.
    // all initialization have been done before calling GlDraw()
    void GLDraw()
    {
    int p;
    const maximum = 200;
    float r;

    glColor3f(0.1f, 0.1f, 0.1f);
    glPointSire(4);

    //If you need to draw points plot
    //Draw points
    glBegin(GL_POINTS);
    for (p=0; p<maximum; p++)
    r = sin((float) p/20)
    glVertex3d(p, 0, r);
    glEnd();

    //If you need a lines plot
    //Draw lines
    glBegin(GL_LINE_STRIP);
    for (p=0; p<maximum; p++) {
    r = sin((float)p/20);
    glVertex3d(p, 0, r)
    }
    glEnd();
    }
    this is the special code and it help to compute points coordinates and plot them on the screen.

  3. #3
    Join Date
    May 2009
    Posts
    542

    Re: How to use openGL to plot a sine wave in C++ language

    I use this code and when I try to compile this code, then I found so many error messages. This code also gives the warning messages. Then I read the basic syntax of the code. Hence I found the correct syntax which is present in the OpenGL that is Open Graphics library. This OpenGL is really help to do such complicated task., hence I think you need to read this OpenGlL for doing such complicated task. Use this and solve the error present in this program. This is really help to you for solving the error and also plot the sine wave on it.

  4. #4
    Join Date
    May 2009
    Posts
    527

    Re: How to use openGL to plot a sine wave in C++ language

    I think there will be some code missing in this program and hence this will be gives the problem. Then I suggest you to insert the following code for doing such task. Hence, check the initialization function of the program. This function use to initialize the variable of the program. Then use the init() function and then initialize OpenGl variables. Few method such as
    glFrustum(-40, 40, -40, 40, 100, 2500);
    glMatrixMode(GL_MODELVIEW);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glTranslated(0, -50, -300);

    will be help to make some changes on the code and in the result the sine wave of the program will be display in the different manner. Then use this code and it help to you for solving the problem.

  5. #5
    Join Date
    May 2009
    Posts
    546

    Re: How to use openGL to plot a sine wave in C++ language

    Now the official site of the OpenGL is available on the internet site. Then you need to just use this official site and then it help to run the code. This code is completely based on the graphics and you need to just read the function present in the OpenGL. The site provides the complete function of this code. Then use this site and it will be hope to built the program. This program is to be syntax error free and this will be help to you for solving the problem.

  6. #6
    Join Date
    Apr 2009
    Posts
    570

    Re: How to use openGL to plot a sine wave in C++ language

    This is the 2D sine wave program and if you want to build the 3D sine wave, then you need to read the official site of the C++ language. This is the best way to solve the problem. Then just read the method as well as the supporting inbuilt function of the C++ and it will be help to you for building the 3D sine wave. Then use this 3D compatible method and it will help to you for solving the problem. The header will be necessary in this program.

  7. #7
    Join Date
    May 2009
    Posts
    640

    Re: How to use openGL to plot a sine wave in C++ language

    Honestly, I will suggest you that many program present over the internet site. This program will be help to generate the sine wave using this OpenGL. You need to execute this code and this will be help to understand the basic syntax of the method. Then check the method syntax and then replace if anything wrong on this code. This will be help to solve the error of the program. The header files of the program must necessary in this code. This header file helps to provide the syntax to the compiler.

Similar Threads

  1. Replies: 8
    Last Post: 19-04-2012, 08:12 PM
  2. Plot hole in Brink
    By ABRIELLE in forum Video Games
    Replies: 5
    Last Post: 19-05-2011, 10:21 AM
  3. How "Pure Sine Wave" generated in UPS.
    By Miren in forum Hardware Peripherals
    Replies: 5
    Last Post: 01-04-2011, 10:40 PM
  4. Scatter plot in excel
    By Gunner 1 in forum Windows Software
    Replies: 5
    Last Post: 06-01-2010, 01:14 PM
  5. Bode Plot in C
    By Triple-X in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 01:50 PM

Posting Permissions

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