// 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;
// cr
没有合适的资源?快使用搜索试试~ 我知道了~
windows游戏编程大师技巧源码
共195个文件
cpp:159个
h:25个
rc:4个
5星 · 超过95%的资源 需积分: 0 44 下载量 150 浏览量
2008-09-13
12:15:58
上传
评论
收藏 930KB RAR 举报
温馨提示
windows游戏编程大师技巧书上所以例子的源码 一共15张 windows游戏编程大师技巧是windows 2d游戏开发的经典之作
资源推荐
资源详情
资源评论
收起资源包目录
windows游戏编程大师技巧源码 (195个子文件)
aliensglow_24.bmp 900KB
aliensglow.bmp 301KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
t3dlib1.cpp 174KB
outpost.cpp 136KB
demo12_3.cpp 113KB
demo12_7_16b.cpp 65KB
demo12_7.cpp 63KB
Shadow.cpp 63KB
demo8_6.cpp 35KB
demo8_8.cpp 35KB
demo7_14.cpp 34KB
demo8_7.cpp 34KB
demo8_9.cpp 32KB
demo7_13.cpp 30KB
demo12_6_16b.cpp 29KB
demo8_4.cpp 27KB
demo12_6.cpp 27KB
demo8_5.cpp 27KB
demo13_10.cpp 25KB
demo8_3.cpp 25KB
demo7_15.cpp 24KB
t3dlib3.cpp 22KB
t3dlib3.cpp 22KB
t3dlib3.cpp 22KB
t3dlib3.cpp 22KB
t3dlib3.cpp 22KB
demo13_8_16b.cpp 22KB
demo8_2.cpp 21KB
demo9_4_16b.cpp 21KB
demo9_2_16b.cpp 20KB
demo13_8.cpp 20KB
demo12_5_16b.cpp 19KB
demo9_4.cpp 19KB
demo9_2a_16b.cpp 19KB
demo9_3_16b.cpp 19KB
demo7_16.cpp 18KB
demo10_3.cpp 18KB
demo7_9.cpp 18KB
demo9_1_16b.cpp 18KB
demo9_2.cpp 18KB
demo12_5.cpp 18KB
demo12_8_16b.cpp 17KB
demo7_10.cpp 17KB
demo9_3.cpp 17KB
demo13_7_16b.cpp 17KB
demo7_8.cpp 17KB
demo9_2a.cpp 16KB
demo9_1a_16b.cpp 16KB
demo9_1.cpp 16KB
demo13_4_16b.cpp 16KB
demo9_3a_16b.cpp 16KB
demo7_11.cpp 16KB
demo7_12.cpp 16KB
demo13_9_16b.cpp 16KB
freakout.cpp 16KB
demo13_7.cpp 15KB
demo12_8.cpp 15KB
demo8_10_16b.cpp 15KB
demo13_3_16b.cpp 15KB
demo8_12_16b.cpp 15KB
demo9_1a.cpp 15KB
demo7_7.cpp 14KB
demo8_1.cpp 14KB
demo13_4.cpp 14KB
demo13_9.cpp 14KB
demo9_3a.cpp 14KB
demo13_5_16b.cpp 14KB
demo8_12.cpp 13KB
demo8_10.cpp 13KB
demo11_10_16b.cpp 13KB
demo13_3.cpp 13KB
demo12_4_16b.cpp 13KB
demo13_2_16b.cpp 13KB
demo10_4.cpp 13KB
demo12_2_16b.cpp 12KB
demo13_6_16b.cpp 12KB
blackbox.cpp 12KB
demo8_11_16b.cpp 12KB
demo7_19.cpp 12KB
demo7_4.cpp 12KB
demo13_11_16b.cpp 12KB
demo13_1_16b.cpp 12KB
demo12_1_16b.cpp 12KB
demo13_5.cpp 12KB
demo7_5.cpp 11KB
demo11_10.cpp 11KB
demo6_3.cpp 11KB
demo13_2.cpp 11KB
demo7_17.cpp 11KB
demo8_11.cpp 11KB
demo12_4.cpp 11KB
demo10_6.cpp 11KB
demo7_2.cpp 11KB
demo13_6.cpp 10KB
共 195 条
- 1
- 2
wingkueng1
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页