亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? demo8_3.cpp

?? 一本外國人寫的關(guān)于3D游戲編程的書的源碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號(hào):

int Draw_Line(int x0, int y0, // starting position 
              int x1, int y1, // ending position
              UCHAR color,    // color index
              UCHAR *vb_start, int lpitch) // video buffer and memory pitch
{
// this function draws a line from xo,yo to x1,y1 using differential error
// terms (based on Bresenahams work)

int dx,             // difference in x's
    dy,             // difference in y's
    dx2,            // dx,dy * 2
    dy2, 
    x_inc,          // amount in pixel space to move during drawing
    y_inc,          // amount in pixel space to move during drawing
    error,          // the discriminant i.e. error i.e. decision variable
    index;          // used for looping

// pre-compute first pixel address in video buffer
vb_start = vb_start + x0 + y0*lpitch;

// compute horizontal and vertical deltas
dx = x1-x0;
dy = y1-y0;

// test which direction the line is going in i.e. slope angle
if (dx>=0)
   {
   x_inc = 1;

   } // end if line is moving right
else
   {
   x_inc = -1;
   dx    = -dx;  // need absolute value

   } // end else moving left

// test y component of slope

if (dy>=0)
   {
   y_inc = lpitch;
   } // end if line is moving down
else
   {
   y_inc = -lpitch;
   dy    = -dy;  // need absolute value

   } // end else moving up

// compute (dx,dy) * 2
dx2 = dx << 1;
dy2 = dy << 1;

// now based on which delta is greater we can draw the line
if (dx > dy)
   {
   // initialize error term
   error = dy2 - dx; 

   // draw the line
   for (index=0; index <= dx; index++)
       {
       // set the pixel
       *vb_start = color;

       // test if error has overflowed
       if (error >= 0) 
          {
          error-=dx2;

          // move to next line
          vb_start+=y_inc;

	   } // end if error overflowed

       // adjust the error term
       error+=dy2;

       // move to the next pixel
       vb_start+=x_inc;

       } // end for

   } // end if |slope| <= 1
else
   {
   // initialize error term
   error = dx2 - dy; 

   // draw the line
   for (index=0; index <= dy; index++)
       {
       // set the pixel
       *vb_start = color;

       // test if error overflowed
       if (error >= 0)
          {
          error-=dy2;

          // move to next line
          vb_start+=x_inc;

          } // end if error overflowed

       // adjust the error term
       error+=dx2;

       // move to the next pixel
       vb_start+=y_inc;

       } // end for

   } // end else |slope| > 1

// return success
return(1);

} // end Draw_Line

///////////////////////////////////////////////////////////////

LRESULT CALLBACK WindowProc(HWND hwnd, 
						    UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT		ps;		// used in WM_PAINT
HDC				hdc;	// handle to a device context
char buffer[80];        // used to print strings

// what is the message 
switch(msg)
	{	
	case WM_CREATE: 
        {
		// do initialization stuff here
        // return success
		return(0);
		} break;
   
	case WM_PAINT: 
		{
		// simply validate the window 
   	    hdc = BeginPaint(hwnd,&ps);	 
        
        // end painting
        EndPaint(hwnd,&ps);

        // return success
		return(0);
   		} break;

	case WM_DESTROY: 
		{

		// kill the application, this sends a WM_QUIT message 
		PostQuitMessage(0);

        // return success
		return(0);
		} break;

	default:break;

    } // end switch

// process any messages that we didn't take care of 
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

///////////////////////////////////////////////////////////

int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here

// make sure this isn't executed again
if (window_closed)
   return(0);

// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
   {
   PostMessage(main_window_handle,WM_CLOSE,0,0);
   window_closed = 1;
   } // end if

// clear out the back buffer
DDraw_Fill_Surface(lpddsback, 0);

// lock primary buffer
DDRAW_INIT_STRUCT(ddsd);

if (FAILED(lpddsback->Lock(NULL,&ddsd,
                           DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
                           NULL)))
return(0);

// draw all the asteroids
for (int curr_index = 0; curr_index < NUM_ASTEROIDS; curr_index++)
    {
    // glow asteroids
    asteroids[curr_index].color = rand()%256;

    // do the graphics
    Draw_Polygon2D(&asteroids[curr_index], (UCHAR *)ddsd.lpSurface, ddsd.lPitch);

    // move the asteroid
    asteroids[curr_index].x0+=asteroids[curr_index].xv;        
    asteroids[curr_index].y0+=asteroids[curr_index].yv;           

    // test for out of bounds
    if (asteroids[curr_index].x0 > SCREEN_WIDTH+100)
        asteroids[curr_index].x0 = - 100;

    if (asteroids[curr_index].y0 > SCREEN_HEIGHT+100)
        asteroids[curr_index].y0 = - 100;

    if (asteroids[curr_index].x0 < -100)
        asteroids[curr_index].x0 = SCREEN_WIDTH+100;

    if (asteroids[curr_index].y0 < -100)
        asteroids[curr_index].y0 = SCREEN_HEIGHT+100;

    } // end for curr_asteroid


// unlock primary buffer
if (FAILED(lpddsback->Unlock(NULL)))
   return(0);

// perform the flip
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));

// wait a sec
Sleep(33);

// return success or failure or your own return code here
return(1);

} // end Game_Main

////////////////////////////////////////////////////////////

int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here

// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
   return(0);

// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, 
                                      DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | 
                                      DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
   return(0);

// set display mode to 640x480x8
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
   return(0);


// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd); 

// enable valid fields
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// set the backbuffer count field to 1, use 2 for triple buffering
ddsd.dwBackBufferCount = 1;

// request a complex, flippable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
   return(0);

// now query for attached surface from the primary surface

// this line is needed by the call
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

// get the attached back buffer surface
if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
  return(0);


// build up the palette data array
for (int color=1; color < 255; color++)
    {
    // fill with random RGB values
    palette[color].peRed   = rand()%256;
    palette[color].peGreen = rand()%256;
    palette[color].peBlue  = rand()%256;

    // set flags field to PC_NOCOLLAPSE
    palette[color].peFlags = PC_NOCOLLAPSE;
    } // end for color

// now fill in entry 0 and 255 with black and white
palette[0].peRed     = 0;
palette[0].peGreen   = 0;
palette[0].peBlue    = 0;
palette[0].peFlags   = PC_NOCOLLAPSE;

palette[255].peRed   = 255;
palette[255].peGreen = 255;
palette[255].peBlue  = 255;
palette[255].peFlags = PC_NOCOLLAPSE;

// create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | 
                                DDPCAPS_INITIALIZE, 
                                palette,&lpddpal, NULL)))
return(0);

// finally attach the palette to the primary surface
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
   return(0);

// clear the surfaces out
DDraw_Fill_Surface(lpddsprimary, 0 );
DDraw_Fill_Surface(lpddsback, 0 );

// define points of asteroid
VERTEX2DI asteroid_vertices[8] = {33,-3, 9,-18, -12,-9, -21,-12, -9,6, -15,15, -3,27, 21,21};


// loop and initialize all asteroids
for (int curr_index = 0; curr_index < NUM_ASTEROIDS; curr_index++)
    {

    // initialize the asteroid
    asteroids[curr_index].state       = 1;   // turn it on
    asteroids[curr_index].num_verts   = 8;  
    asteroids[curr_index].x0          = rand()%SCREEN_WIDTH; // position it
    asteroids[curr_index].y0          = rand()%SCREEN_HEIGHT;
    asteroids[curr_index].xv          = -8 + rand()%17;
    asteroids[curr_index].yv          = -8 + rand()%17;
    asteroids[curr_index].color       = rand()%256;
    asteroids[curr_index].vlist       = new VERTEX2DI [asteroids[curr_index].num_verts];
 
   for (int index = 0; index < asteroids[curr_index].num_verts; index++)
        asteroids[curr_index].vlist[index] = asteroid_vertices[index];

   } // end for curr_index

// return success or failure or your own return code here
return(1);

} // end Game_Init

/////////////////////////////////////////////////////////////

int Game_Shutdown(void *parms = NULL, int num_parms = 0)
{
// this is called after the game is exited and the main event
// loop while is exited, do all you cleanup and shutdown here


// first the palette
if (lpddpal)
   {
   lpddpal->Release();
   lpddpal = NULL;
   } // end if


// now the back buffer surface
if (lpddsback)
   {
   lpddsback->Release();
   lpddsback = NULL;
   } // end if

// now the primary surface
if (lpddsprimary)
   {
   lpddsprimary->Release();
   lpddsprimary = NULL;
   } // end if

// now blow away the IDirectDraw4 interface
if (lpdd)
   {
   lpdd->Release();
   lpdd = NULL;
   } // end if

// return success or failure or your own return code here
return(1);

} // end Game_Shutdown

// WINMAIN ////////////////////////////////////////////////

int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message
HDC        hdc;      // graphics device context

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
						    "DirectDraw 8-Bit Polygon Demo", // title
						    WS_POPUP | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    SCREEN_WIDTH,SCREEN_HEIGHT,  // initial width, height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// initialize game here
Game_Init();

// enter main event loop
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if
    
       // main game processing goes here
       Game_Main();
       
	} // end while

// closedown game here
Game_Shutdown();

// return to Windows like this
return(msg.wParam);

} // end WinMain

///////////////////////////////////////////////////////////

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品一级在线| 91亚洲男人天堂| 91影院在线免费观看| 五月激情综合色| 91成人网在线| 亚洲精品免费一二三区| 91影院在线免费观看| 精品一区二区av| 精品国内片67194| 欧美aaaaa成人免费观看视频| 在线视频中文字幕一区二区| 亚洲视频一区在线| 国产精品自在在线| 成人欧美一区二区三区| 欧美中文字幕不卡| 国产一区二区三区蝌蚪| 国产日韩影视精品| 波多野结衣中文字幕一区| 国产精品免费人成网站| 不卡一卡二卡三乱码免费网站| 美女网站色91| 椎名由奈av一区二区三区| 久久综合五月天婷婷伊人| 成人激情午夜影院| 国产精品一品二品| 国产主播一区二区| 亚洲网友自拍偷拍| 91精品国产综合久久精品性色| 日韩av不卡在线观看| 久久精品亚洲乱码伦伦中文| 色综合色综合色综合| 日韩黄色小视频| 国产欧美一区二区三区在线老狼 | 日本久久电影网| eeuss鲁片一区二区三区| 午夜免费欧美电影| 亚洲国产精品久久艾草纯爱| 亚洲综合区在线| 久久色成人在线| 精品91自产拍在线观看一区| 欧美成人综合网站| 91一区一区三区| 91麻豆精品秘密| 色狠狠一区二区| 91久久精品一区二区二区| 色综合天天综合色综合av| 久久er99精品| 成人永久免费视频| 亚洲激情图片qvod| 久久久91精品国产一区二区精品| 久久综合色8888| 久久综合久色欧美综合狠狠| 久久久噜噜噜久久中文字幕色伊伊 | 国产亚洲综合性久久久影院| 久久久久久久性| 中文字幕人成不卡一区| 自拍偷拍亚洲综合| 亚洲电影在线免费观看| 蜜桃av噜噜一区| 国产suv一区二区三区88区| 亚洲v精品v日韩v欧美v专区 | 日韩—二三区免费观看av| 秋霞午夜鲁丝一区二区老狼| 精品一区二区在线看| 成人美女在线观看| 色av综合在线| 日韩视频123| 欧美丝袜第三区| 色综合天天综合狠狠| 欧美亚洲国产怡红院影院| 日韩视频中午一区| 中文字幕在线播放不卡一区| 亚洲444eee在线观看| 美美哒免费高清在线观看视频一区二区| 国产一区二区三区av电影| 白白色 亚洲乱淫| 欧美一区二区三区免费观看视频| 欧美在线观看视频一区二区| 51精品秘密在线观看| 久久久久88色偷偷免费| 亚洲永久精品大片| 国产精品一线二线三线| 欧美视频中文字幕| 久久久久九九视频| 亚洲高清视频中文字幕| 国产盗摄精品一区二区三区在线| 国内精品嫩模私拍在线| 91福利社在线观看| 久久美女高清视频| 亚洲成av人片在线观看无码| 成人性视频免费网站| 欧美一区午夜视频在线观看| 一色桃子久久精品亚洲| 久久精品国产一区二区三| 色视频欧美一区二区三区| 久久奇米777| 日本欧美肥老太交大片| 99精品欧美一区二区三区综合在线| www.欧美色图| 久久综合资源网| 日一区二区三区| 91免费看`日韩一区二区| 日韩欧美专区在线| 亚洲高清免费视频| 99视频一区二区三区| 国产午夜一区二区三区| 蜜桃精品视频在线观看| 欧美日韩亚洲另类| 日韩欧美aaaaaa| 欧美极品xxx| 亚洲综合自拍偷拍| 毛片av一区二区三区| 欧美三级视频在线| 亚洲欧美日韩中文字幕一区二区三区 | 一本色道久久综合亚洲aⅴ蜜桃| 精品国产一区二区三区av性色 | 成人av在线资源| 精品99999| 久久99国产精品免费网站| 在线播放91灌醉迷j高跟美女| 欧美一区二区视频在线观看| 亚洲主播在线观看| 色综合久久88色综合天天免费| 国产精品美女视频| 粉嫩蜜臀av国产精品网站| 久久影院视频免费| 国产在线精品视频| 久久伊人中文字幕| 精品无码三级在线观看视频| 日韩欧美中文一区| 免费av网站大全久久| 日韩一级欧美一级| 免费成人在线观看| 日韩欧美激情在线| 黑人精品欧美一区二区蜜桃| 日韩欧美国产一区二区在线播放| 日本在线不卡一区| 日韩一区二区免费在线观看| 久久97超碰色| 久久久www成人免费毛片麻豆 | 日韩高清国产一区在线| 欧美一级免费大片| 免费久久99精品国产| 日韩一卡二卡三卡| 国产乱淫av一区二区三区| 国产午夜精品一区二区三区嫩草 | 国产成人精品影视| 国产精品理论在线观看| 极品少妇xxxx精品少妇偷拍| 久久蜜臀精品av| 成人av电影在线| 玉米视频成人免费看| 欧美日韩一区不卡| 奇米色一区二区三区四区| 精品国产精品网麻豆系列| 国产一区二区三区免费在线观看| 国产欧美日韩不卡免费| 99v久久综合狠狠综合久久| 一区二区在线观看不卡| 欧美日韩精品欧美日韩精品一综合| 国产精品超碰97尤物18| 91成人免费网站| 日韩av电影天堂| 国产无一区二区| 欧美亚洲综合色| 久久成人综合网| 亚洲色图视频网| 91精品国产黑色紧身裤美女| 国产麻豆精品在线| 亚洲乱码国产乱码精品精98午夜| 欧美久久一二区| 国内成+人亚洲+欧美+综合在线| 亚洲欧洲一区二区三区| 欧美精品自拍偷拍动漫精品| 成人免费福利片| 天堂蜜桃91精品| 久久久影视传媒| 欧美亚洲日本一区| 国产一区二区在线看| 亚洲精品精品亚洲| 精品国产91乱码一区二区三区| 国产69精品一区二区亚洲孕妇| 亚洲综合成人在线视频| 欧美成人综合网站| 色就色 综合激情| 国产精品影视天天线| 婷婷国产在线综合| 中文字幕在线播放不卡一区| 日韩欧美国产麻豆| 色综合网站在线| 国产馆精品极品| 免费成人结看片| 亚洲午夜影视影院在线观看| 国产亚洲午夜高清国产拍精品| 欧美日韩1区2区| 色婷婷av一区| 国产成人精品午夜视频免费| 日韩精品乱码免费| 亚洲欧美偷拍另类a∨色屁股| 久久久亚洲欧洲日产国码αv|