Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 26-06-2011
Member
 
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.

Reply With Quote
  #2  
Old 26-06-2011
Member
 
Join Date: Apr 2009
Posts: 481
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.
Reply With Quote
  #3  
Old 26-06-2011
Member
 
Join Date: May 2009
Posts: 531
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.
Reply With Quote
  #4  
Old 26-06-2011
Member
 
Join Date: May 2009
Posts: 523
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.
Reply With Quote
  #5  
Old 26-06-2011
Member
 
Join Date: May 2009
Posts: 532
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.
Reply With Quote
  #6  
Old 26-06-2011
Member
 
Join Date: Apr 2009
Posts: 566
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.
Reply With Quote
  #7  
Old 27-06-2011
Member
 
Join Date: May 2009
Posts: 614
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use openGL to plot a sine wave in C++ language"
Thread Thread Starter Forum Replies Last Post
How to change “Microsoft office 2011 for Mac” language as I bought the wrong language package Naq Windows Software 8 19-04-2012 08:12 PM
Plot hole in Brink ABRIELLE Video Games 5 19-05-2011 10:21 AM
How "Pure Sine Wave" generated in UPS. Miren Hardware Peripherals 5 01-04-2011 10:40 PM
Scatter plot in excel Gunner 1 Windows Software 5 06-01-2010 01:14 PM
Bode Plot in C Triple-X Software Development 3 09-11-2009 01:50 PM


All times are GMT +5.5. The time now is 01:41 PM.