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

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

?? demo8_7.cpp

?? 一本外國人寫的關(guān)于3D游戲編程的書的源碼
?? CPP
?? 第 1 頁 / 共 3 頁
字號(hào):
// DEMO8_7.CPP 8-bit triangle drawing demo

// INCLUDES ///////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#define INITGUID

#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 <ddraw.h> // include directdraw

// DEFINES ////////////////////////////////////////////////

// defines for windows 
#define WINDOW_CLASS_NAME "WINCLASS1"

// default screen size
#define SCREEN_WIDTH    640  // size of screen
#define SCREEN_HEIGHT   480
#define SCREEN_BPP      8    // bits per pixel

#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define MAX_COLORS_PALETTE   256

const double PI = 3.1415926535;

// fixed point mathematics constants
#define FIXP16_SHIFT     16
#define FIXP16_MAG       65536
#define FIXP16_DP_MASK   0x0000ffff
#define FIXP16_WP_MASK   0xffff0000
#define FIXP16_ROUND_UP  0x00008000

// TYPES //////////////////////////////////////////////////////

// basic unsigned types
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char  UCHAR;
typedef unsigned char  BYTE;

// a 2D vertex
typedef struct VERTEX2DI_TYP
        {
        int x,y; // the vertex
        } VERTEX2DI, *VERTEX2DI_PTR;

// a 2D vertex
typedef struct VERTEX2DF_TYP
        {
        float x,y; // the vertex
        } VERTEX2DF, *VERTEX2DF_PTR;


// a 2D polygon
typedef struct POLYGON2D_TYP
        {
        int state;        // state of polygon
        int num_verts;    // number of vertices
        int x0,y0;        // position of center of polygon  
        int xv,yv;        // initial velocity
        DWORD color;      // could be index or PALETTENTRY
        VERTEX2DF *vlist; // pointer to vertex list
 
        } POLYGON2D, *POLYGON2D_PTR;


// PROTOTYPES  //////////////////////////////////////////////

int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color);

// 2d 8-bit triangle rendering
void Draw_Top_Tri(int x1,int y1,int x2,int y2, int x3,int y3,int color,UCHAR *dest_buffer, int mempitch);

void Draw_Bottom_Tri(int x1,int y1, int x2,int y2, int x3,int y3,int color,UCHAR *dest_buffer, int mempitch);

void Draw_Top_TriFP(int x1,int y1,int x2,int y2, int x3,int y3,int color,UCHAR *dest_buffer, int mempitch);

void Draw_Bottom_TriFP(int x1,int y1, int x2,int y2, int x3,int y3,int color,UCHAR *dest_buffer, int mempitch);

void Draw_Triangle_2D(int x1,int y1,int x2,int y2,int x3,int y3,
                      int color,UCHAR *dest_buffer, int mempitch);

void Draw_TriangleFP_2D(int x1,int y1,int x2,int y2,int x3,int y3,
                        int color,UCHAR *dest_buffer, int mempitch);

int Translate_Polygon2D(POLYGON2D_PTR poly, int dx, int dy);

int Rotate_Polygon2D(POLYGON2D_PTR poly, int theta);

int Scale_Polygon2D(POLYGON2D_PTR poly, float sx, float sy);

int Set_Palette_Entry(int color_index, LPPALETTEENTRY color);

int Draw_Text_GDI(char *text, int x,int y,int color, LPDIRECTDRAWSURFACE7 lpdds);

// MACROS /////////////////////////////////////////////////

// tests if a key is up or down
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// initializes a direct draw struct
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

// some math macros
#define DEG_TO_RAD(ang) ((ang)*PI/180)
#define RAD_TO_DEG(rads) ((rads)*180/PI)

// GLOBALS ////////////////////////////////////////////////

HWND      main_window_handle = NULL; // globally track main window
int       window_closed      = 0;    // tracks if window is closed
HINSTANCE hinstance_app      = NULL; // globally track hinstance

// directdraw stuff
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
PALETTEENTRY          palette[256];          // color palette
PALETTEENTRY          save_palette[256];     // 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
DWORD                 start_clock_count = 0; // used for timing


// global clipping region

int min_clip_x = 0,      // clipping rectangle 
    max_clip_x = SCREEN_WIDTH - 1,
    min_clip_y = 0,
    max_clip_y = SCREEN_HEIGHT - 1;

char buffer[80];                             // general printing buffer

// storage for our lookup tables
float cos_look[360];
float sin_look[360];

POLYGON2D object; // the polygon object

// FUNCTIONS ////////////////////////////////////////////////

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

void Draw_Top_TriFP(int x1,int y1,
                    int x2,int y2, 
                    int x3,int y3,
                    int color, 
                    UCHAR *dest_buffer, int mempitch)
{
// this function draws a triangle that has a flat top using fixed point math

int dx_right,    // the dx/dy ratio of the right edge of line
    dx_left,     // the dx/dy ratio of the left edge of line
    xs,xe,       // the starting and ending points of the edges
    height;      // the height of the triangle

int temp_x,        // used during sorting as temps
    temp_y,
    right,         // used by clipping
    left;

UCHAR  *dest_addr;

// test for degenerate
if (y1==y3 || y2==y3)
	return;

// test order of x1 and x2
if (x2 < x1)
   {
   temp_x = x2;
   x2     = x1;
   x1     = temp_x;
   } // end if swap

// compute delta's
height = y3-y1;

dx_left  = ((x3-x1)<<FIXP16_SHIFT)/height;
dx_right = ((x3-x2)<<FIXP16_SHIFT)/height;

// set starting points
xs = (x1<<FIXP16_SHIFT);
xe = (x2<<FIXP16_SHIFT);

// perform y clipping
if (y1<min_clip_y)
   {
   // compute new xs and ys
   xs = xs+dx_left*(-y1+min_clip_y);
   xe = xe+dx_right*(-y1+min_clip_y);

   // reset y1
   y1=min_clip_y;

   } // end if top is off screen

if (y3>max_clip_y)
   y3=max_clip_y;

// compute starting address in video memory
dest_addr = dest_buffer+y1*mempitch;

// test if x clipping is needed
if (x1>=min_clip_x && x1<=max_clip_x &&
    x2>=min_clip_x && x2<=max_clip_x &&
    x3>=min_clip_x && x3<=max_clip_x)
    {
    // draw the triangle
    for (temp_y=y1; temp_y<=y3; temp_y++,dest_addr+=mempitch)
        {
        memset((UCHAR *)dest_addr+((xs+FIXP16_ROUND_UP)>>FIXP16_SHIFT),
               color, (((xe-xs+FIXP16_ROUND_UP)>>FIXP16_SHIFT)+1));

        // adjust starting point and ending point
        xs+=dx_left;
        xe+=dx_right;

        } // end for

    } // end if no x clipping needed
else
   {
   // clip x axis with slower version

   // draw the triangle
   for (temp_y=y1; temp_y<=y3; temp_y++,dest_addr+=mempitch)
       {
       // do x clip
       left  = ((xs+FIXP16_ROUND_UP)>>16);
       right = ((xe+FIXP16_ROUND_UP)>>16);

       // adjust starting point and ending point
       xs+=dx_left;
       xe+=dx_right;

       // clip line
       if (left < min_clip_x)
          {
          left = min_clip_x;

          if (right < min_clip_x)
             continue;
          }

       if (right > max_clip_x)
          {
          right = max_clip_x;

          if (left > max_clip_x)
             continue;
          }

       memset((UCHAR  *)dest_addr+(unsigned int)left,
              color,(unsigned int)(right-left+1));

       } // end for

   } // end else x clipping needed

} // end Draw_Top_TriFP

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

void Draw_Bottom_TriFP(int x1,int y1, 
                       int x2,int y2, 
                       int x3,int y3,
                       int color,
                       UCHAR *dest_buffer, int mempitch)
{

// this function draws a triangle that has a flat bottom using fixed point math

int dx_right,    // the dx/dy ratio of the right edge of line
    dx_left,     // the dx/dy ratio of the left edge of line
    xs,xe,       // the starting and ending points of the edges
    height;      // the height of the triangle

int temp_x,        // used during sorting as temps
    temp_y,
    right,         // used by clipping
    left;

UCHAR  *dest_addr;

if (y1==y2 || y1==y3)
	return;

// test order of x1 and x2
if (x3 < x2)
   {
   temp_x = x2;
   x2     = x3;
   x3     = temp_x;

   } // end if swap

// compute delta's
height = y3-y1;

dx_left  = ((x2-x1)<<FIXP16_SHIFT)/height;
dx_right = ((x3-x1)<<FIXP16_SHIFT)/height;

// set starting points
xs = (x1<<FIXP16_SHIFT);
xe = (x1<<FIXP16_SHIFT); 

// perform y clipping
if (y1<min_clip_y)
   {
   // compute new xs and ys
   xs = xs+dx_left*(-y1+min_clip_y);
   xe = xe+dx_right*(-y1+min_clip_y);

   // reset y1
   y1=min_clip_y;

   } // end if top is off screen

if (y3>max_clip_y)
   y3=max_clip_y;

// compute starting address in video memory
dest_addr = dest_buffer+y1*mempitch;

// test if x clipping is needed
if (x1>=min_clip_x && x1<=max_clip_x &&
    x2>=min_clip_x && x2<=max_clip_x &&
    x3>=min_clip_x && x3<=max_clip_x)
    {
    // draw the triangle
    for (temp_y=y1; temp_y<=y3; temp_y++,dest_addr+=mempitch)
        {
        memset((UCHAR *)dest_addr+((xs+FIXP16_ROUND_UP)>>FIXP16_SHIFT),
                color, (((xe-xs+FIXP16_ROUND_UP)>>FIXP16_SHIFT)+1));

        // adjust starting point and ending point
        xs+=dx_left;
        xe+=dx_right;

        } // end for

    } // end if no x clipping needed
else
   {
   // clip x axis with slower version

   // draw the triangle
   for (temp_y=y1; temp_y<=y3; temp_y++,dest_addr+=mempitch)
       {
       // do x clip
       left  = ((xs+FIXP16_ROUND_UP)>>FIXP16_SHIFT);
       right = ((xe+FIXP16_ROUND_UP)>>FIXP16_SHIFT);

       // adjust starting point and ending point
       xs+=dx_left;
       xe+=dx_right;

       // clip line
       if (left < min_clip_x)
          {
          left = min_clip_x;

          if (right < min_clip_x)
             continue;
          }

       if (right > max_clip_x)
          {
          right = max_clip_x;

          if (left > max_clip_x)
             continue;
          }

       memset((UCHAR *)dest_addr+left,
              color, (right-left+1));

       } // end for

   } // end else x clipping needed

} // end Draw_Bottom_TriFP

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

void Draw_Top_Tri(int x1,int y1, 
                  int x2,int y2, 
                  int x3,int y3,
                  int color, 
                  UCHAR *dest_buffer, int mempitch)
{
// this function draws a triangle that has a flat top

float dx_right,    // the dx/dy ratio of the right edge of line
      dx_left,     // the dx/dy ratio of the left edge of line
      xs,xe,       // the starting and ending points of the edges
      height;      // the height of the triangle

int temp_x,        // used during sorting as temps
    temp_y,
    right,         // used by clipping
    left;

// destination address of next scanline
UCHAR  *dest_addr = NULL;

// test order of x1 and x2
if (x2 < x1)
   {
   temp_x = x2;
   x2     = x1;
   x1     = temp_x;
   } // end if swap

// compute delta's
height = y3-y1;

dx_left  = (x3-x1)/height;
dx_right = (x3-x2)/height;

// set starting points
xs = (float)x1;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩精品专区| 国产精品久久久久毛片软件| 中国色在线观看另类| 日韩一区二区三区视频| 777午夜精品免费视频| 欧美二区在线观看| 3d成人h动漫网站入口| 欧美日韩不卡在线| 宅男在线国产精品| 精品少妇一区二区三区日产乱码 | 最新国产精品久久精品| 1区2区3区欧美| 亚洲黄色性网站| 亚洲高清视频的网址| 三级一区在线视频先锋| 奇米综合一区二区三区精品视频| 丝袜美腿成人在线| 精品无人区卡一卡二卡三乱码免费卡 | 精品国产一区二区三区不卡| 精品国产一二三| 欧美国产综合一区二区| 亚洲人成电影网站色mp4| 一区二区三区精密机械公司| 亚洲高清不卡在线观看| 免费成人美女在线观看| 国产一区在线观看麻豆| 成人自拍视频在线观看| 91蜜桃免费观看视频| 精品视频在线免费| 欧美sm美女调教| 中文字幕欧美激情一区| 一区二区成人在线| 欧美熟乱第一页| 日韩视频永久免费| 国产香蕉久久精品综合网| 亚洲视频免费在线| 日韩中文字幕不卡| 成人午夜在线视频| 欧美日韩在线精品一区二区三区激情 | 国产一区亚洲一区| 97国产一区二区| 777色狠狠一区二区三区| 国产性色一区二区| 亚洲福利视频一区二区| 国产精品一区2区| 欧洲精品一区二区| 久久伊99综合婷婷久久伊| 亚洲视频网在线直播| 麻豆精品久久精品色综合| 成人va在线观看| 5月丁香婷婷综合| 一区精品在线播放| 麻豆久久久久久久| 色噜噜夜夜夜综合网| 日韩欧美一区中文| 亚洲色图.com| 国产在线一区二区综合免费视频| 91毛片在线观看| 2021久久国产精品不只是精品| 亚洲激情校园春色| 国产精品亚洲一区二区三区妖精 | 欧美精品一区二| 亚洲一区在线播放| 国产成人精品一区二区三区四区 | 国产91综合一区在线观看| 欧美日韩在线精品一区二区三区激情| 国产亚洲人成网站| 日本在线不卡一区| 91美女福利视频| 国产农村妇女精品| 日本麻豆一区二区三区视频| 91在线porny国产在线看| 精品久久久三级丝袜| 五月激情综合婷婷| 色婷婷亚洲婷婷| 中文字幕av一区二区三区高| 男女激情视频一区| 欧美性猛片xxxx免费看久爱| 国产精品水嫩水嫩| 国产一区二区三区香蕉| 欧美日本韩国一区| 一区二区三区不卡在线观看| 99re热这里只有精品免费视频 | 久久黄色级2电影| 欧美日韩精品电影| 亚洲理论在线观看| 99re6这里只有精品视频在线观看 99re8在线精品视频免费播放 | 不卡av免费在线观看| 国产亚洲综合av| 精油按摩中文字幕久久| 91精品免费观看| 午夜精品国产更新| 精品视频资源站| 亚洲成人免费在线观看| 91精品福利在线| 一区二区三区在线视频观看58 | 欧美日韩国产综合一区二区三区 | 美国欧美日韩国产在线播放| 欧美四级电影在线观看| 亚洲欧美色一区| 91视频免费观看| 国产精品不卡一区| 99久久伊人久久99| 国产精品久久毛片av大全日韩| 成人免费电影视频| 国产精品入口麻豆原神| 丁香婷婷综合网| 国产精品萝li| 色噜噜狠狠色综合欧洲selulu| 亚洲欧美偷拍另类a∨色屁股| 色综合激情五月| 亚洲成人精品一区| 欧美军同video69gay| 日韩va欧美va亚洲va久久| 宅男在线国产精品| 美国毛片一区二区三区| 久久午夜色播影院免费高清 | 欧美成人精品高清在线播放| 麻豆91小视频| 久久精品视频网| 成人ar影院免费观看视频| 亚洲女人的天堂| 欧美日韩黄色影视| 九九**精品视频免费播放| 国产欧美日韩在线看| 91亚洲精品久久久蜜桃| 亚洲激情自拍偷拍| 欧美一区二区成人6969| 国产一区在线视频| 日韩理论片网站| 在线不卡欧美精品一区二区三区| 美洲天堂一区二卡三卡四卡视频| 久久久国产精品午夜一区ai换脸| 成人免费看黄yyy456| 亚洲一区二区三区在线播放| 日韩一区二区中文字幕| 国产999精品久久| 一区二区三区在线播| 欧美一级黄色片| 成人免费高清视频| 午夜久久电影网| 国产午夜精品久久久久久免费视 | 欧美无人高清视频在线观看| 蜜桃视频一区二区| 国产精品美女久久久久aⅴ| 在线精品视频小说1| 蜜臀av一区二区在线免费观看| 国产嫩草影院久久久久| 欧美日本视频在线| 国产福利精品一区二区| 亚洲成人综合在线| 亚洲国产精品黑人久久久| 欧美日韩国产系列| 国产精品综合久久| 亚洲大型综合色站| 中文字幕成人网| 日韩一卡二卡三卡国产欧美| 91一区一区三区| 国产伦精一区二区三区| 亚洲午夜电影网| 国产色产综合色产在线视频| 欧美亚洲另类激情小说| 国产精品123区| 免费视频最近日韩| 亚洲精品成人天堂一二三| 久久综合久久鬼色| 欧美福利一区二区| 97精品国产露脸对白| 久久超碰97中文字幕| 亚洲福利视频导航| 亚洲欧洲无码一区二区三区| 欧美成人一区二区| 91福利在线导航| 成年人网站91| 国产一区二区0| 蜜桃一区二区三区在线| 亚洲国产精品自拍| 日韩伦理电影网| 中文字幕av资源一区| 精品国内片67194| 欧美一级二级在线观看| 欧美日韩一区在线| 91视视频在线直接观看在线看网页在线看| 国产一区二三区好的| 蜜臀av性久久久久av蜜臀妖精| 亚洲伊人色欲综合网| 亚洲天堂2016| 国产精品久久久久婷婷| 国产日韩欧美高清| 26uuu色噜噜精品一区| 日韩欧美精品三级| 91精品国产欧美日韩| 欧美专区日韩专区| av资源网一区| 成人精品电影在线观看| 成人在线综合网站| 成人丝袜视频网| 国产91在线观看| 国产成人精品免费网站| 国产精品1区2区|