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

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

?? t3dlib1.cpp

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

#define WIN32_LEAN_AND_MEAN  

// has the GUID library been included?
//#ifndef INITGUID
//#define INITGUID
//#endif

#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 <sys/timeb.h>
#include <time.h>


#include <ddraw.h>    // directX includes
#include "T3DLIB1.H"

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

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

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

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

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

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

FILE *fp_error                    = NULL; // general error file
char error_filename[80];                  // error file name

// notice that interface 7.0 is used on a number of interfaces
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 for back surface
LPDIRECTDRAWCLIPPER  lpddclipperwin = NULL; // dd clipper for window

PALETTEENTRY         palette[MAX_COLORS_PALETTE];         // color palette
PALETTEENTRY         save_palette[MAX_COLORS_PALETTE];    // 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
UCHAR                *primary_buffer = NULL; // primary video buffer
UCHAR                *back_buffer    = NULL; // secondary back buffer
int                  primary_lpitch  = 0;    // memory line pitch for primary buffer
int                  back_lpitch     = 0;    // memory line pitch for back buffer
BITMAP_FILE          bitmap8bit;             // a 8 bit bitmap file
BITMAP_FILE          bitmap16bit;            // a 16 bit bitmap file
BITMAP_FILE          bitmap24bit;            // a 24 bit bitmap file

DWORD                start_clock_count = 0;     // used for timing
int                  windowed_mode     = FALSE; // tracks if dd is windowed or not

// 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 DDraw_Init()
int screen_width    = SCREEN_WIDTH,            // width of screen
    screen_height   = SCREEN_HEIGHT,           // height of screen
    screen_bpp      = SCREEN_BPP,              // bits per pixel
    screen_windowed = 0;                       // is this a windowed app?    

int dd_pixel_format = DD_PIXEL_FORMAT565;  // default pixel format

int window_client_x0   = 0;   // used to track the starting (x,y) client area for
int window_client_y0   = 0;   // for windowed mode directdraw operations

// storage for our lookup tables
float cos_look[361]; // 1 extra element so we can store 0-360 inclusive
float sin_look[361];

// function ptr to RGB16 builder
USHORT (*RGB16Bit)(int r, int g, int b) = NULL;

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

USHORT RGB16Bit565(int r, int g, int b)
{
// this function simply builds a 5.6.5 format 16 bit pixel
// assumes input is RGB 0-255 each channel
r>>=3; g>>=2; b>>=3;
return(_RGB16BIT565((r),(g),(b)));

} // end RGB16Bit565

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

USHORT RGB16Bit555(int r, int g, int b)
{
// this function simply builds a 5.5.5 format 16 bit pixel
// assumes input is RGB 0-255 each channel
r>>=3; g>>=3; b>>=3;
return(_RGB16BIT555((r),(g),(b)));

} // end RGB16Bit555

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

inline void Mem_Set_WORD(void *dest, USHORT data, int count)
{
// this function fills or sets unsigned 16-bit aligned memory
// count is number of words

_asm 
    { 
    mov edi, dest   ; edi points to destination memory
    mov ecx, count  ; number of 16-bit words to move
    mov ax,  data   ; 16-bit data
    rep stosw       ; move data
    } // end asm
 
} // end Mem_Set_WORD

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

inline void Mem_Set_QUAD(void *dest, UINT data, int count)
{
// this function fills or sets unsigned 32-bit aligned memory
// count is number of quads

_asm 
    { 
    mov edi, dest   ; edi points to destination memory
    mov ecx, count  ; number of 32-bit words to move
    mov eax, data   ; 32-bit data
    rep stosd       ; move data
    } // end asm

} // end Mem_Set_QUAD

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

int Create_BOB(BOB_PTR bob,           // the bob to create
               int x, int y,          // initial posiiton
               int width, int height, // size of bob
               int num_frames,        // number of frames
               int attr,              // attrs
               int mem_flags,         // memory flags in DD format
               USHORT color_key_value, // default color key
               int bpp)                // bits per pixel

{
// Create the BOB object, note that all BOBs 
// are created as offscreen surfaces in VRAM as the
// default, if you want to use system memory then
// set flags equal to:
// DDSCAPS_SYSTEMMEMORY 
// for video memory you can create either local VRAM surfaces or AGP 
// surfaces via the second set of constants shown below in the regular expression
// DDSCAPS_VIDEOMEMORY | (DDSCAPS_NONLOCALVIDMEM | DDSCAPS_LOCALVIDMEM ) 


DDSURFACEDESC2 ddsd; // used to create surface
int index;           // looping var

// set state and attributes of BOB
bob->state          = BOB_STATE_ALIVE;
bob->attr           = attr;
bob->anim_state     = 0;
bob->counter_1      = 0;     
bob->counter_2      = 0;
bob->max_count_1    = 0;
bob->max_count_2    = 0;

bob->curr_frame     = 0;
bob->num_frames     = num_frames;
bob->bpp            = bpp;
bob->curr_animation = 0;
bob->anim_counter   = 0;
bob->anim_index     = 0;
bob->anim_count_max = 0; 
bob->x              = x;
bob->y              = y;
bob->xv             = 0;
bob->yv             = 0;

// set dimensions of the new bitmap surface
bob->width  = width;
bob->height = height;

// set all images to null
for (index=0; index<MAX_BOB_FRAMES; index++)
    bob->images[index] = NULL;

// set all animations to null
for (index=0; index<MAX_BOB_ANIMATIONS; index++)
    bob->animations[index] = NULL;

#if 0
// make sure surface width is a multiple of 8, some old version of dd like that
// now, it's unneeded...
bob->width_fill = ((width%8!=0) ? (8-width%8) : 0);
Write_Error("\nCreate BOB: width_fill=%d",bob->width_fill);
#endif

// now create each surface
for (index=0; index<bob->num_frames; index++)
    {
    // set to access caps, width, and height
    memset(&ddsd,0,sizeof(ddsd));
    ddsd.dwSize  = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

    ddsd.dwWidth  = bob->width + bob->width_fill;
    ddsd.dwHeight = bob->height;

    // set surface to offscreen plain
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;

    // create the surfaces, return failure if problem
    if (FAILED(lpdd->CreateSurface(&ddsd,&(bob->images[index]),NULL)))
        return(0);

    // set color key to default color 000
    // note that if this is a 8bit bob then palette index 0 will be 
    // transparent by default
    // note that if this is a 16bit bob then RGB value 000 will be 
    // transparent
    DDCOLORKEY color_key; // used to set color key
    color_key.dwColorSpaceLowValue  = color_key_value;
    color_key.dwColorSpaceHighValue = color_key_value;

    // now set the color key for source blitting
    (bob->images[index])->SetColorKey(DDCKEY_SRCBLT, &color_key);
    
    } // end for index

// return success
return(1);

} // end Create_BOB

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

int Clone_BOB(BOB_PTR source, BOB_PTR dest)
{
// this function clones a BOB and updates the attr var to reflect that
// the BOB is a clone and not real, this is used later in the destroy
// function so a clone doesn't destroy the memory of a real bob

if ((source && dest) && (source!=dest))
   {
   // copy the bob data
   memcpy(dest,source, sizeof(BOB));

   // set the clone attribute
   dest->attr |= BOB_ATTR_CLONE;

   } // end if

else
    return(0);

// return success
return(1);

} // end Clone_BOB

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

int Destroy_BOB(BOB_PTR bob)
{
// destroy the BOB, tests if this is a real bob or a clone
// if real then release all the memory, otherwise, just resets
// the pointers to null

int index; // looping var

// is this bob valid
if (!bob)
    return(0);

// test if this is a clone
if (bob->attr && BOB_ATTR_CLONE)
    {
    // null link all surfaces
    for (index=0; index<MAX_BOB_FRAMES; index++)
        if (bob->images[index])
            bob->images[index]=NULL;

    // release memory for animation sequences 
    for (index=0; index<MAX_BOB_ANIMATIONS; index++)
        if (bob->animations[index])
            bob->animations[index]=NULL;

    } // end if
else
    {
    // destroy each bitmap surface
    for (index=0; index<MAX_BOB_FRAMES; index++)
        if (bob->images[index])
            (bob->images[index])->Release();

    // release memory for animation sequences 
    for (index=0; index<MAX_BOB_ANIMATIONS; index++)
        if (bob->animations[index])
            free(bob->animations[index]);

    } // end else not clone

// return success
return(1);

} // end Destroy_BOB

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

int Draw_BOB(BOB_PTR bob,               // bob to draw
             LPDIRECTDRAWSURFACE7 dest) // surface to draw the bob on
{
// draw a bob at the x,y defined in the BOB
// on the destination surface defined in dest

RECT dest_rect,   // the destination rectangle
     source_rect; // the source rectangle                             

// is this a valid bob
if (!bob)
    return(0);

// is bob visible
if (!(bob->attr & BOB_ATTR_VISIBLE))
   return(1);

// fill in the destination rect
dest_rect.left   = bob->x;
dest_rect.top    = bob->y;
dest_rect.right  = bob->x+bob->width;
dest_rect.bottom = bob->y+bob->height;

// fill in the source rect
source_rect.left    = 0;
source_rect.top     = 0;
source_rect.right   = bob->width;
source_rect.bottom  = bob->height;

// blt to destination surface
if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
          &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
          NULL)))
    return(0);

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

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

int Draw_Scaled_BOB(BOB_PTR bob, int swidth, int sheight,  // bob and new dimensions
                    LPDIRECTDRAWSURFACE7 dest) // surface to draw the bob on)
{
// this function draws a scaled bob to the size swidth, sheight

RECT dest_rect,   // the destination rectangle
     source_rect; // the source rectangle                             

// is this a valid bob
if (!bob)
    return(0);

// is bob visible
if (!(bob->attr & BOB_ATTR_VISIBLE))
   return(1);

// fill in the destination rect
dest_rect.left   = bob->x;
dest_rect.top    = bob->y;
dest_rect.right  = bob->x+swidth;
dest_rect.bottom = bob->y+sheight;

// fill in the source rect
source_rect.left    = 0;
source_rect.top     = 0;
source_rect.right   = bob->width;
source_rect.bottom  = bob->height;

// blt to destination surface
if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
          &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
          NULL)))
    return(0);

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

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

int Draw_BOB16(BOB_PTR bob,             // bob to draw
             LPDIRECTDRAWSURFACE7 dest) // surface to draw the bob on
{
// draw a bob at the x,y defined in the BOB
// on the destination surface defined in dest

RECT dest_rect,   // the destination rectangle
     source_rect; // the source rectangle                             

// is this a valid bob
if (!bob)
    return(0);

// is bob visible
if (!(bob->attr & BOB_ATTR_VISIBLE))
   return(1);

// fill in the destination rect
dest_rect.left   = bob->x;
dest_rect.top    = bob->y;
dest_rect.right  = bob->x+bob->width;
dest_rect.bottom = bob->y+bob->height;

// fill in the source rect
source_rect.left    = 0;
source_rect.top     = 0;
source_rect.right   = bob->width;
source_rect.bottom  = bob->height;

// blt to destination surface
if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
          &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
          NULL)))
    return(0);

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

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

int Draw_Scaled_BOB16(BOB_PTR bob, int swidth, int sheight,  // bob and new dimensions
                    LPDIRECTDRAWSURFACE7 dest) // surface to draw the bob on)
{
// this function draws a scaled bob to the size swidth, sheight

RECT dest_rect,   // the destination rectangle
     source_rect; // the source rectangle                             

// is this a valid bob
if (!bob)
    return(0);

// is bob visible
if (!(bob->attr & BOB_ATTR_VISIBLE))
   return(1);

// fill in the destination rect
dest_rect.left   = bob->x;
dest_rect.top    = bob->y;
dest_rect.right  = bob->x+swidth;
dest_rect.bottom = bob->y+sheight;

// fill in the source rect
source_rect.left    = 0;
source_rect.top     = 0;
source_rect.right   = bob->width;
source_rect.bottom  = bob->height;

// blt to destination surface
if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
          &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
          NULL)))
    return(0);

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

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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人黄色av网站在线| 色婷婷av一区二区三区大白胸| 国产精品久久久爽爽爽麻豆色哟哟| 在线观看91视频| 国产激情91久久精品导航| 亚洲欧美日本韩国| 国产三级一区二区| 欧美日韩黄色影视| 91影院在线免费观看| 久久99精品国产麻豆不卡| 亚洲一区二区四区蜜桃| 久久综合成人精品亚洲另类欧美| 欧美三级视频在线观看| 成人理论电影网| 久久99久久99| 水蜜桃久久夜色精品一区的特点| 国产精品免费久久| 精品国产a毛片| 91麻豆精品国产91久久久久久| 在线观看视频一区二区欧美日韩| 国产精品一区久久久久| 美女mm1313爽爽久久久蜜臀| 亚洲国产欧美一区二区三区丁香婷| 中文字幕欧美区| 精品国产免费视频| 日韩一区二区三区视频在线观看| 色香色香欲天天天影视综合网| 国产99久久久国产精品潘金| 精品无人码麻豆乱码1区2区| 日韩福利视频导航| 亚洲午夜久久久久| 一个色综合网站| 亚洲男帅同性gay1069| 中文字幕一区二区三区蜜月| 欧美韩国日本不卡| 中文子幕无线码一区tr| 久久久综合精品| 国产欧美一区在线| 久久久777精品电影网影网 | 一卡二卡三卡日韩欧美| 综合av第一页| 亚洲欧美日韩中文播放 | 日本sm残虐另类| 三级在线观看一区二区| 天堂av在线一区| 青青青伊人色综合久久| 麻豆精品视频在线观看免费| 久久99国产精品麻豆| 国产综合久久久久久久久久久久 | 午夜欧美大尺度福利影院在线看| 亚洲五码中文字幕| 日本91福利区| 久久91精品久久久久久秒播| 国内精品国产成人国产三级粉色| 国产一区二区免费看| 成人精品高清在线| 91性感美女视频| 欧美日韩久久一区二区| 91精品国产综合久久婷婷香蕉 | 亚洲观看高清完整版在线观看| 亚洲高清免费观看高清完整版在线观看| 亚洲一区在线看| 日本亚洲欧美天堂免费| 国产精品18久久久久久久网站| 国产福利电影一区二区三区| 91亚洲国产成人精品一区二区三| 欧美色综合久久| 欧美成人在线直播| 国产精品久线在线观看| 亚洲最快最全在线视频| 久久成人18免费观看| 成人精品高清在线| 欧美日韩你懂的| 久久夜色精品国产噜噜av| 亚洲欧洲精品一区二区三区| 图片区小说区区亚洲影院| 国产资源在线一区| 色妞www精品视频| 欧美mv日韩mv国产网站app| 国产精品嫩草影院com| 五月开心婷婷久久| 国产二区国产一区在线观看| 在线视频欧美精品| 久久中文娱乐网| 一区二区三区日韩精品视频| 极品尤物av久久免费看| 在线视频综合导航| 2021久久国产精品不只是精品| 亚洲一区二区四区蜜桃| 国产福利电影一区二区三区| 欧美精品日韩一本| 国产精品日韩成人| 免费观看一级特黄欧美大片| 91热门视频在线观看| 精品日韩欧美一区二区| 亚洲激情在线激情| 国产精品一区在线| 69成人精品免费视频| 国产精品福利一区二区| 黄色日韩网站视频| 欧美中文字幕久久| 国产精品三级视频| 国产精品一二三四区| 69堂成人精品免费视频| 亚洲免费色视频| 国产精品中文字幕欧美| 日韩精品中文字幕在线不卡尤物 | 欧美在线观看一区二区| 国产亚洲精品aa| 日韩精品免费视频人成| 91免费版pro下载短视频| 久久久久国产精品厨房| 裸体歌舞表演一区二区| 欧美日韩专区在线| 一区二区三区欧美视频| 99久久精品99国产精品| 亚洲精品一区二区三区香蕉 | 一区二区免费在线播放| 国产成人精品免费视频网站| 欧美一级日韩免费不卡| 亚洲高清视频中文字幕| 欧美三级韩国三级日本三斤| 亚洲欧美另类小说| 99热这里都是精品| 欧美国产日产图区| 国产精品综合一区二区| 精品乱人伦一区二区三区| 欧美a一区二区| 欧美精品自拍偷拍| 天堂在线亚洲视频| 精品视频在线看| 天堂一区二区在线| 欧美日韩大陆一区二区| 亚洲午夜影视影院在线观看| 欧美主播一区二区三区美女| 亚洲一线二线三线视频| 欧美视频一区二区三区| 亚洲一级二级三级在线免费观看| 精品视频全国免费看| 图片区小说区国产精品视频| 日韩一区二区在线观看视频播放| 日本伊人色综合网| 精品久久久久久久人人人人传媒| 精品综合免费视频观看| 精品国产乱码久久久久久老虎| 久久99精品国产.久久久久久| 亚洲精品一区二区三区精华液 | 亚洲综合丁香婷婷六月香| 在线国产亚洲欧美| 日韩中文字幕亚洲一区二区va在线| 欧美日韩国产一级二级| 日本亚洲免费观看| 久久婷婷国产综合精品青草| 成人做爰69片免费看网站| 亚洲视频香蕉人妖| 欧美日本免费一区二区三区| 日韩av中文在线观看| 久久精品视频在线免费观看| 丁香亚洲综合激情啪啪综合| 国产精品第五页| 欧美日韩久久一区二区| 精品一区二区三区在线播放| 欧美国产成人在线| 91蜜桃在线观看| 看电影不卡的网站| 中文字幕色av一区二区三区| 欧美亚洲国产一区二区三区va | 99精品国产99久久久久久白柏| 亚洲精品成人悠悠色影视| 欧美一区二区二区| 成人免费视频视频在线观看免费 | 欧美va亚洲va| bt欧美亚洲午夜电影天堂| 亚洲国产中文字幕| 精品少妇一区二区三区日产乱码 | 97aⅴ精品视频一二三区| 亚洲一区在线播放| 精品国免费一区二区三区| 白白色 亚洲乱淫| 日日噜噜夜夜狠狠视频欧美人 | 国产日本一区二区| 欧美亚洲精品一区| 国产高清在线观看免费不卡| 伊人一区二区三区| 久久先锋影音av鲁色资源网| 在线观看欧美黄色| 国产大陆精品国产| 丝袜亚洲另类丝袜在线| 中文字幕中文字幕在线一区| 在线播放日韩导航| 波多野结衣欧美| 久久国内精品视频| 国产精品的网站| 欧美tickling网站挠脚心| 欧美三级电影在线观看| 成人av资源网站| 国产在线视视频有精品| 视频一区二区欧美| 一区二区三区国产精华| 中文字幕第一区综合|