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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cacti.cpp

?? 一本關于OPenGL的很好的電子書
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/****************************************************************************
 cacti.cpp
 
 This demo program demonstrates the use of billboarding by drawing cacti
 on a desert landscape.
  
 Author   :   Dave Astle
 Date     :   4/3/2001

 Written for OpenGL Game Programming
*****************************************************************************/


/********************************* Includes *********************************/
#define WIN32_LEAN_AND_MEAN   // get rid of Windows things we don't need

#include <windows.h>          // included in all Windows apps
#include <winuser.h>          // Windows constants
#include <gl/gl.h>            // OpenGL include
#include <gl/glu.h>           // OpenGL utilty library
#include "vectorlib.h"
#include "bitmap.h"


#define WND_CLASS_NAME  "OpenGL Window Class"


/*************************** Constants and Macros ***************************/
const int   SCREEN_WIDTH    = 800;
const int   SCREEN_HEIGHT   = 600;
const int   SCREEN_BPP      = 32;
const bool  USE_FULLSCREEN  = false; 
const char  *APP_TITLE       = "Billboarding Demo";

#define MAP_X       32        // size of map along x-axis
#define MAP_Z       32        // size of map along z-axis
#define MAP_SCALE   25.0f     // the scale of the terrain map

#define PI          3.14159
#define NUM_CACTI   40

#define KEY_DOWN(vk_code)  ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code)    ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

#define RAND_COORD(x)   ((float)rand()/RAND_MAX * (x))

typedef void (APIENTRY * PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
typedef void (APIENTRY * PFNGLUNLOCKARRAYSEXTPROC) (void);


/********************************* Globals **********************************/
HDC       g_hdc;                  // device context
HGLRC     g_hrc;                  // rendering context
BOOL      g_isFullscreen = TRUE;  // toggles fullscreen and windowed display
BOOL      g_isActive = TRUE;      // false if window is minimized
HWND      g_hwnd = NULL;          // main window handle
HINSTANCE g_hInstance;            // application instance

GLuint    g_sand;     // sand texture
GLuint    g_cactus;   // cactus texture

GLboolean g_keys[256];

// terrain data
float   g_terrain[MAP_X * MAP_Z][3];         // heightfield terrain data (0-255); 256x256
GLuint  g_indexArray[MAP_X * MAP_Z * 2];    // vertex array
float   g_colorArray[MAP_X * MAP_Z][3];     // color array
float   g_texcoordArray[MAP_X * MAP_Z][2];  // tex coord array

// compiled array extensions
PFNGLLOCKARRAYSEXTPROC    glLockArraysEXT = 0;
PFNGLUNLOCKARRAYSEXTPROC  glUnlockArraysEXT = 0;


/******************************** Prototypes ********************************/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

BOOL    SetupWindow(const char *title, int width, int height, int bits, bool isFullscreen);
BOOL    KillWindow();

GLvoid  ResizeScene(GLsizei width, GLsizei height);
BOOL    InitializeScene();
void    InitializeTerrain();
BOOL    DisplayScene();
BOOL    Cleanup();

void    DrawCacti();
void    DrawSand();
void    LoadTexture(char *filename, GLuint &texture);
float   GetHeight(float x, float z);


/*****************************************************************************
 WinMain()

 Windows entry point
*****************************************************************************/
int WINAPI WinMain(HINSTANCE g_hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
  MSG   msg;       // message
  BOOL  isDone;    // flag indicatingen the app is done

  // if the window is set up correctly, we can proceed with the message loop
  if (SetupWindow(APP_TITLE, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, USE_FULLSCREEN))
    isDone = FALSE;
  // otherwise, we need to never enter the loop and proceed to exit
  else
    isDone = TRUE;

  // main message loop
  while (!isDone)
  {
    if(PeekMessage(&msg, g_hwnd, NULL, NULL, PM_REMOVE))
    {
      if (msg.message == WM_QUIT)   // do we receive a WM_QUIT message?
      {
        isDone = TRUE;              // if so, time to quit the application
      }
      else
      {
        TranslateMessage(&msg);     // translate and dispatch to event queue
        DispatchMessage(&msg);
      }
    }

    // don't update the scene if the app is minimized
    if (g_isActive)
    {
      // update the scene every time through the loop
      DisplayScene();
      // switch the front and back buffers to display the updated scene
      SwapBuffers(g_hdc);
    }
  }

  Cleanup();
  KillWindow();

  return msg.wParam;
} // end WinMain()


/*****************************************************************************
 WndProc()

 Windows message handler
*****************************************************************************/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch(message)
  {
  case WM_ACTIVATE:  // watch for the window being minimized and restored
    {
      if (!HIWORD(wParam))
      {
        // program was restored or maximized
        g_isActive = TRUE;
      }
      else
      {
        // program was minimized
        g_isActive=FALSE;
      }

      return 0;
    }

  case WM_SYSCOMMAND:  // look for screensavers and powersave mode
    {
      switch (wParam)
      {
      case SC_SCREENSAVE:     // screensaver trying to start
      case SC_MONITORPOWER:   // monitor going to powersave mode
        // returning 0 prevents either from happening
        return 0;
      default:
        break;
      }
    } break;

  case WM_CLOSE:    // window is being closed
    {
      // send WM_QUIT to message queue
      PostQuitMessage(0);

      return 0;
    }

  case WM_SIZE:
    {
      // update perspective with new width and height
      ResizeScene(LOWORD(lParam), HIWORD(lParam));
      return 0;
    }

  case WM_KEYDOWN:
    {
      switch (toupper(wParam))
      {
      case VK_ESCAPE:
        {
          // send WM_QUIT to message queue
          PostQuitMessage(0);
          return 0;
        }
      default:
        {
          g_keys[wParam] = GL_TRUE;
          return 0;
        }
      };
    }

  case WM_KEYUP:
    {
      g_keys[wParam] = GL_FALSE;
      return 0;
    }

  default:
    break;
  }

  return (DefWindowProc(hwnd, message, wParam, lParam));
} // end WndProc()


/*****************************************************************************
 SetupWindow()

 Create the window and everything else we need, including the device and
 rendering context. If a fullscreen window has been requested but can't be
 created, the user will be prompted to attempt windowed mode. Finally,
 InitializeScene is called for application-specific setup.

 Returns TRUE if everything goes well, or FALSE if an unrecoverable error
 occurs. Note that if this is called twice within a program, KillWindow needs
 to be called before subsequent calls to SetupWindow.
*****************************************************************************/
BOOL SetupWindow(const char *title, int width, int height, int bits, bool isFullscreen)
{
  // set the global flag
  g_isFullscreen = isFullscreen;

  // get our instance handle
  g_hInstance = GetModuleHandle(NULL);

  WNDCLASSEX  wc;    // window class

  // fill out the window class structure
  wc.cbSize         = sizeof(WNDCLASSEX);
  wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc.lpfnWndProc    = WndProc;
  wc.cbClsExtra     = 0;
  wc.cbWndExtra     = 0;
  wc.hInstance      = g_hInstance;
  wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);  // default icon
  wc.hIconSm        = LoadIcon(NULL, IDI_WINLOGO);      // windows logo small icon
  wc.hCursor        = LoadCursor(NULL, IDC_ARROW);      // default arrow
  wc.hbrBackground  = NULL;     // no background needed
  wc.lpszMenuName   = NULL;     // no menu
  wc.lpszClassName  = WND_CLASS_NAME;
  
  // register the windows class
  if (!RegisterClassEx(&wc))
  {
    MessageBox(NULL,"Unable to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION);

    // exit and return FALSE
    return FALSE;       
  }

  // if we're in fullscreen mode, set the display up for it
  if (g_isFullscreen)
  {
    // set up the device mode structure
    DEVMODE screenSettings;
    memset(&screenSettings,0,sizeof(screenSettings));

    screenSettings.dmSize       = sizeof(screenSettings);
    screenSettings.dmPelsWidth  = width;    // screen width
    screenSettings.dmPelsHeight = height;   // screen height
    screenSettings.dmBitsPerPel = bits;     // bits per pixel
    screenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    // attempt to switch to the resolution and bit depth we've selected
    if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    {
      // if we can't get fullscreen, let them choose to quit or try windowed mode
      if (MessageBox(NULL, "Cannot run in the fullscreen mode at the selected resolution\n"
                           "on your video card. Try windowed mode instead?",
                           "OpenGL Game Programming",
                           MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
      {
        g_isFullscreen = FALSE;
      }
      else
      {
        return FALSE;
      }
    }
  }

  DWORD dwExStyle;
  DWORD dwStyle;

  // set the window style appropriately, depending on whether we're in fullscreen mode
  if (g_isFullscreen)
  {
    dwExStyle = WS_EX_APPWINDOW;
    dwStyle = WS_POPUP;           // simple window with no borders or title bar
    ShowCursor(FALSE);            // hide the cursor for now
  }
  else
  {
    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    dwStyle = WS_OVERLAPPEDWINDOW;
  }

  // set up the window we're rendering to so that the top left corner is at (0,0)
  // and the bottom right corner is (height,width)
  RECT  windowRect;
  windowRect.left = 0;
  windowRect.right = (LONG) width;
  windowRect.top = 0;
  windowRect.bottom = (LONG) height;

  // change the size of the rect to account for borders, etc. set by the style
  AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);

  // class registered, so now create our window
  g_hwnd = CreateWindowEx(dwExStyle,          // extended style
                          WND_CLASS_NAME,     // class name
                          title,              // app name
                          dwStyle |           // window style
                          WS_CLIPCHILDREN |   // required for
                          WS_CLIPSIBLINGS,    // using OpenGL
                          0, 0,               // x,y coordinate
                          windowRect.right - windowRect.left, // width
                          windowRect.bottom - windowRect.top, // height
                          NULL,               // handle to parent
                          NULL,               // handle to menu
                          g_hInstance,        // application instance
                          NULL);              // no extra params

  // see if our window handle is valid
  if (!g_hwnd)
  {
    MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // get a device context
  if (!(g_hdc = GetDC(g_hwnd)))
  {
    MessageBox(NULL,"Unable to create device context", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // set the pixel format we want
  PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),  // size of structure
    1,                              // default version
    PFD_DRAW_TO_WINDOW |            // window drawing support
    PFD_SUPPORT_OPENGL |            // OpenGL support
    PFD_DOUBLEBUFFER,               // double buffering support
    PFD_TYPE_RGBA,                  // RGBA color mode
    bits,                           // 32 bit color mode
    0, 0, 0, 0, 0, 0,               // ignore color bits, non-palettized mode
    0,                              // no alpha buffer
    0,                              // ignore shift bit
    0,                              // no accumulation buffer
    0, 0, 0, 0,                     // ignore accumulation bits
    16,                             // 16 bit z-buffer size
    0,                              // no stencil buffer
    0,                              // no auxiliary buffer
    PFD_MAIN_PLANE,                 // main drawing plane
    0,                              // reserved
    0, 0, 0 };                      // layer masks ignored
      
  GLuint  pixelFormat;

  // choose best matching pixel format
  if (!(pixelFormat = ChoosePixelFormat(g_hdc, &pfd)))
  {
    MessageBox(NULL, "Can't find an appropriate pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // set pixel format to device context
  if(!SetPixelFormat(g_hdc, pixelFormat,&pfd))
  {
    MessageBox(NULL, "Unable to set pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // create the OpenGL rendering context
  if (!(g_hrc = wglCreateContext(g_hdc)))
  {
    MessageBox(NULL, "Unable to create OpenGL rendering context", "Error",MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // now make the rendering context the active one
  if(!wglMakeCurrent(g_hdc, g_hrc))
  {
    MessageBox(NULL,"Unable to activate OpenGL rendering context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  // show the window in the forground, and set the keyboard focus to it
  ShowWindow(g_hwnd, SW_SHOW);
  SetForegroundWindow(g_hwnd);
  SetFocus(g_hwnd);

  // set up the perspective for the current screen size
  ResizeScene(width, height);

  // do one-time initialization
  if (!InitializeScene())
  {
    MessageBox(NULL, "Initialization failed", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;
  }

  return TRUE;
} // end SetupWindow()


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人午夜在线播放| 日韩美女视频一区| 黄色资源网久久资源365| 欧美精品123区| 久久精品国产精品亚洲综合| 精品久久一区二区| 国产福利一区二区三区视频| 国产午夜三级一区二区三| 成人一区二区三区在线观看| 亚洲欧美日韩国产一区二区三区 | 国产精品一二三四五| 国产精品三级视频| 在线观看日产精品| 不卡电影免费在线播放一区| 一区二区三区日韩欧美| 91精品国产入口在线| 国产专区欧美精品| 亚洲精品网站在线观看| 91精品国产91久久综合桃花| 国产自产高清不卡| 亚洲精品日产精品乱码不卡| 欧美久久一区二区| 国产精品夜夜嗨| 亚洲成人综合视频| 欧美极品少妇xxxxⅹ高跟鞋| 欧洲精品中文字幕| 国产最新精品免费| 一区二区三区欧美日| 精品三级在线看| 91成人国产精品| 国产精品一区二区黑丝| 亚洲最新视频在线观看| 国产亚洲人成网站| 欧美日韩成人激情| 国产成人一级电影| 日韩电影在线看| 亚洲欧洲国产专区| 精品久久久久久最新网址| 色噜噜狠狠色综合中国| 国产精品原创巨作av| 亚洲国产精品久久久久婷婷884| 久久精品视频一区二区三区| 欧美视频一区在线| 99精品一区二区| 国产精品一区在线| 免费看黄色91| 午夜精品久久久久久久久久| 中文字幕在线观看一区二区| 精品国免费一区二区三区| 欧美三级电影网| 91亚洲精品乱码久久久久久蜜桃| 麻豆专区一区二区三区四区五区| 一区二区在线观看不卡| 欧美国产日本韩| 久久久美女艺术照精彩视频福利播放| 欧美日韩亚洲高清一区二区| 99天天综合性| 高清日韩电视剧大全免费| 激情欧美一区二区| 青青草原综合久久大伊人精品 | k8久久久一区二区三区 | 中文在线资源观看网站视频免费不卡| 91精品欧美久久久久久动漫 | 欧美高清激情brazzers| 91小视频在线观看| 不卡的电影网站| 成人综合激情网| 成人午夜伦理影院| 国产成人精品影视| 国产精品99久久久久久宅男| 极品美女销魂一区二区三区免费| 三级不卡在线观看| 日本三级亚洲精品| 久久成人免费电影| 国内精品第一页| 国产一区二区成人久久免费影院| 国产米奇在线777精品观看| 韩国成人精品a∨在线观看| 精品一区二区三区av| 国产一区免费电影| 成人h动漫精品一区二区| 成人午夜激情影院| 97精品久久久午夜一区二区三区| 91麻豆精品秘密| 欧美在线一区二区三区| 欧美人xxxx| 精品国产乱码久久| 国产精品私人影院| 一区二区三区日本| 欧美aaaaa成人免费观看视频| 激情久久五月天| av激情成人网| 欧美日本一区二区三区四区| 91精品免费观看| 欧美精品一区二| 欧美高清在线精品一区| 国产精品另类一区| 亚洲国产综合在线| 久久国产精品免费| 波多野结衣中文字幕一区二区三区 | 中文一区二区完整视频在线观看| 国产精品素人视频| 午夜激情一区二区| 国产精品中文字幕日韩精品| 99riav一区二区三区| 欧美另类高清zo欧美| 久久美女高清视频| 亚洲精品国产精华液| 日本美女一区二区| av成人动漫在线观看| 欧美裸体一区二区三区| 国产婷婷色一区二区三区在线| 一区二区三区四区在线免费观看| 日本aⅴ免费视频一区二区三区| 国产东北露脸精品视频| 欧美日韩国产区一| 国产三级精品三级| 色欧美乱欧美15图片| 欧美哺乳videos| 亚洲精品videosex极品| 国产自产视频一区二区三区| 在线欧美日韩精品| 日本一区二区免费在线| 日韩国产精品91| 91同城在线观看| 精品国产伦一区二区三区观看方式| 亚洲色图视频网| 精品一区二区免费在线观看| 欧美三级资源在线| 中文字幕一区av| 国产精品影视网| 欧美一区二区大片| 亚洲黄色av一区| 99久久久国产精品| 国产亚洲欧洲一区高清在线观看| 天天做天天摸天天爽国产一区 | 日本一不卡视频| 色综合久久中文字幕| 国产欧美日韩视频在线观看| 日韩影院在线观看| 欧美综合久久久| 亚洲欧美激情一区二区| 成人福利在线看| 欧美国产一区二区| 国产一区在线看| 久久综合色婷婷| 老司机精品视频在线| 欧美精品国产精品| 亚洲成人精品在线观看| 色吧成人激情小说| 亚洲欧美综合另类在线卡通| 国产成人午夜高潮毛片| 亚洲精品一区二区三区99| 日韩av中文字幕一区二区三区| 欧美午夜影院一区| 亚洲一区二区偷拍精品| 欧美制服丝袜第一页| 亚洲男人天堂一区| 国产成人精品免费视频网站| 久久亚洲一区二区三区四区| 韩国女主播成人在线| 精品国产一区久久| 国产乱淫av一区二区三区| 2017欧美狠狠色| 国产.欧美.日韩| 成人欧美一区二区三区视频网页 | 色综合色综合色综合色综合色综合| 日本一区二区电影| av一区二区三区| 亚洲伊人色欲综合网| 一本色道**综合亚洲精品蜜桃冫| 国产精品毛片大码女人| 99国产精品久久久| 亚洲国产三级在线| 日韩一区二区影院| 激情欧美一区二区三区在线观看| 26uuu国产电影一区二区| 国产一本一道久久香蕉| 国产精品视频在线看| 色猫猫国产区一区二在线视频| 亚洲午夜激情av| 欧美精品国产精品| 秋霞电影一区二区| 国产日产欧产精品推荐色| 91在线免费视频观看| 亚洲成人综合在线| 久久亚洲一级片| 色综合久久久久综合| 石原莉奈一区二区三区在线观看| 欧美成人一区二区三区片免费| 国产麻豆成人精品| 亚洲美女免费在线| 欧美日本在线一区| 国产成人免费视| 首页国产欧美久久| 亚洲国产岛国毛片在线| 欧美日韩亚洲国产综合| 国产一区二区免费在线| 亚洲欧美电影一区二区| 日韩欧美精品在线视频|