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

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

?? blackbox.cpp

?? 一本外國人寫的關(guān)于3D游戲編程的書的源碼
?? CPP
字號(hào):
// BLACKBOX.CPP - Game Engine 
 
// INCLUDES ///////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  // make sure all macros are included


#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>           // directX includes
#include "blackbox.h"        // game library includes
                                   
// DEFINES ////////////////////////////////////////////////////

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

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

// EXTERNALS //////////////////////////////////////////////////

extern HWND main_window_handle; // save the window handle
extern HINSTANCE main_instance; // save the instance

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

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

// these defined the general clipping rectangle
int min_clip_x = 0,                          // clipping rectangle 
    max_clip_x = SCREEN_WIDTH-1,
    min_clip_y = 0,
    max_clip_y = SCREEN_HEIGHT-1;

// these are overwritten globally by DD_Init()
int screen_width  = SCREEN_WIDTH,            // width of screen
    screen_height = SCREEN_HEIGHT,           // height of screen
    screen_bpp    = SCREEN_BPP;              // bits per pixel

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

int DD_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable

// create object and test for error
if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK)
   return(0);

// set cooperation level to windowed mode normal
if (lpdd->SetCooperativeLevel(main_window_handle,
           DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
           DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK)
    return(0);

// set the display mode
if (lpdd->SetDisplayMode(width,height,bpp,0,0)!=DD_OK)
   return(0);

// set globals
screen_height = height;
screen_width  = width;
screen_bpp    = bpp;

// Create the primary surface
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// we need to let dd know that we want a complex 
// flippable surface structure, set flags for that
ddsd.ddsCaps.dwCaps = 
  DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

// set the backbuffer count to 1
ddsd.dwBackBufferCount = 1;

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

// query for the backbuffer i.e the secondary surface
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback);

// create and attach palette

// create palette data
// clear all entries defensive programming
memset(palette,0,256*sizeof(PALETTEENTRY));

// create a R,G,B,GR gradient palette
for (index=0; index < 256; index++)
    {
    // set each entry
    if (index < 64) 
        palette[index].peRed = index*4; 
    else           // shades of green
    if (index >= 64 && index < 128) 
        palette[index].peGreen = (index-64)*4;
    else           // shades of blue
    if (index >= 128 && index < 192) 
       palette[index].peBlue = (index-128)*4;
    else           // shades of grey
    if (index >= 192 && index < 256) 
        palette[index].peRed = palette[index].peGreen = 
        palette[index].peBlue = (index-192)*4;
    
    // set flags
    palette[index].peFlags = PC_NOCOLLAPSE;
    } // end for index

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

// attach the palette to the primary
if (lpddsprimary->SetPalette(lpddpal)!=DD_OK)
   return(0);

// clear out both primary and secondary surfaces
DD_Fill_Surface(lpddsprimary,0);
DD_Fill_Surface(lpddsback,0);

// attach a clipper to the screen
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DD_Attach_Clipper(lpddsback,1,&screen_rect);

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

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

int DD_Shutdown(void)
{
// this function release all the resources directdraw
// allocated, mainly to com objects

// release the clipper first
if (lpddclipper)
    lpddclipper->Release();

// release the palette
if (lpddpal)
   lpddpal->Release();

// release the secondary surface
if (lpddsback)
    lpddsback->Release();

// release the primary surface
if (lpddsprimary)
   lpddsprimary->Release();

// finally, the main dd object
if (lpdd)
    lpdd->Release();

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

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

LPDIRECTDRAWCLIPPER DD_Attach_Clipper(LPDIRECTDRAWSURFACE7 lpdds,
                                      int num_rects,
                                      LPRECT clip_list)

{
// this function creates a clipper from the sent clip list and attaches
// it to the sent surface

int index;                         // looping var
LPDIRECTDRAWCLIPPER lpddclipper;   // pointer to the newly created dd clipper
LPRGNDATA region_data;             // pointer to the region data that contains
                                   // the header and clip list

// first create the direct draw clipper
if ((lpdd->CreateClipper(0,&lpddclipper,NULL))!=DD_OK)
   return(NULL);

// now create the clip list from the sent data

// first allocate memory for region data
region_data = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+num_rects*sizeof(RECT));

// now copy the rects into region data
memcpy(region_data->Buffer, clip_list, sizeof(RECT)*num_rects);

// set up fields of header
region_data->rdh.dwSize          = sizeof(RGNDATAHEADER);
region_data->rdh.iType           = RDH_RECTANGLES;
region_data->rdh.nCount          = num_rects;
region_data->rdh.nRgnSize        = num_rects*sizeof(RECT);

region_data->rdh.rcBound.left    =  64000;
region_data->rdh.rcBound.top     =  64000;
region_data->rdh.rcBound.right   = -64000;
region_data->rdh.rcBound.bottom  = -64000;

// find bounds of all clipping regions
for (index=0; index<num_rects; index++)
    {
    // test if the next rectangle unioned with the current bound is larger
    if (clip_list[index].left < region_data->rdh.rcBound.left)
       region_data->rdh.rcBound.left = clip_list[index].left;

    if (clip_list[index].right > region_data->rdh.rcBound.right)
       region_data->rdh.rcBound.right = clip_list[index].right;

    if (clip_list[index].top < region_data->rdh.rcBound.top)
       region_data->rdh.rcBound.top = clip_list[index].top;

    if (clip_list[index].bottom > region_data->rdh.rcBound.bottom)
       region_data->rdh.rcBound.bottom = clip_list[index].bottom;

    } // end for index

// now we have computed the bounding rectangle region and set up the data
// now let's set the clipping list

if ((lpddclipper->SetClipList(region_data, 0))!=DD_OK)
   {
   // release memory and return error
   free(region_data);
   return(NULL);
   } // end if

// now attach the clipper to the surface
if ((lpdds->SetClipper(lpddclipper))!=DD_OK)
   {
   // release memory and return error
   free(region_data);
   return(NULL);
   } // end if

// all is well, so release memory and send back the pointer to the new clipper
free(region_data);
return(lpddclipper);

} // end DD_Attach_Clipper

///////////////////////////////////////////////////////////////
   
int DD_Flip(void)
{
// this function flip the primary surface with the secondary surface

// flip pages
while(lpddsprimary->Flip(NULL, DDFLIP_WAIT)!=DD_OK);

// flip the surface

// return success
return(1);

} // end DD_Flip

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

DWORD Start_Clock(void)
{
// this function starts the clock, that is, saves the current
// count, use in conjunction with Wait_Clock()

return(start_clock_count = Get_Clock());

} // end Start_Clock

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

DWORD Get_Clock(void)
{
// this function returns the current tick count

// return time
return(GetTickCount());

} // end Get_Clock

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

DWORD Wait_Clock(DWORD count)
{
// this function is used to wait for a specific number of clicks
// since the call to Start_Clock

while((Get_Clock() - start_clock_count) < count);
return(Get_Clock());

} // end Wait_Clock

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

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

// clear out the structure and set the size field 
DD_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 | DDBLT_ASYNC,   // fill and wait                   
           &ddbltfx);  // ptr to DDBLTFX structure

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

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

int Draw_Rectangle(int x1, int y1, int x2, int y2, int color,
                   LPDIRECTDRAWSURFACE7 lpdds)
{
// this function uses directdraw to draw a filled rectangle

DDBLTFX ddbltfx; // this contains the DDBLTFX structure
RECT fill_area;  // this contains the destination rectangle

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

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

// fill in the destination rectangle data (your data)
fill_area.top    = y1;
fill_area.left   = x1;
fill_area.bottom = y2+1;
fill_area.right  = x2+1;

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

// return success
return(1);

} // end Draw_Rectangle

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

int Draw_Text_GDI(char *text, int x,int y,int color, LPDIRECTDRAWSURFACE7 lpdds)
{
// this function draws the sent text on the sent surface 
// using color index as the color in the palette

HDC xdc; // the working dc

// get the dc from surface
if (lpdds->GetDC(&xdc)!=DD_OK)
   return(0);

// set the colors for the text up
SetTextColor(xdc,RGB(palette[color].peRed,palette[color].peGreen,palette[color].peBlue) );

// set background mode to transparent so black isn't copied
SetBkMode(xdc, TRANSPARENT);

// draw the text a
TextOut(xdc,x,y,text,strlen(text));

// release the dc
lpdds->ReleaseDC(xdc);

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

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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久91精品国产91久久小草| 欧美乱妇23p| 欧美精品一区二区三区视频| 视频在线观看一区| 99久久99久久精品免费观看| 综合久久综合久久| 国产精品77777| 久久精品一区二区三区av| 亚洲国产精品尤物yw在线观看| 91国产精品成人| 亚洲综合男人的天堂| 欧美日产在线观看| 美女看a上一区| 久久亚洲精华国产精华液 | 91视频国产观看| 1区2区3区欧美| 在线观看亚洲精品视频| 午夜婷婷国产麻豆精品| 欧美精品视频www在线观看 | 夜夜嗨av一区二区三区四季av| 欧美色倩网站大全免费| 亚洲444eee在线观看| 欧美精品一二三四| 国产自产高清不卡| 中文字幕综合网| 精品视频色一区| 国内精品伊人久久久久影院对白| 国产欧美日韩在线| 99久久精品免费观看| 一二三四社区欧美黄| 久久综合久色欧美综合狠狠| 91首页免费视频| 美女视频网站久久| 亚洲精品欧美激情| 日韩欧美一区在线| 色综合一区二区三区| 三级欧美在线一区| 国产精品福利影院| 日韩免费高清电影| 8v天堂国产在线一区二区| 国产+成+人+亚洲欧洲自线| 亚洲国产一区二区三区| 国产欧美日韩麻豆91| 日韩女优av电影在线观看| 91传媒视频在线播放| 国产成人av一区二区三区在线 | 国产精品免费网站在线观看| 欧美一区二区视频在线观看2022| 成人app软件下载大全免费| 日韩—二三区免费观看av| 一区二区三区日韩欧美| 最新日韩在线视频| 日本一区二区三区四区| 国产亚洲精品资源在线26u| 3d成人动漫网站| 制服丝袜亚洲精品中文字幕| 色88888久久久久久影院野外| 不卡电影一区二区三区| 成人美女视频在线观看18| 韩国一区二区在线观看| 激情久久久久久久久久久久久久久久| 日韩国产精品久久久久久亚洲| 亚洲va欧美va国产va天堂影院| 亚洲国产精品欧美一二99| 日韩中文字幕不卡| 天天亚洲美女在线视频| 日韩一区欧美二区| 久草热8精品视频在线观看| 九一久久久久久| eeuss鲁一区二区三区| 成人激情免费网站| 精品视频一区三区九区| 欧美一级xxx| 国产精品视频一二三| 一区二区三区波多野结衣在线观看 | 中文字幕一区二区日韩精品绯色| 亚洲激情图片小说视频| 日韩主播视频在线| 国产成人免费高清| 欧美日韩免费一区二区三区| www久久久久| 亚洲综合色自拍一区| 精品在线亚洲视频| 在线观看免费视频综合| 国产午夜精品一区二区三区视频 | 欧美日本一区二区三区| 亚洲国产激情av| 亚洲成人激情自拍| 91亚洲精品久久久蜜桃网站| 日韩欧美国产成人一区二区| 亚洲色图20p| caoporm超碰国产精品| 91精品国产福利| 亚洲国产乱码最新视频| av高清不卡在线| 一级精品视频在线观看宜春院| 不卡在线观看av| 久久午夜免费电影| 五月天激情小说综合| 欧美一区二区三区四区视频| 亚洲综合一区二区三区| www.久久精品| 久久久一区二区| 国产精品资源在线观看| 久久久五月婷婷| 国产精品综合网| 日本一二三不卡| 国产91精品一区二区麻豆亚洲| 久久蜜桃一区二区| 国产综合色产在线精品| 日韩一区二区三区在线观看| 国产一区二区三区在线观看免费视频 | 国产精品乱人伦中文| 国产99久久精品| 国产精品美女一区二区在线观看| 成人国产在线观看| 亚洲欧美另类在线| 欧美午夜精品一区二区三区| 日本不卡一二三| 日韩美女视频一区二区在线观看| 天堂久久久久va久久久久| 欧美一区二区女人| 成人av网在线| 视频在线观看一区二区三区| 国产精品18久久久久久久网站| 久久精品夜色噜噜亚洲a∨| 成人美女在线视频| 美女一区二区在线观看| 国产精品网站导航| 日韩精品一区二区三区swag| 91麻豆精品秘密| 国产一区中文字幕| 亚洲国产精品麻豆| 国产精品嫩草影院com| 欧美日韩免费不卡视频一区二区三区| 久久99精品久久久久久动态图| 亚洲精品乱码久久久久久久久| 日韩欧美在线观看一区二区三区| 色欲综合视频天天天| 国产一区二区三区四区五区美女| 亚洲成av人片在线观看| 国产精品盗摄一区二区三区| 亚洲欧洲国产日韩| 久久久久9999亚洲精品| av成人动漫在线观看| 亚洲r级在线视频| 欧美一级日韩不卡播放免费| 成人免费毛片片v| 亚洲大片一区二区三区| 亚洲一区二区三区美女| 亚洲人成网站影音先锋播放| 久久这里只有精品首页| 国产欧美日产一区| 欧美高清视频一二三区 | 中文字幕免费在线观看视频一区| 欧美精品一区视频| 国产日韩在线不卡| 国产欧美日韩精品一区| 日本一区二区三区免费乱视频 | 精品免费国产二区三区| 欧美一区二区三区视频| 91精品欧美综合在线观看最新| 7777精品伊人久久久大香线蕉经典版下载| 亚洲伊人伊色伊影伊综合网| 青青草国产成人99久久| 国产a精品视频| 色噜噜狠狠色综合欧洲selulu| 欧美片网站yy| 国产精品卡一卡二| 亚洲h动漫在线| 国产精品69毛片高清亚洲| 欧美在线视频不卡| 精品福利一区二区三区| 久久精品亚洲精品国产欧美| 一级做a爱片久久| 丰满亚洲少妇av| 欧美色中文字幕| 国产精品你懂的在线| 亚洲国产一区在线观看| 国产精品白丝av| 欧美色图一区二区三区| 日韩精品在线看片z| 国产精品毛片久久久久久久| 亚洲国产精品一区二区www| 国产美女娇喘av呻吟久久| 成人成人成人在线视频| 91精品福利在线一区二区三区| 久久老女人爱爱| 视频在线观看一区| 欧美性xxxxxx少妇| 亚洲情趣在线观看| 国产91综合网| 欧美国产一区二区| 日本人妖一区二区| 欧美日韩一区二区三区不卡| 亚洲一区二区欧美日韩| 国产成人欧美日韩在线电影| 日韩欧美电影在线| 韩国精品久久久| 欧美电影免费观看完整版|