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

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

?? demo8_1.cpp

?? 一本外國人寫的關(guān)于3D游戲編程的書的源碼
?? CPP
字號:
// DEMO8_1.CPP 8-bit line drawing program

// INCLUDES ///////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#define INITGUID

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h> 
#include <math.h>
#include <io.h>
#include <fcntl.h>

#include <ddraw.h> // include directdraw

// DEFINES ////////////////////////////////////////////////

// defines for windows 
#define WINDOW_CLASS_NAME "WINCLASS1"

// default screen size
#define SCREEN_WIDTH    640  // size of screen
#define SCREEN_HEIGHT   480
#define SCREEN_BPP      8    // bits per pixel

#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define MAX_COLORS_PALETTE   256


// TYPES //////////////////////////////////////////////////////

// basic unsigned types
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char  UCHAR;
typedef unsigned char  BYTE;

// PROTOTYPES  //////////////////////////////////////////////

int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color);

int Draw_Line(int x0, int y0, int x1, int y1, UCHAR color, UCHAR *vb_start, int lpitch);

// MACROS /////////////////////////////////////////////////

// tests if a key is up or down
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// initializes a direct draw struct
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

// GLOBALS ////////////////////////////////////////////////

HWND      main_window_handle = NULL; // globally track main window
int       window_closed      = 0;    // tracks if window is closed
HINSTANCE hinstance_app      = NULL; // globally track hinstance

// directdraw stuff
LPDIRECTDRAW7         lpdd         = NULL;   // dd object
LPDIRECTDRAWSURFACE7  lpddsprimary = NULL;   // dd primary surface
LPDIRECTDRAWSURFACE7  lpddsback    = NULL;   // dd back surface
LPDIRECTDRAWPALETTE   lpddpal      = NULL;   // a pointer to the created dd palette
LPDIRECTDRAWCLIPPER   lpddclipper  = NULL;   // dd clipper
PALETTEENTRY          palette[256];          // color palette
PALETTEENTRY          save_palette[256];     // used to save palettes
DDSURFACEDESC2        ddsd;                  // a direct draw surface description struct
DDBLTFX               ddbltfx;               // used to fill
DDSCAPS2              ddscaps;               // a direct draw surface capabilities struct
HRESULT               ddrval;                // result back from dd calls
DWORD                 start_clock_count = 0; // used for timing


char buffer[80];                             // general printing buffer

// FUNCTIONS ////////////////////////////////////////////////

inline int Draw_Pixel(int x, int y,int color,
               UCHAR *video_buffer, int lpitch)
{
// this function plots a single pixel at x,y with color

video_buffer[x + y*lpitch] = color;

// return success
return(1);

} // end Draw_Pixel

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

int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color)
{
DDBLTFX ddbltfx; // this contains the DDBLTFX structure

// clear out the structure and set the size field 
DDRAW_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color
ddbltfx.dwFillColor = color; 

// ready to blt to surface
lpdds->Blt(NULL,       // ptr to dest rectangle
           NULL,       // ptr to source surface, NA            
           NULL,       // ptr to source rectangle, NA
           DDBLT_COLORFILL | DDBLT_WAIT,   // fill and wait                   
           &ddbltfx);  // ptr to DDBLTFX structure

// return success
return(1);
} // end DDraw_Fill_Surface

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

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


// lock primary buffer
DDRAW_INIT_STRUCT(ddsd);

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

// draw 1000 random lines
for (int index=0; index < 1000; index++)
    {
    Draw_Line(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT,
              rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT,
              rand()%256,
              (UCHAR *)ddsd.lpSurface, ddsd.lPitch);

    } // end for index


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

// 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;

// request primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
   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 primary surface off
DDraw_Fill_Surface(lpddsprimary, 0 );


// 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 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 Line Drawing 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
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美视频一区二区在线观看| 91麻豆精品久久久久蜜臀| 亚洲一区二区三区免费视频| 中文字幕一区二区三区乱码在线 | 欧美一区二区黄色| 欧美日韩精品高清| 91精品国产综合久久福利| 7777精品久久久大香线蕉| 日韩亚洲欧美综合| 精品久久久久久亚洲综合网| 久久精品日产第一区二区三区高清版| 精品久久久久久久久久久久久久久久久| 日韩视频免费直播| 久久久久久久久久久久久久久99 | 夜夜精品视频一区二区| 亚洲国产人成综合网站| 日韩黄色片在线观看| 开心九九激情九九欧美日韩精美视频电影| 免费人成精品欧美精品| 激情五月婷婷综合网| 国产成人免费在线| 色综合中文字幕国产| 日本美女视频一区二区| 亚洲免费三区一区二区| 有坂深雪av一区二区精品| 亚洲免费观看高清| 日韩在线播放一区二区| 精油按摩中文字幕久久| 不卡一区二区三区四区| 91福利在线看| 精品sm捆绑视频| 国产精品色婷婷久久58| 亚洲自拍偷拍图区| 国产综合色精品一区二区三区| 成人黄色软件下载| 在线成人午夜影院| 国产欧美综合在线观看第十页| 亚洲美女在线国产| 久久不见久久见免费视频7| 国产黄色精品网站| 欧美日韩一二区| 国产亚洲综合色| 亚洲地区一二三色| 国产aⅴ精品一区二区三区色成熟| 色狠狠av一区二区三区| 精品国产免费一区二区三区四区 | 不卡大黄网站免费看| 一本色道亚洲精品aⅴ| 欧美一区二区不卡视频| 国产精品三级视频| 日本不卡不码高清免费观看| 国产91色综合久久免费分享| 欧美日韩精品一区二区在线播放| xnxx国产精品| 亚洲国产美国国产综合一区二区| 国产精品一品二品| 91精品国产全国免费观看| 一区视频在线播放| 久久国产日韩欧美精品| 欧美在线一区二区| 国产精品国产三级国产普通话蜜臀| 日韩av中文字幕一区二区| 99久久国产综合色|国产精品| 精品国产91洋老外米糕| 亚洲国产视频直播| 成人国产精品免费观看| 欧美成人官网二区| 偷拍与自拍一区| 91视频观看免费| 久久久99免费| 蜜桃视频免费观看一区| 在线欧美日韩精品| 成人免费视频在线观看| 国产一区二区三区精品视频| 欧美一卡二卡在线| 亚洲一区二区四区蜜桃| 99视频精品在线| 国产清纯白嫩初高生在线观看91 | 2020国产精品自拍| 日韩精品亚洲一区| 在线欧美日韩精品| 亚洲免费视频中文字幕| 波多野结衣欧美| 国产欧美一区二区精品仙草咪| 裸体歌舞表演一区二区| 欧美一个色资源| 日韩av一区二区在线影视| 欧美做爰猛烈大尺度电影无法无天| 国产精品国产馆在线真实露脸| 国产精品12区| 欧美激情在线看| 国产精品1024| 中文在线一区二区| 成人黄色网址在线观看| 国产精品美女久久久久久久网站| 国产精品一二三四五| 26uuu国产电影一区二区| 国产在线日韩欧美| 精品成人佐山爱一区二区| 韩国欧美一区二区| 久久先锋影音av鲁色资源网| 国产中文字幕精品| 国产日产欧美一区| 波多野结衣在线一区| 国产精品久久久久永久免费观看 | 欧美一卡二卡三卡四卡| 奇米在线7777在线精品 | 青青青爽久久午夜综合久久午夜| 7777精品伊人久久久大香线蕉完整版| 亚洲电影一级片| 在线不卡免费av| 蜜桃久久av一区| 久久午夜色播影院免费高清| 成人网在线免费视频| 国产精品剧情在线亚洲| 色综合久久中文字幕综合网| 亚洲一区在线观看免费观看电影高清| 欧美三电影在线| 美女精品一区二区| 久久久久久久久久电影| 99久久久免费精品国产一区二区| 日韩毛片在线免费观看| 欧美性色欧美a在线播放| 天堂午夜影视日韩欧美一区二区| 日韩视频免费直播| 高清shemale亚洲人妖| 亚洲欧美激情小说另类| 7777精品伊人久久久大香线蕉完整版 | 91黄色激情网站| 日本在线观看不卡视频| 久久久久久久久久电影| 一本色道亚洲精品aⅴ| 日本不卡在线视频| 国产精品美女www爽爽爽| 欧美系列亚洲系列| 韩国av一区二区三区四区| 国产精品久久久久影院老司 | 天天综合天天做天天综合| 精品免费视频.| 色偷偷成人一区二区三区91| 青娱乐精品在线视频| 中文乱码免费一区二区| 欧美性色黄大片| 国产精品系列在线观看| 一区二区三区欧美视频| 精品久久久久av影院| 99在线视频精品| 捆绑紧缚一区二区三区视频| 国产精品国产精品国产专区不蜜| 欧美丰满高潮xxxx喷水动漫| 风流少妇一区二区| 亚洲成av人片观看| 日本一区二区成人| 91精品国产手机| 91美女片黄在线观看| 精品在线一区二区三区| 亚洲精品免费播放| 久久久久久综合| 7878成人国产在线观看| 99久久综合国产精品| 精品亚洲免费视频| 亚洲h动漫在线| 亚洲色图制服丝袜| 精品乱码亚洲一区二区不卡| 日本韩国欧美一区二区三区| 国产精品中文有码| 奇米在线7777在线精品| 伊人色综合久久天天人手人婷| 久久欧美中文字幕| 日韩三级视频在线看| 色中色一区二区| 成人国产精品免费观看视频| 久久99国产精品免费| 亚洲成人激情自拍| 一区二区中文字幕在线| 久久先锋影音av| 日韩免费成人网| 欧美精品在线观看播放| 在线免费观看成人短视频| 成人综合在线观看| 国内精品伊人久久久久av影院| 性做久久久久久| 亚洲精品国产视频| 中文字幕一区二区三区在线不卡| 久久久国产精品麻豆| 欧美精品一区视频| 日韩欧美专区在线| 91精品国产手机| 欧美电影在线免费观看| 欧美视频精品在线| 欧美性xxxxxx少妇| 91福利精品视频| 在线观看欧美黄色| 色国产综合视频| 在线精品视频小说1| 色婷婷综合久久久中文字幕| 91欧美一区二区| 91视频91自| 在线观看av一区二区| 欧美中文字幕久久|