scanline.cpp
来自「经典算法实现」· C++ 代码 · 共 51 行
CPP
51 行
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include "Scan.h"
void myInit();
void setPixel(int x, int y);
void myDisplay();
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition (100, 150);
glutCreateWindow("SweepLine");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
void setPixel(int x, int y) {
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
void myInit() {
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void myDisplay() {
int i, j;
glClear(GL_COLOR_BUFFER_BIT);
int p[5][2];
p[0][0] = 100; p[0][1] = 300;
p[1][0] = 200; p[1][1] = 50;
p[2][0] = 300; p[2][1] = 100;
p[3][0] = 400; p[3][1] = 0;
p[4][0] = 350; p[4][1] = 470;
sweep(p, 5, setPixel);
glFlush();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?