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

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

?? t3dlib1.cpp

?? 一本外國人寫的關(guān)于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一区二区三区免费野_久草精品视频
色网站国产精品| 国产在线一区二区| 精品久久久久99| 欧美亚洲动漫制服丝袜| 国产一区二区三区在线观看精品| 亚洲欧美一区二区三区国产精品| 欧美成人在线直播| 欧美老女人第四色| 99久久久国产精品| 夫妻av一区二区| 国产精品日韩成人| 91黄色免费看| 91官网在线观看| 色综合激情五月| 色婷婷精品久久二区二区蜜臀av| 国产综合久久久久久鬼色 | 国产成人午夜电影网| 蜜臀久久久99精品久久久久久| 亚洲成人综合在线| 日韩高清在线电影| 偷窥国产亚洲免费视频| 香蕉乱码成人久久天堂爱免费| 一区二区三区色| 午夜欧美2019年伦理| 成人午夜视频网站| av一区二区久久| 国产一区日韩二区欧美三区| 国产日本亚洲高清| 日韩免费视频一区二区| 韩国女主播成人在线观看| 日韩国产欧美三级| 亚洲欧美日韩在线不卡| 精品国产乱码久久久久久免费| 欧美日韩国产高清一区| 欧美蜜桃一区二区三区| 在线观看日韩毛片| 欧美美女bb生活片| 一区二区高清免费观看影视大全| 亚洲欧美日韩系列| 日韩中文字幕麻豆| 国产在线国偷精品产拍免费yy| 国产麻豆91精品| 色综合久久中文综合久久97| 欧美高清一级片在线| 精品国产免费一区二区三区四区| 欧美激情在线观看视频免费| 夜夜嗨av一区二区三区四季av| 午夜欧美2019年伦理| 福利视频网站一区二区三区| 一本一道综合狠狠老| 日韩视频中午一区| 国产欧美日韩亚州综合| 亚洲精品国产成人久久av盗摄| 婷婷激情综合网| 不卡欧美aaaaa| 日韩精品一区在线| 亚洲一二三专区| 91香蕉视频污| 欧美精品一区二区三区在线| 首页欧美精品中文字幕| 日本韩国视频一区二区| 国产精品美女久久久久久久久久久 | 国产精品一区二区三区99| 国产自产视频一区二区三区| 欧美私模裸体表演在线观看| 成人免费在线视频| www.av精品| 欧美国产日本视频| 91在线视频官网| 久久久久久久久久看片| 日韩电影在线观看一区| 在线亚洲免费视频| 综合网在线视频| 91麻豆精品在线观看| 一色桃子久久精品亚洲| 91女人视频在线观看| 亚洲欧美另类久久久精品| 99久久综合精品| 亚洲免费在线播放| 欧美性大战久久久久久久蜜臀| 国产精品免费视频一区| 99久精品国产| 一区二区三区在线观看动漫| 日本道色综合久久| 天天免费综合色| 337p日本欧洲亚洲大胆色噜噜| 国产精品综合一区二区| 中文字幕av一区二区三区| av中文字幕不卡| 视频在线观看国产精品| 久久久国产精华| 色婷婷久久综合| 日韩av电影免费观看高清完整版| 欧美日高清视频| 精品一区二区免费视频| 日韩欧美国产综合一区| 国产999精品久久久久久| 国产精品沙发午睡系列990531| 色女孩综合影院| 国模冰冰炮一区二区| 国产精品欧美一区喷水| 欧美曰成人黄网| 精彩视频一区二区三区| 国产精品毛片久久久久久久| 色欧美乱欧美15图片| 久久国产三级精品| 国产精品福利电影一区二区三区四区| 色综合夜色一区| 国产一区二区不卡老阿姨| 亚洲免费毛片网站| 欧美日韩成人综合在线一区二区| 国产一区二区不卡| 成人性生交大片| 一区二区不卡在线视频 午夜欧美不卡在 | 国产一区二区三区日韩| 一区二区三区视频在线观看| 久久久国产午夜精品| 精品久久久久一区| 欧美美女一区二区| 欧美亚洲丝袜传媒另类| av电影天堂一区二区在线| 国产成a人无v码亚洲福利| 亚洲情趣在线观看| 中文字幕欧美国产| 久久这里只有精品首页| 制服丝袜国产精品| 精品欧美一区二区在线观看| 69精品人人人人| 欧美一卡二卡三卡四卡| 欧美日韩国产一级片| 欧美色精品在线视频| 欧美二区三区91| 精品粉嫩aⅴ一区二区三区四区| 欧美福利视频导航| 欧美成人三级电影在线| 久久久久久黄色| 国产精品国产三级国产普通话99| 亚洲欧美日本韩国| 日韩综合小视频| 国产一区不卡精品| www.成人在线| 884aa四虎影成人精品一区| 日韩欧美中文一区二区| 国产视频一区二区三区在线观看 | 一区二区免费在线播放| 免费成人结看片| 成人激情图片网| 欧美精品自拍偷拍动漫精品| 日韩欧美一级二级| 亚洲欧洲日韩在线| 日韩电影在线看| 欧美在线制服丝袜| 欧美一卡二卡在线观看| 欧美精品一区二区蜜臀亚洲| 久久久久久久久久久久久久久99| 亚洲欧美日韩在线不卡| 日本vs亚洲vs韩国一区三区二区| 蜜桃91丨九色丨蝌蚪91桃色| 欧美伊人久久久久久久久影院| 欧美另类高清zo欧美| 久久久久久久久久看片| 一区二区三区在线免费| 极品销魂美女一区二区三区| 91麻豆国产在线观看| 日韩免费性生活视频播放| 国产精品久久久久桃色tv| 麻豆精品一二三| 欧美日韩国产综合久久| 中文字幕+乱码+中文字幕一区| 亚洲图片欧美综合| 91丨九色丨国产丨porny| 精品久久久久久无| 亚洲不卡在线观看| 色琪琪一区二区三区亚洲区| 国产午夜精品理论片a级大结局 | 日本一区二区三区在线不卡| 国产一区二区三区在线观看免费| 日韩欧美www| 国产在线精品视频| 精品盗摄一区二区三区| 国内精品国产成人| 精品剧情在线观看| 麻豆精品新av中文字幕| 欧美色图在线观看| 一区二区三区在线免费播放| 94色蜜桃网一区二区三区| 久久色视频免费观看| 国产真实乱子伦精品视频| 日韩欧美专区在线| 激情欧美一区二区| 中文字幕高清一区| 成人高清在线视频| 亚洲精品视频观看| 91久久人澡人人添人人爽欧美| 亚洲日韩欧美一区二区在线| 欧美日韩日日摸| 毛片av中文字幕一区二区| 国产日本亚洲高清| 日本福利一区二区| 久草精品在线观看|