freeglut
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <iostream> #include <gl/glut.h> using namespace std; struct Point { int x; int y; }; // #define VERTEX_COUNT 5 Point points[VERTEX_COUNT] = { 103, 273, 516, 273, 184, 32, 308, 452, 439, 32 }; // void draw_dda(Point p1, Point p2) { GLfloat dx = p2.x - p1.x; GLfloat dy = p2.y - p1.y; GLfloat x1 = p1.x; GLfloat y1 = p1.y; GLfloat step = 0; if ( abs (dx) > abs (dy)) { step = abs (dx); } else { step = abs (dy); } GLfloat xInc = dx/step; GLfloat yInc = dy/step; for ( float i = 1; i <= step; i++) { glVertex2i(x1, y1); x1 += xInc; y1 += yInc; } } void init() { glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(0.0f, 0.0f, 0.0f); gluOrtho2D(0.0, 640.0, 0.0, 480.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glPointSize(1.0f); } void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); Point stPoint = points[0]; for ( int i = 1; i < VERTEX_COUNT; i++) { draw_dda(stPoint, points[i]); stPoint = points[i]; } draw_dda(stPoint, points[0]); glEnd(); glFlush(); } int main( int argc, char ** argv) { glutInit(&argc, argv); glutInitWindowPosition(400, 200); glutInitWindowSize(640, 480); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow( "OpenGL" ); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2022-05-30 计算机学习启蒙
2022-05-30 RSA算法的数学基础