XLT.cpp
资源名称:XLT.rar [点击查看]
上传用户:yunyi28
上传日期:2021-04-25
资源大小:6978k
文件大小:10k
源码类别:
分形几何
开发平台:
Visual C++
- // XLT.cpp : 定义应用程序的入口点。
- //
- #pragma once
- #include <windows.h> // Header File For Windows
- #include <stdio.h> // Header file for standard input output (IE, "FILE") (NEW)
- #include <stdlib.h>
- #include "XLT.h"
- #include "opengl.h"
- #include "Script.h"
- #define MAX_LOADSTRING 100
- // 全局变量:
- //HINSTANCE hInst; // 当前实例
- //TCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
- //TCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名
- HDC hDC=NULL;
- HWND hWnd=NULL;
- //HGLRC hRC=NULL;
- //HWND hWnd=NULL;
- opengl *m_opengl;
- bool pause=true;
- void GameLoop();
- void Init();
- void NewWindow(HWND hWnd);
- int Width=800;
- int Height=600;
- int bits=16;
- // 此代码模块中包含的函数的前向声明:
- /*
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- */
- LRESULT CALLBACK MsgProc(HWND, UINT, WPARAM, LPARAM);
- void NewWindow(HWND hWnd)
- {
- bool b_fullscreen=true;
- DWORD dwExStyle;
- DWORD dwStyle;
- RECT windowRect;
- int nX=0,nY=0;
- dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
- dwStyle=WS_OVERLAPPEDWINDOW;
- int wid=GetSystemMetrics(SM_CXSCREEN);
- int hei=GetSystemMetrics(SM_CYSCREEN);
- nX=(wid-Width)/2,nY=(hei-Height)/2;
- AdjustWindowRectEx(&windowRect,dwStyle,false,dwExStyle);
- char cc[]="tml";
- WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,cc,NULL};
- RegisterClassEx(&wc);
- HWND hWnd2=CreateWindowEx(NULL,cc,"OpenGL",dwStyle|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,nX,nY,Width,Height,NULL,NULL,NULL,NULL);
- ShowWindow(hWnd2,SW_SHOWDEFAULT);
- // m_opengl->init(hWnd2,Width,Height);
- // m_opengl->ClearUI();
- }
- int WINAPI WinMain(HINSTANCE hInst,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- bool b_fullscreen=true;
- DWORD dwExStyle;
- DWORD dwStyle;
- RECT windowRect;
- int nX=0,nY=0;
- dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
- dwStyle=WS_OVERLAPPEDWINDOW;
- int wid=GetSystemMetrics(SM_CXSCREEN);
- int hei=GetSystemMetrics(SM_CYSCREEN);
- nX=(wid-Width)/2,nY=(hei-Height)/2;
- AdjustWindowRectEx(&windowRect,dwStyle,false,dwExStyle);
- char cc[]="tml";
- WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,cc,NULL};
- RegisterClassEx(&wc);
- hWnd=CreateWindowEx(NULL,cc,"OpenGL",dwStyle|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,nX,nY,Width,Height,NULL,NULL,hInst,NULL);
- ShowWindow(hWnd,SW_SHOWDEFAULT);
- m_opengl->init(hWnd,Width,Height);
- /*bool fullscreen=true;
- DWORD dwExStyle;
- DWORD dwStyle;
- int width=GetSystemMetrics(SM_CXSCREEN);
- int height=GetSystemMetrics(SM_CYSCREEN);
- if (fullscreen) // Attempt Fullscreen Mode?
- {
- DEVMODE dmScreenSettings; // Device Mode
- memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
- dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
- dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
- dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
- dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
- dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
- // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
- if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
- {
- // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
- if (MessageBox(NULL,(LPCWSTR)"The Requested Fullscreen Mode Is Not Supported BynYour Video Card. Use Windowed Mode Instead?",(LPCWSTR)"NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
- {
- fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
- }
- else
- {
- // Pop Up A Message Box Letting User Know The Program Is Closing.
- MessageBox(NULL,(LPCWSTR)"Program Will Now Close.",(LPCWSTR)"ERROR",MB_OK|MB_ICONSTOP);
- return FALSE; // Return FALSE
- }
- }
- }
- if (fullscreen) // Are We Still In Fullscreen Mode?
- {
- dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
- dwStyle=WS_POPUP; // Windows Style
- // ShowCursor(FALSE); // Hide Mouse Pointer
- }
- else
- {
- dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
- dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
- }
- //AdjustWindowRectEx(&windowRect,dwStyle,false,dwExStyle);
- char cc[]="tml";
- WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandle(NULL),NULL,NULL,NULL,NULL,(LPCWSTR)cc,NULL};
- RegisterClassEx(&wc);
- HWND hWnd=CreateWindowEx(NULL,(LPCWSTR)cc,(LPCWSTR)"OpenGL",dwStyle|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,0,0,width,height,NULL,NULL,hInst,NULL);
- ShowWindow(hWnd,SW_SHOWDEFAULT);*/
- UpdateWindow(hWnd);
- Init();
- GameLoop();
- return 0;
- }
- /*int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // TODO: 在此放置代码。
- MSG msg;
- HACCEL hAccelTable;
- // 初始化全局字符串
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_XLT, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // 执行应用程序初始化:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_XLT));
- // 主消息循环:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return (int) msg.wParam;
- }
- */
- //
- // 函数: MyRegisterClass()
- //
- // 目的: 注册窗口类。
- //
- // 注释:
- //
- // 仅当希望
- // 此代码与添加到 Windows 95 中的“RegisterClassEx”
- // 函数之前的 Win32 系统兼容时,才需要此函数及其用法。调用此函数十分重要,
- // 这样应用程序就可以获得关联的
- // “格式正确的”小图标。
- //
- //
- // 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // 目的: 处理主窗口的消息。
- //
- // WM_COMMAND - 处理应用程序菜单
- // WM_PAINT - 绘制主窗口
- // WM_DESTROY - 发送退出消息并返回
- //
- //
- LRESULT CALLBACK MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_CREATE:
- hDC=GetDC(hWnd);
- m_opengl->SetupPixelFormat(hDC);
- return 0;
- case WM_CLOSE:
- m_opengl->CleanUp();
- PostQuitMessage(0);
- return 0;
- case WM_SIZE:
- Height=HIWORD(lParam);
- Width=LOWORD(lParam);
- if(Height==0) Height=1;
- m_opengl->init(hWnd,Width,Height);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_KEYUP:
- switch(wParam)
- {
- case VK_ESCAPE:
- // NewWindow(hWnd);
- m_opengl->CleanUp();
- PostQuitMessage(0);
- return 0;
- case VK_PAUSE:
- pause=!pause;
- }
- default:break;
- }
- return (DefWindowProc(hWnd,message,wParam,lParam));
- }
- /*
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_XLT));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_XLT);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassEx(&wcex);
- }
- */
- //
- // 函数: InitInstance(HINSTANCE, int)
- //
- // 目的: 保存实例句柄并创建主窗口
- //
- // 注释:
- //
- // 在此函数中,我们在全局变量中保存实例句柄并
- // 创建和显示主程序窗口。
- //
- /*
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWnd;
- hInst = hInstance; // 将实例句柄存储在全局变量中
- hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return TRUE;
- }
- */
- //
- // 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // 目的: 处理主窗口的消息。
- //
- // WM_COMMAND - 处理应用程序菜单
- // WM_PAINT - 绘制主窗口
- // WM_DESTROY - 发送退出消息并返回
- //
- //
- /*
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- PAINTSTRUCT ps;
- HDC hdc;
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- // 分析菜单选择:
- switch (wmId)
- {
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- // TODO: 在此添加任意绘图代码...
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // “关于”框的消息处理程序。
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
- */
- void GameLoop()
- {
- MSG msg;
- BOOL fmessage;
- PeekMessage(&msg,NULL,0U,0U,PM_NOREMOVE);
- while(msg.message!=WM_QUIT)
- {
- fmessage=PeekMessage(&msg,NULL,0U,0U,PM_REMOVE);
- if(fmessage)
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- m_opengl->Render();
- }
- }
- void Init()
- {
- InitData();
- LoadTreeTypes("../Script/TreeType.ini");
- LoadTreePos("../Script/M2_TreePos.pos");
- }