亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
色先锋aa成人| 欧美极品另类videosde| 欧美韩日一区二区三区| 亚洲va韩国va欧美va| 懂色av中文字幕一区二区三区| 欧美性猛片xxxx免费看久爱| 国产精品丝袜91| 久久激情五月激情| 91精品久久久久久久久99蜜臂| 亚洲日本韩国一区| 成人免费高清视频| 精品美女在线观看| 欧美bbbbb| 欧美日韩mp4| 亚洲国产aⅴ天堂久久| 91在线porny国产在线看| 久久精品网站免费观看| 久久99国产精品尤物| 欧美精品日韩一本| 亚洲午夜私人影院| 欧美色图免费看| 亚洲精品成人悠悠色影视| 99免费精品视频| 国产精品色婷婷| 高清在线成人网| 欧美国产日韩亚洲一区| 久久99九九99精品| 精品剧情v国产在线观看在线| 青草国产精品久久久久久| 欧美精品国产精品| 婷婷综合五月天| 91精品国产91久久久久久一区二区 | 亚洲va欧美va人人爽午夜| 在线视频一区二区三| 亚洲精品免费在线| 精品视频全国免费看| 亚洲成av人片在线| 91精品一区二区三区在线观看| 香蕉加勒比综合久久| 91麻豆精品国产91久久久久久久久| 亚洲第一会所有码转帖| 欧美高清视频一二三区 | 国产精品综合一区二区三区| 亚洲精品一线二线三线| 国产电影精品久久禁18| 中文字幕欧美激情| 色综合一个色综合| 亚洲高清不卡在线观看| 日韩欧美国产精品一区| 国产精品69毛片高清亚洲| 亚洲天堂久久久久久久| 欧美日韩在线免费视频| 久久99精品国产.久久久久久| 久久久国产精品不卡| 91免费看`日韩一区二区| 亚洲国产成人av| 亚洲精品在线电影| 色8久久人人97超碰香蕉987| 丝袜诱惑制服诱惑色一区在线观看| 日韩欧美资源站| av电影一区二区| 日韩黄色免费电影| 中文字幕一区在线观看视频| 欧美日韩一级大片网址| 激情文学综合丁香| 亚洲一区二三区| 国产午夜精品一区二区三区嫩草| 日本韩国一区二区三区视频| 日韩高清在线观看| 1024国产精品| 26uuu久久天堂性欧美| 91麻豆免费视频| 激情深爱一区二区| 亚洲一区二区三区在线看| 久久久久亚洲蜜桃| 欧美日韩精品专区| 99在线精品观看| 国内国产精品久久| 天天综合天天做天天综合| 国产精品久久久久三级| 日韩午夜三级在线| 色婷婷香蕉在线一区二区| 国产精品18久久久久久vr| 亚洲午夜免费电影| 中文字幕制服丝袜成人av| 欧美不卡视频一区| 欧美日韩电影在线| 色爱区综合激月婷婷| 波多野结衣中文一区| 国产乱码一区二区三区| 丝袜脚交一区二区| 亚洲日本乱码在线观看| 国产精品网友自拍| 久久亚洲精品国产精品紫薇| 欧美一区二区成人6969| 欧美日韩成人一区二区| 99久久精品99国产精品| 成人综合婷婷国产精品久久免费| 九九**精品视频免费播放| 午夜精品一区在线观看| 亚洲综合激情另类小说区| 亚洲美女一区二区三区| 国产精品久久久久久亚洲伦| 日本一区二区成人| 中日韩免费视频中文字幕| 26uuu亚洲综合色| 精品国产免费一区二区三区四区| 欧美精品久久天天躁| 制服丝袜成人动漫| 4438x亚洲最大成人网| 欧美男人的天堂一二区| 欧美精品久久久久久久多人混战| 欧美日韩国产美女| 欧美伦理电影网| 666欧美在线视频| 91精品国产综合久久精品app| 欧美日韩黄色一区二区| 在线电影国产精品| 欧美一区二区福利在线| 欧美一区二区三区婷婷月色| 欧美一区二区三区播放老司机| 欧美一级一区二区| 久久久久久久久久久99999| 中文字幕电影一区| 亚洲免费观看高清完整版在线观看| **性色生活片久久毛片| 亚洲高清免费视频| 蜜桃久久久久久久| 国产乱对白刺激视频不卡| 成人av在线一区二区| 色菇凉天天综合网| 91精品国产91久久综合桃花| www激情久久| 亚洲欧洲国产专区| 天涯成人国产亚洲精品一区av| 久久精品国产77777蜜臀| 精彩视频一区二区| 粉嫩av亚洲一区二区图片| 91福利视频在线| 精品国产髙清在线看国产毛片| 国产亚洲精品中文字幕| 亚洲精品一二三四区| 麻豆一区二区三区| 91丨porny丨最新| 日韩欧美一二三四区| 国产精品久久久久久久久搜平片| 一区二区三区电影在线播| 蜜臀av一级做a爰片久久| 成人黄页毛片网站| 欧美日本精品一区二区三区| 久久久www免费人成精品| 亚洲综合免费观看高清完整版在线 | 久久综合久久综合久久| 日韩美女久久久| 久久99精品一区二区三区| 97久久精品人人做人人爽50路| 91精品国产色综合久久久蜜香臀| 国产欧美日韩亚州综合| 婷婷亚洲久悠悠色悠在线播放| 国产成人午夜精品影院观看视频 | 日韩三级高清在线| 亚洲欧美激情小说另类| 国内精品不卡在线| 欧美嫩在线观看| 中文字幕日韩av资源站| 激情图区综合网| 欧美精品成人一区二区三区四区| 国产蜜臀97一区二区三区| 免费一区二区视频| 欧美日韩中文国产| 亚洲日本青草视频在线怡红院| 99视频精品免费视频| 91精品国产91热久久久做人人| 亚洲少妇30p| 福利视频网站一区二区三区| 91精品国产色综合久久不卡电影| 亚洲人妖av一区二区| 国产伦精品一区二区三区视频青涩 | 在线视频中文字幕一区二区| 国产性做久久久久久| 美腿丝袜一区二区三区| 欧美亚洲一区二区在线| 综合久久久久综合| 丁香亚洲综合激情啪啪综合| 欧美成人性战久久| 日韩影视精彩在线| 欧美中文字幕一区| 一区二区三区精密机械公司| 99久久99久久免费精品蜜臀| 欧美激情在线看| 国产自产高清不卡| 久久久美女艺术照精彩视频福利播放| 免播放器亚洲一区| 日韩免费高清视频| 精品一区二区久久| 2021国产精品久久精品| 久久99精品一区二区三区三区| 在线电影欧美成精品| 日韩av电影一区| 日韩午夜三级在线|