Lập trình đồ họa bằng visual C++
Số trang: 8
Loại file: doc
Dung lượng: 45.00 KB
Lượt xem: 19
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tài liệu lập trình đồ họa bằng visual C++
Nội dung trích xuất từ tài liệu:
Lập trình đồ họa bằng visual C++Muốn lập trình đồ họa bằng visual C++ 6.0 thì cần phải có các thư viện bổ sung sau:Nhấn vào đây để down về (http://www.fileden.com/files/2008/1/19/1707613/glut.rar)Giải nén và chép tất cả vào trong thư mục project của bạn đang làm việcBài 1: Lập trình chương trình vẽ hình vuông// Bo qua man hinh Console#pragma comment( linker, /subsystem:windows /entry:mainCRTStartup )#include #include glut.h#include iostream.h#include afxwin.h#include // kich thuoc, vi tri cua so#define windowWidth 640#define windowHeight 480#define startX 0#define startY 0// hang so PI#define M_PI 3.14159265358979// macro doi tu do --> radian#define RAD(goc) ((goc)*(M_PI/180.0))// cau truc 1 thanh phan mau theo RGBstruct colorentry {unsigned char red;unsigned char green;unsigned char blue;colorentry(int r, int g, int b):red(r),green(g), blue(b){};};// ham khoi taovoid Init();// !!! ham ve (tat ca thao tac ve nam trong ham nay)void Display();// ham ve lai moi khi cua so thay doi kich thuocvoid Reshape(int Width,int Height);// ham xu ly ban phimvoid OnKey(unsigned char key,int x, int y);// ham ve duong thangvoid DrawLine(int x1, int y1, int x2,int y2, colorentry c);// ham ve diemvoid PutPixel(int x, int y, colorentry c);// ham ve hinh vuongvoid DrawSquare(int x0, int y0, int w, colorentry c);int main(int argc, char* argv[]){// Khoi tap cua so OpenGLglutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowSize(windowWidth, windowHeight);glutInitWindowPosition(startX, startY);glutCreateWindow(Draw Square Demo);// Cac thao tac khoi taoInit();// Dang ky ham DisplayglutDisplayFunc(Display);// Dang ky ham ReshapeglutReshapeFunc(Reshape);// Dang ky ham OnKeyglutKeyboardFunc(OnKey);// Vong lap su kienglutMainLoop();// Ket thucreturn 0;}void Init(){glClearColor(0.0,0.0,0.0,0.0);}int w=100;void Display(){// Xoa de bat dau veglClear(GL_COLOR_BUFFER_BIT);// !!! Cac thao tac veint xMax = glutGet(GLUT_WINDOW_WIDTH);int yMax = glutGet(GLUT_WINDOW_HEIGHT);DrawSquare(xMax/2,yMax/2,w,colorentry(255,255,0));PutPixel(xMax/2,yMax/2,colorentry(255,0,0));// Ket xuat ra man hinhglFlush();}void Reshape(int Width,int Height){glViewport(0, 0 , (GLsizei)Width,(GLsizei)Height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0,(GLdouble)Width,0, (GLdouble)Height);}void OnKey(unsigned char key,int x, int y){switch(key){case +:w+=10;break;case -:w=w-10;break;case 27: // (ESC)exit(0);break;}glutPostRedisplay();}void DrawLine(int x1, int y1, int x2,int y2, colorentry c){glBegin(GL_LINES);glColor3ub(c.red,c.green,c.blue);glVertex2f(x1,y1);glVertex2f(x2,y2);glEnd();}void PutPixel(int x, int y, colorentry c){glPointSize(2.0);glBegin(GL_POINTS);glColor3ub(c.red,c.green,c.blue);glVertex2f(x,y);glEnd();}void DrawSquare(int x0, int y0, int w, colorentry c){int pos[][2] = { {-w,w},{w,w},{w,-w},{-w,-w},{-w,w} };for(int i=0;i}Đây là toàn bộ soure code để vẽ hình vuông trong VC++ 6.0. Tất cả đều có chú thích đầy đủ.quangtp30-04-2008, 01:44 AManh oi , cho em pass giải nén được ko ? anh co code vẽ cả bàn cờ vua ko cho e xin mới ah .emđang cần gấp . có gì anh gửi vào hòm thư cho e : bu_ra_ti_no_5678@yahoo.com.vnfinalfantasy30-04-2008, 09:40 AMSr em nha. Pass để giải nén là www.binhphu.info. Còn về code của bàn cờ vua thì anh chưa có.Anh sẽ cố gắng vẽ trong thời gian nhanh nhất để post lên cho em tải về. Mà chỉ cần vẽ bàncờ vua thôi phải ko em? Đâu có vẽ mấy con cờ trên đó phải hem?:Dfinalfantasy30-04-2008, 01:36 PMĐây là source code của bàn cờ vua nè.// Bo qua man hinh Console#pragma comment( linker, /subsystem:windows /entry:mainCRTStartup )#include #include glut.h#include // kich thuoc, vi tri cua so#define windowWidth 640#define windowHeight 480#define startX 0#define startY 0// hang so PI#define M_PI 3.14159265358979// macro doi tu do --> radian#define RAD(goc) ((goc)*(M_PI/180.0))// ham khoi taovoid Init();// !!! ham ve (tat ca thao tac ve nam trong ham nay)void Display();// ham ve lai moi khi cua so thay doi kich thuocvoid Reshape(int Width,int Height);// ham xu ly Idlevoid OnIdle();void DrawSquareBlack(int x0,int y0,int d);void DrawSquareWhite(int x0,int y0,int d);void DrawChessBoard(int xc,int yc);int main(int argc, char* argv[]){// Khoi tap cua so OpenGLglutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowSize(windowWidth, windowHeight);glutInitWindowPosition(startX, startY);glutCreateWindow(Chess Board);// Cac thao tac khoi taoInit();// Dang ky ham DisplayglutDisplayFunc(Display);// Dang ky ham ReshapeglutReshapeFunc(Reshape);// Dang ky ham OnIdleglutIdleFunc(OnIdle);// Vong lap su kienglutMainLoop();// Ket thucreturn 0;}void Init(){glClearColor(0.0,0.0,0.0,0.0);}void Display(){// Xoa de bat dau veglClear(GL_COLOR_BUFFER_BIT);// ...
Nội dung trích xuất từ tài liệu:
Lập trình đồ họa bằng visual C++Muốn lập trình đồ họa bằng visual C++ 6.0 thì cần phải có các thư viện bổ sung sau:Nhấn vào đây để down về (http://www.fileden.com/files/2008/1/19/1707613/glut.rar)Giải nén và chép tất cả vào trong thư mục project của bạn đang làm việcBài 1: Lập trình chương trình vẽ hình vuông// Bo qua man hinh Console#pragma comment( linker, /subsystem:windows /entry:mainCRTStartup )#include #include glut.h#include iostream.h#include afxwin.h#include // kich thuoc, vi tri cua so#define windowWidth 640#define windowHeight 480#define startX 0#define startY 0// hang so PI#define M_PI 3.14159265358979// macro doi tu do --> radian#define RAD(goc) ((goc)*(M_PI/180.0))// cau truc 1 thanh phan mau theo RGBstruct colorentry {unsigned char red;unsigned char green;unsigned char blue;colorentry(int r, int g, int b):red(r),green(g), blue(b){};};// ham khoi taovoid Init();// !!! ham ve (tat ca thao tac ve nam trong ham nay)void Display();// ham ve lai moi khi cua so thay doi kich thuocvoid Reshape(int Width,int Height);// ham xu ly ban phimvoid OnKey(unsigned char key,int x, int y);// ham ve duong thangvoid DrawLine(int x1, int y1, int x2,int y2, colorentry c);// ham ve diemvoid PutPixel(int x, int y, colorentry c);// ham ve hinh vuongvoid DrawSquare(int x0, int y0, int w, colorentry c);int main(int argc, char* argv[]){// Khoi tap cua so OpenGLglutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowSize(windowWidth, windowHeight);glutInitWindowPosition(startX, startY);glutCreateWindow(Draw Square Demo);// Cac thao tac khoi taoInit();// Dang ky ham DisplayglutDisplayFunc(Display);// Dang ky ham ReshapeglutReshapeFunc(Reshape);// Dang ky ham OnKeyglutKeyboardFunc(OnKey);// Vong lap su kienglutMainLoop();// Ket thucreturn 0;}void Init(){glClearColor(0.0,0.0,0.0,0.0);}int w=100;void Display(){// Xoa de bat dau veglClear(GL_COLOR_BUFFER_BIT);// !!! Cac thao tac veint xMax = glutGet(GLUT_WINDOW_WIDTH);int yMax = glutGet(GLUT_WINDOW_HEIGHT);DrawSquare(xMax/2,yMax/2,w,colorentry(255,255,0));PutPixel(xMax/2,yMax/2,colorentry(255,0,0));// Ket xuat ra man hinhglFlush();}void Reshape(int Width,int Height){glViewport(0, 0 , (GLsizei)Width,(GLsizei)Height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0,(GLdouble)Width,0, (GLdouble)Height);}void OnKey(unsigned char key,int x, int y){switch(key){case +:w+=10;break;case -:w=w-10;break;case 27: // (ESC)exit(0);break;}glutPostRedisplay();}void DrawLine(int x1, int y1, int x2,int y2, colorentry c){glBegin(GL_LINES);glColor3ub(c.red,c.green,c.blue);glVertex2f(x1,y1);glVertex2f(x2,y2);glEnd();}void PutPixel(int x, int y, colorentry c){glPointSize(2.0);glBegin(GL_POINTS);glColor3ub(c.red,c.green,c.blue);glVertex2f(x,y);glEnd();}void DrawSquare(int x0, int y0, int w, colorentry c){int pos[][2] = { {-w,w},{w,w},{w,-w},{-w,-w},{-w,w} };for(int i=0;i}Đây là toàn bộ soure code để vẽ hình vuông trong VC++ 6.0. Tất cả đều có chú thích đầy đủ.quangtp30-04-2008, 01:44 AManh oi , cho em pass giải nén được ko ? anh co code vẽ cả bàn cờ vua ko cho e xin mới ah .emđang cần gấp . có gì anh gửi vào hòm thư cho e : bu_ra_ti_no_5678@yahoo.com.vnfinalfantasy30-04-2008, 09:40 AMSr em nha. Pass để giải nén là www.binhphu.info. Còn về code của bàn cờ vua thì anh chưa có.Anh sẽ cố gắng vẽ trong thời gian nhanh nhất để post lên cho em tải về. Mà chỉ cần vẽ bàncờ vua thôi phải ko em? Đâu có vẽ mấy con cờ trên đó phải hem?:Dfinalfantasy30-04-2008, 01:36 PMĐây là source code của bàn cờ vua nè.// Bo qua man hinh Console#pragma comment( linker, /subsystem:windows /entry:mainCRTStartup )#include #include glut.h#include // kich thuoc, vi tri cua so#define windowWidth 640#define windowHeight 480#define startX 0#define startY 0// hang so PI#define M_PI 3.14159265358979// macro doi tu do --> radian#define RAD(goc) ((goc)*(M_PI/180.0))// ham khoi taovoid Init();// !!! ham ve (tat ca thao tac ve nam trong ham nay)void Display();// ham ve lai moi khi cua so thay doi kich thuocvoid Reshape(int Width,int Height);// ham xu ly Idlevoid OnIdle();void DrawSquareBlack(int x0,int y0,int d);void DrawSquareWhite(int x0,int y0,int d);void DrawChessBoard(int xc,int yc);int main(int argc, char* argv[]){// Khoi tap cua so OpenGLglutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowSize(windowWidth, windowHeight);glutInitWindowPosition(startX, startY);glutCreateWindow(Chess Board);// Cac thao tac khoi taoInit();// Dang ky ham DisplayglutDisplayFunc(Display);// Dang ky ham ReshapeglutReshapeFunc(Reshape);// Dang ky ham OnIdleglutIdleFunc(OnIdle);// Vong lap su kienglutMainLoop();// Ket thucreturn 0;}void Init(){glClearColor(0.0,0.0,0.0,0.0);}void Display(){// Xoa de bat dau veglClear(GL_COLOR_BUFFER_BIT);// ...
Tìm kiếm theo từ khóa liên quan:
giáo trình đồ họa thiết kế đồ họa lập trình đồ họa lập trình đồ học bằng visual C++ tài liệu lập trình đồ hoạGợi ý tài liệu liên quan:
-
Đề cương chi tiết học phần Thiết kế đồ họa (Graphic Designer)
12 trang 538 2 0 -
Đồ án tốt nghiệp Thiết kế đồ họa: Cụm thiết kế đồ họa quảng cáo cho shop giày Denah Sneaker
39 trang 275 0 0 -
5 trang 266 2 0
-
Ý tưởng lớn trong kỹ thuật thiết kế đồ họa: Phần 1
92 trang 264 1 0 -
60 trang 233 1 0
-
Đồ án tốt nghiệp: Thiết kế nội thất khách sạn thuyền buồm
21 trang 198 0 0 -
Bài giảng Lập trình Java căn bản: Chương 7 - ThS. Võ Đức Cẩm Hải
29 trang 190 0 0 -
43 trang 185 1 0
-
Tóm tắt Đồ án tốt nghiệp Thiết kế đồ họa: Cụm thiết kế đồ họa quảng bá hiệp hội bảo vệ động vật Peta
33 trang 178 1 0 -
182 trang 172 0 0