OpenGL绘制函数

#include <windows.h>    // Windows的头文件

#include <gl\gl.h> // OpenGL32库的头文件
#include <gl\glu.h> // GLu32库的头文件
#include <gl\glaux.h> // GLaux库的头文件
#include <gl\glut.h> // Glut库头文件

#include <math.h>

#pragma comment( lib, "opengl32.lib") // OpenGL32连接库
#pragma comment( lib, "glu32.lib") // GLu32连接库
#pragma comment( lib, "glaux.lib") // GLaux连接库
#pragma comment( lib, "glut.lib") // Glut链接库

int screenWidth=640;
int screenHeight=480;
GLdouble A,B,C,D; //比例变换平移值

void myInit()
{
glClearColor(1.0,1.0,1.0,0.0); //设置背景颜色为亮白
glColor3f(0.0f,0.0f,0.0f); //设置绘图颜色为黑色
glPointSize(4.0); //设置点的大小为4*4像素
glMatrixMode(GL_PROJECTION); //设置合适的矩阵
glLoadIdentity();
gluOrtho2D(0.0,screenWidth,0.0,screenHeight);
A=screenWidth/4.0;
B=0.0;
C=D=screenHeight/2.0;
}


GLdouble func(GLdouble x)
{
return exp(-x)*cos(2*3.1415926*x);
}

void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);

for(GLdouble x=0;x<2*3.14159;x+=0.00025)
glVertex2d(A*x+B,C*func(x)+D);

glEnd();
glFlush();

}

void main(int argc, char **argv)
{
glutInit(&argc,argv); //初始化工具包
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//设置显示模式
glutInitWindowSize(640,480); //设置窗口大小
glutInitWindowPosition(100,150); //设置窗口在屏幕上的位置
glutCreateWindow("my first attempt"); //打开屏幕窗口

//注册回调函数
glutDisplayFunc(myDisplay);

myInit();
glutMainLoop(); //进入循环
}
posted @ 2012-01-21 20:09  Dsp Tian  阅读(1006)  评论(0编辑  收藏  举报