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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? demo7_4.cpp

?? 一本外國人寫的關于3D游戲編程的書的源碼
?? CPP
字號:
// DEMO7_4.CPP 8-bit double buffering demo

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

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

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

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

#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

UCHAR                 *double_buffer = NULL;  // pointer to double buffer

char buffer[80];                             // general printing buffer

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

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

UCHAR *primary_buffer = NULL; // used as alias to primary surface buffer

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

// erase double buffer
memset((void *)double_buffer,0, SCREEN_WIDTH*SCREEN_HEIGHT);

// you would perform game logic...
       
// draw the next frame into the double buffer
// plot 5000 random pixels
for (int index=0; index < 5000; index++)
    {
    int   x   = rand()%SCREEN_WIDTH;
    int   y   = rand()%SCREEN_HEIGHT;
    UCHAR col = rand()%256;
    double_buffer[x+y*SCREEN_WIDTH] = col;
    } // end for index

// copy the double buffer into the primary buffer
DDRAW_INIT_STRUCT(ddsd);

// lock the primary surface
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);

// get video pointer to primary surfce
primary_buffer = (UCHAR *)ddsd.lpSurface;       

// test if memory is linear
if (ddsd.lPitch == SCREEN_WIDTH)
   {
   // copy memory from double buffer to primary buffer
   memcpy((void *)primary_buffer, (void *)double_buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
   } // end if
else
   { // non-linear

   // make copy of source and destination addresses
   UCHAR *dest_ptr = primary_buffer;
   UCHAR *src_ptr  = double_buffer;

   // memory is non-linear, copy line by line
   for (int y=0; y < SCREEN_HEIGHT; y++)
       {
       // copy line
       memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);

       // advance pointers to next line
       dest_ptr+=ddsd.lPitch;
       src_ptr +=SCREEN_WIDTH;

       // note: the above code code be replaced with the simpler
       // memcpy(&primary_buffer[y*ddsd.lPitch], double_buffer[y*SCREEN_WIDTH], SCREEN_WIDTH);
       // but it is much slower due to the recalculation and multiplication each cycle

       } // end for

   } // end else

// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
   return(0);

// wait a sec
Sleep(500);

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

// allocate double buffer
if ((double_buffer=new UCHAR[SCREEN_WIDTH * SCREEN_HEIGHT])==NULL)
   return(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

// release the memory used for double buffer
if (double_buffer)
   {
   delete double_buffer;
   double_buffer = 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 Double Buffering 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

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久99精品久久只有精品| 欧美人伦禁忌dvd放荡欲情| 色诱视频网站一区| 欧美va在线播放| 五月天国产精品| av在线这里只有精品| 日韩精品中文字幕在线不卡尤物| 玉米视频成人免费看| 国产精品自在在线| 日韩亚洲国产中文字幕欧美| 亚洲三级久久久| 成人精品在线视频观看| 日韩欧美专区在线| 亚洲成人黄色小说| 91久久精品国产91性色tv| 国产精品热久久久久夜色精品三区 | 国产精品白丝jk白祙喷水网站| 欧美色图免费看| 亚洲欧洲av另类| 国产69精品久久久久毛片| 精品国产人成亚洲区| 日韩电影在线看| 日韩一区二区免费在线电影| 亚洲成人自拍偷拍| 91国偷自产一区二区开放时间| 中文字幕不卡的av| 国产成人精品www牛牛影视| 精品少妇一区二区三区日产乱码| 日韩精品电影在线观看| 欧美日韩精品一区二区| 亚洲成人动漫一区| 欧美人成免费网站| 亚洲 欧美综合在线网络| 欧美天堂一区二区三区| 夜夜嗨av一区二区三区| 欧美亚洲国产bt| 一级精品视频在线观看宜春院| 91网站在线观看视频| 亚洲精品自拍动漫在线| 91福利社在线观看| 亚洲成av人片www| 日韩手机在线导航| 精品无人区卡一卡二卡三乱码免费卡 | 午夜电影一区二区| 欧美一区二区三区在线观看 | 在线不卡的av| 美女视频黄a大片欧美| 日韩三级视频在线看| 毛片不卡一区二区| 国产日产欧产精品推荐色| 成a人片国产精品| 一区二区免费看| 欧美一区二区三区影视| 国产精品88av| 一区二区三区日韩精品| 日韩一区二区中文字幕| 国产成人午夜视频| 伊人夜夜躁av伊人久久| 日韩一区二区三区四区| 成人丝袜视频网| 偷拍一区二区三区四区| 久久夜色精品国产欧美乱极品| 成人在线一区二区三区| 香蕉影视欧美成人| 欧美精品一区二区不卡| www.色综合.com| 免费观看在线综合| 国产精品超碰97尤物18| 51精品视频一区二区三区| 国产老妇另类xxxxx| 亚洲一区精品在线| 久久亚洲一区二区三区四区| 色狠狠综合天天综合综合| 美女mm1313爽爽久久久蜜臀| 亚洲欧美偷拍卡通变态| 日韩片之四级片| 欧美亚洲综合色| 国产一区二区0| 日韩av一二三| 亚洲视频资源在线| 久久蜜桃av一区精品变态类天堂 | 国产麻豆精品theporn| 亚洲美女电影在线| 久久久精品人体av艺术| 欧美二区三区的天堂| 成人爱爱电影网址| 麻豆91在线观看| 亚洲精品第一国产综合野| 国产视频一区二区在线| 欧美一二三区在线观看| 精品视频一区 二区 三区| 99久久精品免费看国产免费软件| 激情国产一区二区| 日本少妇一区二区| 亚洲国产精品久久一线不卡| 中文字幕一区二区三区在线播放| 精品黑人一区二区三区久久 | 国产成人午夜片在线观看高清观看| 亚洲第一久久影院| 亚洲男人的天堂在线aⅴ视频| 久久综合国产精品| 日韩一区二区视频在线观看| 在线不卡一区二区| 欧美性色黄大片| 欧美这里有精品| 在线欧美日韩精品| 99久久久免费精品国产一区二区| 国产精品1区2区3区| 韩国精品免费视频| 国产一区二区三区综合| 国产老肥熟一区二区三区| 九九视频精品免费| 免费亚洲电影在线| 精品在线亚洲视频| 国产乱码字幕精品高清av| 国产一区二区三区蝌蚪| 精品在线亚洲视频| 精品一区二区国语对白| 国产一区二区按摩在线观看| 国产精品亚洲专一区二区三区 | 国产欧美日韩视频一区二区| 国产婷婷一区二区| 国产欧美日韩中文久久| 国产精品久线在线观看| 亚洲婷婷在线视频| 亚洲国产你懂的| 免费观看在线综合| 国产精品18久久久久| eeuss鲁片一区二区三区 | 国产精品亚洲成人| 成人91在线观看| 欧美最猛黑人xxxxx猛交| 制服丝袜在线91| 久久久午夜精品| 成人欧美一区二区三区白人| 亚洲综合免费观看高清完整版在线| 亚洲一级片在线观看| 日韩电影在线免费观看| 国产成人午夜片在线观看高清观看| 99国内精品久久| 91精品国产福利| 欧美国产日韩a欧美在线观看 | 国产日韩成人精品| 亚洲日本va午夜在线电影| 午夜亚洲国产au精品一区二区| 久久精品国产久精国产爱| 成人美女视频在线看| 欧美日韩激情一区二区| 久久嫩草精品久久久久| 亚洲精品少妇30p| 麻豆国产精品一区二区三区| 成人综合在线观看| 欧美日韩一二三区| 欧美国产欧美综合| 天堂在线一区二区| 成人av在线看| 日韩一区二区三区在线| 亚洲视频在线观看三级| 美女网站在线免费欧美精品| 91视频一区二区三区| 91精品一区二区三区久久久久久 | 94-欧美-setu| 日韩美女一区二区三区四区| 亚洲美女偷拍久久| 久久国产精品色| 欧美色综合网站| 中文字幕永久在线不卡| 久久99精品一区二区三区三区| 在线精品视频一区二区| 久久久国产综合精品女国产盗摄| 亚洲观看高清完整版在线观看| 成人黄色网址在线观看| 欧美xingq一区二区| 亚洲第一会所有码转帖| va亚洲va日韩不卡在线观看| 欧美不卡激情三级在线观看| 亚洲成va人在线观看| 91原创在线视频| 中文幕一区二区三区久久蜜桃| 日本一不卡视频| 欧美日韩另类一区| 一区二区三区高清在线| 99久久精品国产毛片| 中文一区二区在线观看| 国内精品国产成人国产三级粉色| 欧美女孩性生活视频| 亚洲精品视频在线观看网站| av欧美精品.com| 中文字幕电影一区| 国产成人精品免费网站| 久久久美女毛片| 国产一区二区剧情av在线| 日韩亚洲欧美成人一区| 日韩黄色小视频| 欧美一区二区三区成人| 丝瓜av网站精品一区二区| 欧美剧在线免费观看网站| 亚洲成人免费视| 在线播放中文一区| 婷婷丁香久久五月婷婷|