用鼠标左键按下确定直线起点,鼠标左键抬起确定直线终点。放一部分代码。
// 中点Bresenham算法.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <GL/glut.h> #include <iostream> #include <cmath> int windowWidth = 800; int windowHeight = 600; int startX, startY, endX, endY; bool isDrawing = false; void setPixel(int x, int y, float r, float g, float b) { glColor3f(r, g, b); glPointSize(5);//设置点的大小 glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); } void drawLine(int x0, int y0, int x1, int y1, float r0, float g0, float b0, float r1, float g1, float b1) { } void display() { glClear(GL_COLOR_BUFFER_BIT); glFlush(); } void mouse(int button, int state, int x, int y) { } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow("Color Gradient Line Drawing"); glClearColor(0.0, 0.0, 0.0, 1.0); gluOrtho2D(0, windowWidth, 0, windowHeight); glutDisplayFunc(display); glutMouseFunc(mouse); glutMainLoop(); return 0; }