⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 简单的消防演示 简单的消防演示
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
Name: Fire Demo
Author: M. Shieh
Version: 1.1
Notes: Written and compiled on Dev-C++ 4.9.8.7b
Special thanks to: >Dustin Davis @ www.programmers-unlimited.com
                   >Jeff Molofe (NeHe) @ nehe.gamedev.net
                   >www.gametutorials.com
                   >The people @ www.gamedev.net
*/

/*==============================================================================
Header Files and Global Defines
==============================================================================*/
#include "resource.h"       //Header File for Resource IDs and Headers

/*==============================================================================
Global Variables
==============================================================================*/
//~~~~~The Window's Variables
    const char *WinClass_name="Fire Demo";
    HDC	hDC=NULL;
    HGLRC hRC=NULL;
    HWND hwnd=NULL;
    HMENU hMenu=NULL;
    HINSTANCE hInstance;
    float g_FrameInterval = 0.0f;

//~~~~~Control Variables
	bool done=FALSE;
    bool active=TRUE;
    struct option
    {
        unsigned int particle_count;
        int particle_speed;
        int top_x;
        int top_y;
        int bottom_x;
        int bottom_y;
        int fade;
        int point;
        int red;
        int green;
        int blue;
    } options;

//~~~~~Computer Speed Compensation::nehe.gamedev.net/
    struct
    {
       __int64 frequency;
       float resolution;
       unsigned long mm_timer_start;
       unsigned long mm_timer_elapsed;
       bool performance_timer;
       __int64 performance_timer_start;
       __int64 performance_timer_elapsed;
    } timer;
    float speed_mod=0.0;
    
/*==============================================================================
FUNCTION PROTOTYPES
==============================================================================*/
//=====Resize Scene Based on Window Dimesions
void ReSizeGLScene(GLsizei width, GLsizei height);

//=====Timer Functions for Computer Speed Compensation
//Timer Inilization
void TimerInit();
//Timer Retriever
float TimerGetTime();

//=====Other Functions
//Framerate Calculation
void CalculateFrameRate();

//=====Dialog Callbacks
//Options
bool CALLBACK Options_Dialog(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);

//=====External Functions
//Load Bitmaps
extern bool LoadBMP();
//Particle Generator Inilization
extern bool xia_IniFire(int quantity, float size, float speed_edit);
//Particle Generator De-inilization
extern void xia_CleanFire();
//Scene Drawing
extern int DrawScene();

/*==============================================================================
OPENGL INITIALIZATION
==============================================================================*/
int InitGL()
{
    if(!LoadBMP())
    {
        return FALSE;
    }
	srand(time(NULL));
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
    glEnable(GL_BLEND);
//Set up options variables
    options.particle_count=300;
    options.particle_speed=10;
    options.top_x=-6;
    options.top_y=20;
    options.bottom_x=4;
    options.bottom_y=-13;
    options.fade=80;
    options.point=10;
    options.red=100;
    options.green=20;
    options.blue=0;
//Initialize Fire Particle Generator
	xia_IniFire(options.particle_count, .005, 1);
    gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -150.0, 0.0, 1.0, 0.0);
    return TRUE;
}

/*==============================================================================
WINDOW CALLBACK
==============================================================================*/
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_ACTIVATE:
		{
			if (!HIWORD(wParam))
			{
				active=TRUE;
			}
			else
			{
				active=FALSE;
			}
			return 0;
		}
		case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			     case IDM_OPTIONS:
			     {
			   		 CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OPTIONS), hwnd,(DLGPROC)Options_Dialog);
			     }
			     break;
			     case IDM_ABOUT:
			     {
                     MessageBox(hwnd, "Programmed by: M. Shieh\nVersion: 1.1", "Simple Fire Demo", MB_OK);
			     }
			     break;
			     case IDM_EXIT:
			     {
					 PostQuitMessage(0);
					 return 0;
			     }
            }
        }
        break;
		case WM_SYSCOMMAND:
		{
			switch (wParam)
			{
				case SC_SCREENSAVE:
				case SC_MONITORPOWER:
				return 0;
			}
			break;
		}
		case WM_SIZE:
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
			return 0;
		}
		case WM_DESTROY:
		case WM_CLOSE:
		{
			PostQuitMessage(0);
			return 0;
		}
	}
	return DefWindowProc(hwnd,msg,wParam,lParam);
}

/*==============================================================================
OPTIONS CALLBACK
==============================================================================*/
bool CALLBACK Options_Dialog(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
    switch(message)
	{
		case WM_INITDIALOG:
		{
	    //Assign Values to edit Controls
	        SetDlgItemInt(hwnd, IDC_OPTIONS_COUNT, options.particle_count, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_SPEED, options.particle_speed, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_TOPX, options.top_x, TRUE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_TOPY, options.top_y, TRUE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_BOTTOMX, options.bottom_x, TRUE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_BOTTOMY, options.bottom_y, TRUE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_FADE, options.fade, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_POINT, options.point, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_RED, options.red, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_GREEN, options.green, FALSE);
	        SetDlgItemInt(hwnd, IDC_OPTIONS_BLUE, options.blue, FALSE);
        //Set Character Limit for Edit Boxes
            SendDlgItemMessage(hwnd, IDC_OPTIONS_COUNT, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_SPEED, EM_LIMITTEXT, 3, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_TOPX, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_TOPY, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_BOTTOMX, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_BOTTOMY, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_FADE, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_POINT, EM_LIMITTEXT, 5, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_RED, EM_LIMITTEXT, 3, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_GREEN, EM_LIMITTEXT, 3, 0);
            SendDlgItemMessage(hwnd, IDC_OPTIONS_BLUE, EM_LIMITTEXT, 3, 0);
		}
		return TRUE;
		case WM_COMMAND:
		{
			switch(LOWORD(wparam))
            {
               case IDC_OPTIONS_OK:
               {
               //Obtain contents of the edit boxes
                   options.particle_count=GetDlgItemInt(hwnd, IDC_OPTIONS_COUNT, NULL, FALSE);
                   options.particle_speed=GetDlgItemInt(hwnd, IDC_OPTIONS_SPEED, NULL, FALSE);
                   options.top_x=GetDlgItemInt(hwnd, IDC_OPTIONS_TOPX, NULL, TRUE);
                   options.top_y=GetDlgItemInt(hwnd, IDC_OPTIONS_TOPY, NULL, TRUE);
                   options.bottom_x=GetDlgItemInt(hwnd, IDC_OPTIONS_BOTTOMX, NULL, TRUE);
                   options.bottom_y=GetDlgItemInt(hwnd, IDC_OPTIONS_BOTTOMY, NULL, TRUE);
                   options.fade=GetDlgItemInt(hwnd, IDC_OPTIONS_FADE, NULL, FALSE);
                   options.point=GetDlgItemInt(hwnd, IDC_OPTIONS_POINT, NULL, FALSE);
                   options.red=GetDlgItemInt(hwnd, IDC_OPTIONS_RED, NULL, FALSE);
                   options.green=GetDlgItemInt(hwnd, IDC_OPTIONS_GREEN, NULL, FALSE);
                   options.blue=GetDlgItemInt(hwnd, IDC_OPTIONS_BLUE, NULL, FALSE);
               //Clean memory allocation and allocate memory again
                   xia_CleanFire();
                   xia_IniFire(options.particle_count, .005, 1);
               //End the dialog box
                   EndDialog(hwnd,0);
               }
               break;
               case IDC_OPTIONS_CANCEL:
               {
                   EndDialog(hwnd,0);
               }
               break;
            }
		}
		break;
	}
	return FALSE;
}

/*==============================================================================
FUNCTION DEFINITIONS
==============================================================================*/
//Resize Scene Based on Window Dimesions::nehe.gamedev.net/
void ReSizeGLScene(GLsizei width, GLsizei height)
{
	if (height == 0)
	{
		height=1;
	}
	glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -