When we control the event,we control your lives
 
IndexTrợ giúpTìm kiếmThành viênNhómĐăng kýĐăng Nhập
Tìm kiếm
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» Tô màu theo vùng quét
Tue Aug 13, 2013 4:18 pm by minhlap

» authentischen Hermes Lindy Taschen
Wed Jan 23, 2013 11:15 am by cangliang

» Hermes Bag
Wed Jan 23, 2013 11:14 am by cangliang

» Hermes Evelyn pm
Wed Jan 23, 2013 11:13 am by cangliang

» Hermes Kelly bag billig
Mon Jan 21, 2013 8:57 am by cangliang

» Hermes Constance Bag
Mon Jan 21, 2013 8:56 am by cangliang

» Discout Hermes Belt
Mon Jan 21, 2013 8:55 am by cangliang

» Christian Louboutin Love Flats
Tue Jan 15, 2013 12:25 pm by cangliang

» Christian Louboutin Love Flats
Tue Jan 15, 2013 12:25 pm by cangliang

Navigation
 Portal
 Diễn Đàn
 Thành viên
 Lý lịch
 Trợ giúp
 Tìm kiếm
December 2016
MonTueWedThuFriSatSun
   1234
567891011
12131415161718
19202122232425
262728293031 
CalendarCalendar
Diễn Đàn
Affiliates
free forum


Share | 
 

 to mau de qui

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
minhlap
Admin - Quản trị viên
Admin - Quản trị viên


Tổng số bài gửi : 129
Points : 374
Reputation : 5
Join date : 22/07/2009
Age : 27
Đến từ : TP Hồ Chí Minh

Bài gửiTiêu đề: to mau de qui   Sat Dec 12, 2009 7:02 pm

#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#include
#include"math.h"
#include "glut.h"
#define Round(x) int(x+0.5)
int width,height,xc,yc,xi,yi;

struct Colorentry
{
GLubyte Red;
GLubyte Blue;
GLubyte Green;
Colorentry() {Red=Green=Blue=0; }
Colorentry(GLbyte R,GLbyte G,GLbyte B)
{
Red=R;
Green=G;
Blue=B;
}
int operator==(Colorentry &c)
{
return (Red==c.Red && Green==c.Green && Blue==c.Blue);
}
int operator!=(Colorentry &c)
{
return !(*this==c);
}
};

void PutPixel(int x,int y,Colorentry c)
{
glColor3ub(c.Red,c.Green,c.Blue);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
void PutPixel(int x,int y)
{
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
Colorentry GetPixel(int x,int y)
{
GLbyte color[3];
float Pos[4];
glRasterPos2d(x,y);
glGetFloatv(GL_CURRENT_RASTER_POSITION,Pos);
glReadPixels(Pos[0],Pos[1],1,1,GL_RGB,GL_UNSIGNED_BYTE,color);
return Colorentry(color[0],color[1],color[2]);
}
void Fillleft(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor);
void Fillright(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor);
void Filltop(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor);
void Fillbottom(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor);

void Fillleft(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor)
{
Colorentry color=GetPixel(x,y);
if(color!=Fillcolor && color!= Boundarycolor)
{
PutPixel(x,y,Fillcolor);
Fillleft (x-1, y , Fillcolor, Boundarycolor);
Filltop (x , y+1, Fillcolor, Boundarycolor);
Fillbottom (x , y-1, Fillcolor, Boundarycolor);
}
}
void Fillright(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor)
{
Colorentry color=GetPixel(x,y);
if(color!=Fillcolor && color!= Boundarycolor)
{
PutPixel(x,y,Fillcolor);
Fillright (x+1, y , Fillcolor, Boundarycolor);
Filltop (x , y+1, Fillcolor, Boundarycolor);
Fillbottom (x , y-1, Fillcolor, Boundarycolor);
}
}
void Filltop(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor)
{
Colorentry color=GetPixel(x,y);
if(color!=Fillcolor && color!= Boundarycolor)
{
PutPixel(x,y,Fillcolor);
Fillleft (x-1, y , Fillcolor, Boundarycolor);
Fillright (x+1, y , Fillcolor, Boundarycolor);
Filltop (x , y+1, Fillcolor, Boundarycolor);

}
}
void Fillbottom(int x,int y,Colorentry Fillcolor,Colorentry Boundarycolor)
{
Colorentry color=GetPixel(x,y);
if(color!=Fillcolor && color!= Boundarycolor)
{
PutPixel(x,y,Fillcolor);
Fillleft (x-1, y , Fillcolor, Boundarycolor);
Fillright (x+1, y , Fillcolor, Boundarycolor);
Fillbottom (x , y-1, Fillcolor, Boundarycolor);
}
}
void BundaryFill(int x, int y, Colorentry Fillcolor, Colorentry Boundarycolor)
{
Colorentry color=GetPixel(x,y);
if(color != Fillcolor && color != Boundarycolor)
{
PutPixel(x,y,Fillcolor);
Fillleft (x-1, y , Fillcolor, Boundarycolor);
Fillright (x+1, y , Fillcolor, Boundarycolor);
Filltop (x , y+1, Fillcolor, Boundarycolor);
Fillbottom (x , y-1, Fillcolor, Boundarycolor);
}
}
void DrawRectangle_Rotate(int xc,int yc,int a, int b)
{
int dPoints[][2] = { {-a,b},{a,b},{a,-b},{-a,-b} };
int n = 4;
int x,y;
glBegin(GL_LINE_LOOP);

for(int i=0;i {
x = xc + dPoints[i][0];
y = yc + dPoints[i][1];
glVertex2f(x,y);
}
glEnd();
}
void test()
{
DrawRectangle_Rotate(xc,yc,30,20);
Colorentry a(255,255,0);
Colorentry b(255,0,0);
BundaryFill(xc,yc,a,b);
}
//-----------------------------------
void myInit()
{
width=glutGet(GLUT_WINDOW_WIDTH);
height=glutGet(GLUT_WINDOW_HEIGHT);
xc=width/2;
yc=height/2;
}
void mydraw()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(255,0,0);
test();
glFlush();
glutSwapBuffers();
}
void onkey(unsigned char key,int x,int y)
{
switch(key)
{
case 27:
exit(0);
}
}
void OnSize(int width,int height)
{
glViewport(0, 0 , (GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,(GLdouble)width,0, (GLdouble)height);
}

void main()
{
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,480);
glutCreateWindow("hello");
myInit();
glutDisplayFunc(mydraw);
glutReshapeFunc(OnSize);
glutKeyboardFunc(onkey);
glutMainLoop();
}

_________________
minhlapit
Về Đầu Trang Go down
Xem lý lịch thành viên http://minhlap.allgoo.us
 
to mau de qui
Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 
Trang 1 trong tổng số 1 trang

Permissions in this forum:Bạn không có quyền trả lời bài viết
minhlap.allgoo.us :: Lập trình :: Lập Trình Hướng Đối Tượng,Đồ Họa OpenGL C, C++-
Chuyển đến