亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
91麻豆精品国产91久久久久久久久| 日本一二三四高清不卡| 国内精品国产三级国产a久久| 国产精品成人免费| 久久伊人蜜桃av一区二区| 欧美日韩精品福利| 欧美日韩一级黄| 欧美片网站yy| 日韩毛片在线免费观看| 国产精品色呦呦| 亚洲人一二三区| 国产毛片精品一区| 波波电影院一区二区三区| 国产福利精品一区| 99国产欧美另类久久久精品| 在线观看日韩精品| 欧美色爱综合网| 一区二区中文视频| 亚洲国产欧美在线| 午夜av电影一区| 久久97超碰色| 豆国产96在线|亚洲| 91免费版在线| 精品1区2区3区| 一区二区三区久久久| 亚洲成a人片综合在线| 狠狠网亚洲精品| 911精品国产一区二区在线| 一区二区三区日本| 99这里都是精品| 国产精品毛片久久久久久久| 国产精品18久久久久| 日本高清不卡视频| 日韩一区二区不卡| 欧美韩国一区二区| 丁香激情综合国产| 91精品国产福利在线观看| 国产欧美日韩三级| 青青草视频一区| 成人动漫一区二区| 日韩免费看的电影| 一级日本不卡的影视| 91亚洲大成网污www| 亚洲一区视频在线| jizz一区二区| 亚洲人成影院在线观看| 久久福利视频一区二区| 99视频在线精品| ...xxx性欧美| 欧美体内she精高潮| 中文字幕在线免费不卡| 99v久久综合狠狠综合久久| 一区二区三区**美女毛片| 欧美视频一区二| 精品亚洲porn| 国产精品久久久久久久久免费丝袜 | 国产成人自拍网| 一区免费观看视频| 欧美精品欧美精品系列| 亚洲色图视频网| 7777精品伊人久久久大香线蕉 | 日韩午夜激情免费电影| av一区二区三区黑人| 亚洲欧美日韩精品久久久久| 欧美精品久久久久久久多人混战 | 日韩女优视频免费观看| 国产不卡一区视频| 亚洲综合视频在线| 欧美mv日韩mv国产网站| 亚洲一区二区三区美女| 日韩欧美激情四射| 91在线视频免费91| 麻豆精品一区二区三区| 日韩一区二区不卡| 99久久精品免费精品国产| 香蕉乱码成人久久天堂爱免费| 日韩欧美激情四射| 色综合久久六月婷婷中文字幕| 久久久久99精品一区| 狠狠狠色丁香婷婷综合久久五月| 国产精品二三区| 精品美女一区二区| 欧美性欧美巨大黑白大战| 国产在线看一区| 一区二区在线观看免费视频播放| 99精品视频中文字幕| 久久精品72免费观看| 亚洲一线二线三线久久久| 国产亚洲精品aa午夜观看| 福利电影一区二区| 蜜桃传媒麻豆第一区在线观看| 亚洲人成伊人成综合网小说| 国产亚洲一区字幕| 日韩一级视频免费观看在线| 欧美亚洲综合在线| 91日韩在线专区| 国产一区在线不卡| 日韩高清不卡一区| 久久久久国产一区二区三区四区| 欧美精选一区二区| 在线亚洲一区观看| 91丨国产丨九色丨pron| 丁香六月综合激情| 丰满少妇在线播放bd日韩电影| 蜜臀久久99精品久久久久久9| 亚洲一区二区免费视频| 亚洲精品欧美激情| 1024成人网| 中文欧美字幕免费| 亚洲国产精品国自产拍av| 久久先锋影音av| 久久九九国产精品| 国产无人区一区二区三区| 精品国产一二三| 欧美午夜视频网站| 精品视频1区2区3区| 欧美午夜电影一区| 欧美午夜不卡视频| 欧美日韩另类国产亚洲欧美一级| 91麻豆精品一区二区三区| 99精品国产91久久久久久| 波多野结衣中文一区| 91一区二区在线观看| 91视频你懂的| 91福利在线播放| 欧洲av一区二区嗯嗯嗯啊| 欧洲国内综合视频| 91精品久久久久久久91蜜桃| 日韩欧美一卡二卡| 久久九九久久九九| 亚洲丝袜自拍清纯另类| 一区二区三区 在线观看视频| 日日夜夜一区二区| 亚洲精品视频在线| 亚洲国产日韩a在线播放性色| 日韩制服丝袜先锋影音| 精品一区二区综合| 99久久精品一区| 欧美日韩一二三| 欧美大片免费久久精品三p | 国产在线观看一区二区| 国产91精品一区二区麻豆网站| 97aⅴ精品视频一二三区| 欧美视频在线不卡| 欧美v亚洲v综合ⅴ国产v| 国产精品久久影院| 亚洲午夜久久久久久久久电影院| 天天综合日日夜夜精品| 精品一二三四在线| 91色综合久久久久婷婷| 欧美一个色资源| 国产精品美女久久久久av爽李琼| 亚洲一线二线三线视频| 国产一区二区毛片| 欧美色图第一页| 久久久高清一区二区三区| 亚洲一区在线观看免费| 国产一区二区三区免费| 日本韩国一区二区三区视频| 日韩精品一区二| 亚洲黄网站在线观看| 国产一区二区三区香蕉| 欧美午夜宅男影院| 欧美极品xxx| 免费精品视频在线| 日本高清不卡视频| 久久久777精品电影网影网| 午夜精品成人在线视频| 97精品超碰一区二区三区| 欧美xxxxx裸体时装秀| 亚洲精品国产成人久久av盗摄| 国产自产2019最新不卡| 欧美精品一二三四| 亚洲另类中文字| 粉嫩aⅴ一区二区三区四区| 日韩一区二区三区四区| 亚洲综合小说图片| 成人国产精品免费观看视频| 欧美一区二区精品久久911| 一区二区不卡在线播放 | 亚洲色图欧洲色图婷婷| 国产成a人无v码亚洲福利| 欧美一区二区三区精品| 亚洲一区二区精品3399| 91老师国产黑色丝袜在线| 26uuu色噜噜精品一区二区| 午夜亚洲国产au精品一区二区| 97精品国产97久久久久久久久久久久| 精品理论电影在线观看| 久久精品国产亚洲a| 91精品国产色综合久久不卡电影 | 日韩精品一区第一页| 色综合久久99| 综合久久给合久久狠狠狠97色| 国产成人综合亚洲网站| 久久精品一区蜜桃臀影院| 国产一区二区三区日韩| 精品国产123| 国产一区二区导航在线播放| 精品久久久久久无|