#include<Windows.h>
#include<math.h>
#include<gl/glut.h>;
const int screenWidth=640; //屏幕窗口的宽度,以像素为单位
const int screenHeight=480; //屏幕窗口的高度,以像素为单位
GLdouble A,B,C,D; //比例变换和平移值
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0); //设置背景颜色为白色
glColor3f(0.0f,0.0f,0.0f); //图片颜色为黑
glPointSize(2.0); //点大小为2*2像素
glMatrixMode(GL_PROJECTION); //设置“相机模式”,将当前矩阵指定为投影矩阵
glLoadIdentity(); //将矩阵设为单位矩阵
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
A=screenWidth/4.0; //设置比例变换和平移值
B=0.0;
C=D=screenHeight/2.0;
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); //清屏
glBegin(GL_POINTS);
for(GLdouble x=0;x<4.0;x+=0.005)
{
GLdouble func=sin(x*x);
glVertex2d(A*x+B,C*func+D);
}
glEnd();
glFlush();
}
void main(int argc,char** argv)
{
glutInit(&argc,argv); //初始工具包
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //设置显示模式
glutInitWindowSize(screenWidth,screenHeight); //设置窗口大小
glutInitWindowPosition(100,150);//设置窗口在屏幕上的位置
glutCreateWindow("用点集绘制函数");
glutDisplayFunc(myDisplay); //注册重画函数
myInit();
glutMainLoop(); //进入永久循环
}
#include<math.h>
#include<gl/glut.h>;
const int screenWidth=640; //屏幕窗口的宽度,以像素为单位
const int screenHeight=480; //屏幕窗口的高度,以像素为单位
GLdouble A,B,C,D; //比例变换和平移值
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0); //设置背景颜色为白色
glColor3f(0.0f,0.0f,0.0f); //图片颜色为黑
glPointSize(2.0); //点大小为2*2像素
glMatrixMode(GL_PROJECTION); //设置“相机模式”,将当前矩阵指定为投影矩阵
glLoadIdentity(); //将矩阵设为单位矩阵
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
A=screenWidth/4.0; //设置比例变换和平移值
B=0.0;
C=D=screenHeight/2.0;
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); //清屏
glBegin(GL_POINTS);
for(GLdouble x=0;x<4.0;x+=0.005)
{
GLdouble func=sin(x*x);
glVertex2d(A*x+B,C*func+D);
}
glEnd();
glFlush();
}
void main(int argc,char** argv)
{
glutInit(&argc,argv); //初始工具包
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //设置显示模式
glutInitWindowSize(screenWidth,screenHeight); //设置窗口大小
glutInitWindowPosition(100,150);//设置窗口在屏幕上的位置
glutCreateWindow("用点集绘制函数");
glutDisplayFunc(myDisplay); //注册重画函数
myInit();
glutMainLoop(); //进入永久循环
}