Tài liệu Lập trình đồ họa bằng visual C++ - Pdf 86

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ệc
Bà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 <stdio.h>
#include "glut.h"
#include "iostream.h"
#include "afxwin.h"
#include <math.h>
// 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 RGB
struct 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 tao
void Init();
// !!! ham ve (tat ca thao tac ve nam trong ham nay)
void Display();

}
void Init()
{
glClearColor(0.0,0.0,0.0,0.0);
}
int w=100;
void Display()
{
// Xoa de bat dau ve
glClear(GL_COLOR_BUFFER_BIT);
// !!! Cac thao tac ve
int 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 hinh
glFlush();
}
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 '+':

for(int i=0;i<4;i++)
{
int x1 = x0 + pos[i][0];
int y1 = y0 + pos[i][1];
int x2 = x0 + pos[i+1][0];
int y2 = y0 + pos[i+1][1];
DrawLine(x1,y1,x2,y2,c);
}
}
Đâ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 đủ.
quangtp
30-04-2008, 01:44 AM
anh 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 : [email protected]
finalfantasy
30-04-2008, 09:40 AM
Sr 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àn cờ vua
thôi phải ko em? Đâu có vẽ mấy con cờ trên đó phải hem?:D
finalfantasy
30-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 <stdio.h>
#include "glut.h"
#include <math.h>
// kich thuoc, vi tri cua so
#define windowWidth 640
#define windowHeight 480

glutReshapeFunc(Reshape);
// Dang ky ham OnIdle
glutIdleFunc(OnIdle);
// Vong lap su kien
glutMainLoop();
// Ket thuc
return 0;
}
void Init()
{
glClearColor(0.0,0.0,0.0,0.0);
}
void Display()
{
// Xoa de bat dau ve
glClear(GL_COLOR_BUFFER_BIT);
// !!! Cac thao tac ve
int xMax = glutGet(GLUT_WINDOW_WIDTH);
int yMax = glutGet(GLUT_WINDOW_HEIGHT);
DrawChessBoard(xMax/2,yMax/2);
// Ket xuat ra man hinh
glFlush();
glutSwapBuffers();
}
void OnIdle()


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status