forked from EpsOnlineEducation/ComputerGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToMauduongbien.cpp
70 lines (63 loc) · 1.62 KB
/
ToMauduongbien.cpp
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
#include <math.h>
#include <time.h>
#include <GL/glut.h>
void init()
{
glClearColor(2.0,1.0,1.0,0.0);
glOrtho(0,640,0,480,-1,1);
}
void bound_it(int x, int y, float* fillColor, float* bc)
{
float color[3];
glReadPixels(x,y,1.0,1.0,GL_RGB,GL_FLOAT,color);
if((color[0]!=bc[0] || color[1]!=bc[1] || color[2]!=bc[2])&&(
color[0]!=fillColor[0] || color[1]!=fillColor[1] || color[2]!=fillColor[2]))
{
glColor3f(fillColor[0],fillColor[1],fillColor[2]);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
bound_it(x+1,y,fillColor,bc);
bound_it(x-1,y,fillColor,bc);
bound_it(x,y+1,fillColor,bc);
bound_it(x,y-1,fillColor,bc);
}
}
void mouse(int btn, int state, int x, int y)
{
y = 480-y;
if(btn==GLUT_LEFT_BUTTON)
{
if(state==GLUT_DOWN)
{
float bCol[] = {1,0,0};
float color[] = {0,0,1};
bound_it(x,y,color,bCol);
}
}
}
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_LINE_LOOP);
glVertex2i(100,400);
glVertex2i(300,400);
glVertex2i(150,200);
glVertex2i(10,300);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Boundary Fill");
glutDisplayFunc(mydisplay);
glutMouseFunc(mouse);
init();
glutMainLoop();
return 0;
}