opengl学习之 编码裁剪法


#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值