我想用我的代码创建一个图形(2d图形),如何在opengl中创建一个简单的2d图形?我是opengl的新手,所以也许你可以解释一下我的代码是如何工作的.顺便说一句,这是我的代码:
#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");
}
Run Code Online (Sandbox Code Playgroud)
可能你应该看看这里http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_01
有很好的信息可以开始绘制曲线.因为你有一个参数化曲线,只需将你的x,y存储在一个顶点缓冲对象(VBO)中,其大小为你想要在曲线上的点数,并像这样绘制VBO:
glDrawArrays(GL_LINE_STRIP, 0, nbPoints);
Run Code Online (Sandbox Code Playgroud)
这将使连续的断线连接所有点.
| 归档时间: |
|
| 查看次数: |
10055 次 |
| 最近记录: |