// 计算机图形学_实验5_20181017.cpp : 定义应用程序的入口点。
//
#include "计算机图形学_实验5_20181017.h"
#include <graphics.h>
#include <conio.h>
// circle algorithm.cpp : Defines the entry point for the console application.
//
//This program was updated by Ms Huang Jing in Beijing Normal Unbersity Zhuhai Campus
// in Oct 20 in 2012,Contact email: 306744855@qq.com
#include "stdafx.h"
#include <glut.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <math.h>
#define N 1000 //maximum line numbers
int cx = 150, cy = 150, radius = 80, ri = 50, ro = 80, n = 3, samples = 1, flag = 1;
int ww, hh; // for display window width and height
int line[N][4], k = 0; //for line's endpoint coordinates and line number
void Myinit(void);
void plotC(int x, int y, int xc, int yc);
void Bresenham_Circle_Algorithm(int cx, int cy, int radius);
void DrawOneLine(int x1, int y1, int x2, int y2);
void NSidedPolygon(int n, int cx, int cy, int radius);
void SampleCircle(int inner, int outer, int samples, int cx, int cy);
void Keyboard(unsigned char key, int x, int y);
void Display(void);
void Reshape(int w, int h);
void Drawlines();
void myMouse(int button, int state, int x, int y);
void myMotion(int x, int y);
void DDA_Drawlines();
void CirPot(int x0, int y0, int x, int y, int color);
void drawCircle();
void MidPoint_Circle(int x0, int y0, double radius, int color);
void Bresenham_line(int xa, int ya, int xb, int yb);
void Bresenham_line2(int xa, int ya, int xb, int yb);
void Bresenham_Drawlines();
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
char *argv[] = { "hello ", " " };
int argc = 2; // must/should match the number of strings in argv
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Basic_Primitive_Algorithm");
Myinit(); //初始设置
glutDisplayFunc(Display); //注册绘制响应回调函数
glutKeyboardFunc(Keyboard); //注册键盘响应回调函数
glutReshapeFunc(Reshape); //注册窗口改变回调函数
glutMouseFunc(myMouse); //注册鼠标按钮回调函数
glutMotionFunc(myMotion); //注册鼠标移动回调函数
glutMainLoop();
return 0;
}
void Myinit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0); //背景色
glLineWidth(4.0); //线宽
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //设置矩阵模式为模型变换模式,表示在世界坐标系下
glLoadIdentity(); //将当前矩阵设置为单位矩阵
if (flag == 1) //画圆
Bresenham_Circle_Algorithm(cx, cy, radius);
if (flag == 2) //画多边形
NSidedPolygon(n, cx, cy, radius);
if (flag == 3) //画胖圆
SampleCircle(ri, radius, samples, cx, cy);
if (flag == 4) //鼠标划线
Drawlines();
if (flag == 5)
DDA_Drawlines();//DDA画直线
if (flag == 6)
{
drawCircle();//bresenham中心画圆法
}
if (flag == 7)
{
Bresenham_Drawlines();//bresenham画直线
}
glutSwapBuffers();
}
void Keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case