使用异或模式画橡皮线
来源:互联网 发布:马克斯cms下载 编辑:程序博客网 时间:2024/05/11 04:58
#include <gl/glut.h>
int iPointNum = 0; //已确定点的数目
int x1=0,x2=0,y1=0,y2=0; //确定的点坐标
int tempPoint[2];
int winWidth = 500, winHeight =500; //窗口的宽度和高度
void Initial(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
}
void ChangeSize(int w, int h)
{
winWidth = w; winHeight = h;
glViewport(0, 0, w, h); //指定窗口显示区域
glMatrixMode(GL_PROJECTION); //设置投影参数
glLoadIdentity();
gluOrtho2D(0.0,winWidth,0.0,winHeight);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
if(iPointNum ==1) {
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
tempPoint[0]=x2;
tempPoint[1]=y2;
iPointNum =2;
glFlush();
}
else
{
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(tempPoint[0],tempPoint[1]);
glEnd();
glFlush();
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
tempPoint[0]=x2;
tempPoint[1]=y2;
glFlush();
}
}
void MousePlot(GLint button, GLint action, GLint xMouse, GLint yMouse)
{
if(button == GLUT_LEFT_BUTTON && action == GLUT_DOWN) {
if(iPointNum == 0 || iPointNum == 2){
iPointNum = 1;
x1 = xMouse; y1 = winHeight - yMouse;
}
else {
iPointNum = 2;
x2 = xMouse; y2 = winHeight - yMouse;
glutPostRedisplay(); //指定窗口重新绘制
}
}
if(button == GLUT_RIGHT_BUTTON && action == GLUT_DOWN){
iPointNum = 0;
glutPostRedisplay();
}
}
void PassiveMouseMove (GLint xMouse, GLint yMouse)
{
if(iPointNum == 1)
{
x2 = xMouse;
y2 = winHeight - yMouse;
glutPostRedisplay();
}
else if(iPointNum == 2)
{
x2 = xMouse;
y2 = winHeight - yMouse;
glutPostRedisplay();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //使用单缓存及RGB模型
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("异或模式橡皮线");
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize); //指定窗口在整形回调函数
glutMouseFunc(MousePlot); //指定鼠标响应函数
glutPassiveMotionFunc(PassiveMouseMove); //指定鼠标移动响应函数
Initial();
glutMainLoop();
}
int iPointNum = 0; //已确定点的数目
int x1=0,x2=0,y1=0,y2=0; //确定的点坐标
int tempPoint[2];
int winWidth = 500, winHeight =500; //窗口的宽度和高度
void Initial(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
}
void ChangeSize(int w, int h)
{
winWidth = w; winHeight = h;
glViewport(0, 0, w, h); //指定窗口显示区域
glMatrixMode(GL_PROJECTION); //设置投影参数
glLoadIdentity();
gluOrtho2D(0.0,winWidth,0.0,winHeight);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
if(iPointNum ==1) {
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
tempPoint[0]=x2;
tempPoint[1]=y2;
iPointNum =2;
glFlush();
}
else
{
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(tempPoint[0],tempPoint[1]);
glEnd();
glFlush();
glBegin(GL_LINES); //绘制直线段
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
tempPoint[0]=x2;
tempPoint[1]=y2;
glFlush();
}
}
void MousePlot(GLint button, GLint action, GLint xMouse, GLint yMouse)
{
if(button == GLUT_LEFT_BUTTON && action == GLUT_DOWN) {
if(iPointNum == 0 || iPointNum == 2){
iPointNum = 1;
x1 = xMouse; y1 = winHeight - yMouse;
}
else {
iPointNum = 2;
x2 = xMouse; y2 = winHeight - yMouse;
glutPostRedisplay(); //指定窗口重新绘制
}
}
if(button == GLUT_RIGHT_BUTTON && action == GLUT_DOWN){
iPointNum = 0;
glutPostRedisplay();
}
}
void PassiveMouseMove (GLint xMouse, GLint yMouse)
{
if(iPointNum == 1)
{
x2 = xMouse;
y2 = winHeight - yMouse;
glutPostRedisplay();
}
else if(iPointNum == 2)
{
x2 = xMouse;
y2 = winHeight - yMouse;
glutPostRedisplay();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //使用单缓存及RGB模型
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("异或模式橡皮线");
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize); //指定窗口在整形回调函数
glutMouseFunc(MousePlot); //指定鼠标响应函数
glutPassiveMotionFunc(PassiveMouseMove); //指定鼠标移动响应函数
Initial();
glutMainLoop();
}
- 使用异或模式画橡皮线
- 画橡皮线
- 使用双缓存作出的橡皮线
- 双缓存画橡皮线解决闪屏
- AE中的橡皮线
- 画笔的异或模式
- 异或的使用
- 异或的使用
- grep 或 egrep 或awk 过滤两个或多个关键词|使用grep匹配“与”或者“或”模式
- grep 或 egrep 或awk 过滤两个或多个关键词|使用grep匹配“与”或者“或”模式
- grep 或 egrep 或awk 过滤两个或多个关键词|使用grep匹配“与”或者“或”模式
- 使用showModalDialog或同等的模式框方法的问题
- 责任链或过滤器模式1-使用过滤器
- 责任链或过滤器模式2-使用过滤链
- 配置Hive使用嵌入式derby或客服模式derby方法
- 责任链或过滤器模式1-使用过滤器
- 责任链或过滤器模式2-使用过滤链
- 如何使用 awk 按模式筛选文本或字符串
- 黑马程序员-高新技术day 2
- 关于SSH框架的集群,负载均衡,以及缓存集群的配置搭建
- uboot 分析之二 start_armboot
- Zend Studio 快捷键,支持7.0以上的版本
- 【堆+区间DP】Orz细菌(orz)
- 使用异或模式画橡皮线
- ASP.net性能优化
- Linux USB 鼠标驱动程序解析
- 键盘KeyCode值列表
- Java注释(Annotation)详解
- 理解 JavaScript 的 this 关键字(代码)
- 使用双缓存作出的橡皮线
- 自定义继承自ProfileBase的Profile
- vc中调用exe文件并传递参数