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

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

?? t3dlib1.cpp

?? 一本外國人寫的關于3D游戲編程的書的源碼
?? CPP
?? 第 1 頁 / 共 5 頁
字號:
// 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

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲第一会所有码转帖| 成人一区二区三区中文字幕| 狠狠色2019综合网| 不卡大黄网站免费看| 3d成人h动漫网站入口| 国产精品天干天干在观线| 婷婷开心久久网| 99久久夜色精品国产网站| 日韩免费一区二区| 亚洲成人tv网| 91蝌蚪porny| 欧美高清在线视频| 亚洲激情在线激情| 国产乱码一区二区三区| 黑人精品欧美一区二区蜜桃 | 中国色在线观看另类| 亚洲一区二区av电影| av亚洲精华国产精华精| 久久一夜天堂av一区二区三区| 日本欧美大码aⅴ在线播放| 色噜噜狠狠一区二区三区果冻| 欧美激情自拍偷拍| 国产精品综合一区二区| 日韩久久免费av| 午夜激情久久久| 欧美日韩精品一区二区三区蜜桃| 亚洲精品福利视频网站| 色综合色狠狠综合色| 亚洲欧美偷拍三级| 91丨porny丨中文| 中文字幕一区二区在线播放 | 婷婷久久综合九色综合伊人色| 色偷偷久久一区二区三区| 国产精品每日更新在线播放网址| 国产成人亚洲综合a∨婷婷图片 | 久久er精品视频| 精品国产污污免费网站入口 | 午夜电影网一区| 欧美精三区欧美精三区| 图片区小说区区亚洲影院| 欧美日韩色综合| 欧美aaa在线| 精品福利一区二区三区| 国产成人午夜精品影院观看视频| 久久亚洲综合色一区二区三区| 经典三级视频一区| 国产日韩一级二级三级| av福利精品导航| 一区二区三区精品久久久| 欧美亚洲国产bt| 麻豆国产一区二区| 国产亚洲人成网站| 91美女福利视频| 日韩精品久久理论片| 精品99久久久久久| 成人av手机在线观看| 夜夜精品浪潮av一区二区三区| 欧美欧美午夜aⅴ在线观看| 麻豆免费精品视频| 中文幕一区二区三区久久蜜桃| 一本色道久久综合狠狠躁的推荐| 亚洲第一成年网| 久久蜜臀精品av| 91麻豆123| 精品一区二区三区影院在线午夜 | 日韩欧美中文字幕制服| 国产精品99久久久久久宅男| 亚洲女人的天堂| 精品人在线二区三区| 91网上在线视频| 麻豆精品在线视频| 国产精品不卡在线观看| 欧美一区二区视频在线观看2020| 高清beeg欧美| 天天综合网 天天综合色| 国产精品美女久久久久久久| 欧美日精品一区视频| 高清日韩电视剧大全免费| 日韩电影在线免费| 亚洲激情图片qvod| 欧美激情一二三区| 91麻豆精品久久久久蜜臀| 99国产精品久久久久久久久久 | 亚洲三级在线观看| 久久尤物电影视频在线观看| 在线观看成人免费视频| 成人精品视频一区二区三区 | 成人av电影免费在线播放| 久久精品理论片| 亚洲在线观看免费| 综合亚洲深深色噜噜狠狠网站| 日韩亚洲欧美中文三级| 欧美系列一区二区| 99r国产精品| 成人深夜福利app| 久久99精品久久久久久动态图| 一区二区三区日韩欧美精品| 欧美国产日韩精品免费观看| 日韩精品一区二区三区四区| 欧美日韩高清一区二区不卡| 99精品1区2区| av亚洲精华国产精华精| 成人理论电影网| 国产成人在线视频网址| 国模冰冰炮一区二区| 免费视频最近日韩| 日韩福利电影在线观看| 亚洲第一成人在线| 午夜免费欧美电影| 亚洲国产美国国产综合一区二区| 亚洲日本电影在线| 亚洲男人的天堂网| 日韩一区在线播放| 亚洲三级久久久| 成人欧美一区二区三区黑人麻豆 | a亚洲天堂av| 91视频xxxx| 日本韩国精品一区二区在线观看| 一本大道久久a久久精品综合| 91污片在线观看| 91丨九色porny丨蝌蚪| 色欧美片视频在线观看| 91成人看片片| 欧美日韩一区小说| 欧美一激情一区二区三区| 日韩一区二区在线观看视频| 日韩午夜激情免费电影| 精品成人一区二区三区四区| 国产欧美日韩三级| 国产精品第五页| 亚洲在线视频网站| 久久精品国产免费| 成人精品国产福利| 在线亚洲免费视频| 欧美大片一区二区三区| 久久久久久久久久久久电影| 中文字幕欧美国产| 亚洲最大成人综合| 美女视频一区二区| 国产不卡一区视频| 色偷偷88欧美精品久久久 | 色噜噜狠狠一区二区三区果冻| 欧美日精品一区视频| 久久这里只有精品6| 国产精品久久免费看| 一区二区久久久久| 激情图片小说一区| 91欧美一区二区| 欧美一二三区在线| 亚洲欧美国产三级| 精品写真视频在线观看| 99久精品国产| 日韩一区二区影院| 亚洲啪啪综合av一区二区三区| 日韩中文字幕区一区有砖一区| 韩国在线一区二区| 色8久久人人97超碰香蕉987| 日韩一本二本av| 一区二区三区久久| 成人深夜在线观看| 日韩一区二区三区电影在线观看| 中文av一区二区| 麻豆精品在线观看| 欧美四级电影在线观看| 国产欧美精品在线观看| 午夜精品在线看| 91色在线porny| 精品国产一区a| 视频一区视频二区中文字幕| 91免费精品国自产拍在线不卡| 欧美大白屁股肥臀xxxxxx| 亚洲日本韩国一区| 成熟亚洲日本毛茸茸凸凹| 精品少妇一区二区三区在线视频| 亚洲激情综合网| 99免费精品视频| 欧美国产日韩在线观看| 韩国一区二区在线观看| 欧美卡1卡2卡| 亚洲成人精品在线观看| 色综合久久综合网欧美综合网| 国产日韩精品一区| 久久99国产精品尤物| 欧美高清视频www夜色资源网| 亚洲美女在线国产| av在线一区二区| 中文字幕不卡的av| 丁香啪啪综合成人亚洲小说| 久久色视频免费观看| 精品一区二区三区不卡| 日韩一区二区精品葵司在线| 午夜电影一区二区三区| 欧美色网站导航| 五月综合激情日本mⅴ| 欧美在线综合视频| 亚洲一区二区三区在线| 色丁香久综合在线久综合在线观看| 日韩毛片高清在线播放| 色综合中文字幕国产| 国产精品免费视频网站|