#include "stdafx.h"
#include "编码裁剪法.h"
//鼠标画线小程序
#include <glut.h>
#define N 1000 //maximum line numbers
int ww, hh; // for display window width and height
int line[N][4], k = 0; //for line's endpoint coordinates and line number
int flag = 1;
int xa, ya, xb, yb; //矩形两个对角线的坐标
class wcPt2D { public: float x, y; };
wcPt2D p1, p2, winMin, winMax;
void Myinit(void);
void Reshape(int w, int h);
void myMouse(int button, int state, int x, int y);
void myMotion(int x, int y);
void Display(void);
void drawlines();
void mykeyboard(unsigned char key, int x, int y);
void drawbox();
void drawcliplines();
void LBLineClip(float xleft, float xright, float ybottom, float ytop, float x1, float y1, float x2, float y2);
bool LBclipTest(float p, float q, float& u1, float& u2);
GLubyte encode(wcPt2D pt, wcPt2D winMin, wcPt2D winMax);
void swapPts(wcPt2D *p1, wcPt2D *p2);
void swapCodes(GLubyte *c1, GLubyte *c2);
void lineClipCohSuth(wcPt2D winMin, wcPt2D winMax, wcPt2D p1, wcPt2D p2);
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); //初始化GLUT库;
glutInitWindowSize(800, 600); //设置显示窗口大小
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //设置显示模式;(注意双缓冲)
glutCreateWindow("鼠标画线小程序演示"); // 创建显示窗口
Myinit();
glutDisplayFunc(Display); //注册显示回调函数
glutMouseFunc(myMouse); //注册鼠标按钮回调函数
glutMotionFunc(myMotion); //注册鼠标移动回调函数
glutReshapeFunc(Reshape); //注册窗口改变回调函数
glutKeyboardFunc(mykeyboard); //注册键盘回调函数
glutMainLoop(); //进入事件处理循环
return 0;
}
void Myinit(void)
{
//glPolygonMode(GL_FRONT, GL_LINE);
glClearColor(0.0, 0.0, 0.0, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glLineWidth(3.0);
}
//渲染绘制子程序--------------------------------------------------------------------------
void Display(void)
{
gl