I want to create a graph (2d graph) with my code, How can I make a simple 2d graph in opengl? I'm new in opengl, so maybe you can explain me how is the code works, please. by the way here is my code :
#include <iostream>
using namespace std;
int main ()
{
double dt = 0.10; //(it is constant)
double t = 0.00;
double dx = 0.10; //(it is constant)
double x = 0.00;
double ddy = 1.00; //(it is constant)
double dy = 0.00;
double y = 1.00;
cout<<"t = "<<t<<endl;
cout<<"dx = "<<dx<<endl;
cout<<"x = "<<x<<endl;
cout<<"dy = "<<dy<<endl;
cout<<"y = "<<y<<endl;
cout<<endl;
while(t<=5)
{
x = x + dx*dt;
dy = dy - ddy * dt * dt;
y = y + dy * dt;
if (y<=-1)
{
y = -y;
dy = -dy * 0.70;
}
t = t + dt;
cout<<"t = "<<t<<endl;
cout<<"dx = "<<dx<<endl;
cout<<"x = "<<x<<endl;
cout<<"dy = "<<dy<<endl;
cout<<"y = "<<y<<endl;
cout<<endl;
}
system("pause");
}
May be you should take a look here http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_01
There is good information to start drawing curves. Because you have a parametrized curve, just store your x,y in a vertex buffer object (VBO) with a size of the number of points you want on your curve and draw that VBO like that :
glDrawArrays(GL_LINE_STRIP, 0, nbPoints);
This will make a continuous broken line connecting all your points.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With