
程序代码:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
int Round(float a) //对小数进行四舍五入
{
int i=(int)a;
float j=a-i;
if(j<0.5)
return i;
if(j>0.5)
return i+1;
if(j==0.5)
{
if(i%2==0)
return i;
else
return i+1;
}
return -1;
}
void display() //边计算边画点
{
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,250.0,0.0,550.0); //对象显示区域
glColor3f(1.0,0.0,0.0); //对象设置为红色
int _x=200,_y=500,i;
int x=0,y=0;
int p=2*_x-_y;
glBegin(GL_POINTS); //画第一点
glVertex2i(0,0);
glEnd();
for(i=0;i<_y;i++) //找一点画一点
{
if(p<0) //判断下一点
{
y=y+1;
p=p+2*_x;
}
else //判断下一点
{
x=x+1;
y=y+1;
p=p+2*_x-2*_y;
}
glBegin(GL_POINTS); //画点
glVertex2i(x,y);
glEnd();
}
glFlush(); //刷新
}
void main(int argc,char **argv)
{
glutInit(&argc,argv); //glut初始化
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100); //窗体位置
glutInitWindowSize(300,600); //窗体大小
glutCreateWindow("0810050225"); //窗体名字
glClearColor(0.0,0.0,0.0,0.0); //黑色背景
glClear(GL_COLOR_BUFFER_BIT);
glutDisplayFunc(display); //执行
glutMainLoop(); //程序等待
system("pause");
}
MFC不会,OpenGL略知一二!