CGLApplication.h
资源名称:g.rar [点击查看]
上传用户:laitongbao
上传日期:2021-02-20
资源大小:8176k
文件大小:5k
源码类别:
射击游戏
开发平台:
Visual C++
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- #pragma comment(lib, "dxguid.lib")
- #pragma comment(lib, "winmm.lib")
- //dshow 支持文件
- #pragma comment(lib, "Strmiids.lib")
- #pragma comment(lib, "Quartz.lib")
- //普通支持头文件
- #include <windows.h>
- #include <mmsystem.h>
- #include <stdio.h>
- #include <assert.h>
- #include <tchar.h>
- #include <commctrl.h>
- //D3D支持头文件
- #include<d3d9.h>
- #include<d3dx9.h>
- #ifndef CGLAPPLICATION_H
- #define CGLAPPLICATION_H
- class EventLogger;
- class CGLApplication;
- class Clock;
- class Timer;
- class AnimationController;
- extern IDirect3DDevice9* g_pDevice;//全局设备对象(任何地方可用)
- extern D3DPRESENT_PARAMETERS g_d3dpp;
- extern CGLApplication* g_pApp;
- extern AnimationController* g_pAc;
- extern ID3DXMatrixStack* g_pStack;
- extern Clock* g_pClock;
- class View;
- class Surface;
- class SceneTree;
- class Camera;
- class UIController;
- class ShaderController;
- class GraphicController;
- class CGLApplication{
- public:
- virtual ~CGLApplication();
- HRESULT Create(HINSTANCE hInstance,TCHAR *title=TEXT("Window mode"),TCHAR *icon=NULL,bool windowed=true,int width=640,int height=480);
- void Run();
- HRESULT Restore();
- void CleanUp();
- void Show();
- void Hide();
- void SetWindowTitle(TCHAR* newTitle);
- HRESULT ResetWindow(bool newWindowedState,int newWidth,int newHeight);
- void SetView(View *view){m_view=view;};
- View* GetView()const{return m_view;};
- HWND GetHwnd()const{return m_hWnd;};
- void SetUserMsgProc(void (CALLBACK*newMsgProc)( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)){m_userMsgProc=newMsgProc;};
- void SetPreRenderFunc(void (CALLBACK*newFunc)(void)){m_preRenderFunc=newFunc;};
- void SetPostRenderFunc(void (CALLBACK*newFunc)(void)){m_postRenderFunc=newFunc;};
- void SetGUIFunc(void (CALLBACK*newFunc)(HDC));
- void SetRestoreFunc(void (CALLBACK*newFunc)(void));
- void SetRenderFunc(void (CALLBACK*newFunc)(void));
- LRESULT MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void SetInitFunc(void(CALLBACK*newFunc)(void)){m_initFunc=newFunc;};
- void Exit(){DestroyWindow(m_hWnd);};
- private:
- HWND m_hWnd;
- bool m_windowed;
- int m_width;
- int m_height;
- View* m_view;
- AnimationController* m_AC;
- void(CALLBACK*m_userMsgProc)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void(CALLBACK*m_preRenderFunc)(void);
- void(CALLBACK*m_postRenderFunc)(void);
- void(CALLBACK*m_initFunc)(void);
- };
- class View{//视图,一个视图对应一个子窗口,一个程序可有多个视图。一个视图包含一个surface类作为其内容容器
- friend class CGLApplication;
- public:
- ~View();
- View(HWND hwnd);
- View(HWND hwnd,RECT rect);
- void SetGraphicController(GraphicController* gc){m_GC=gc;};// 每个视图的全局图像表现方式不同
- GraphicController* GetGraphicController()const{return this->m_GC;};
- void SetUIController(UIController* UIController){this->m_UC=UIController;};
- UIController* GetUIController()const{return m_UC;};
- void SetCamera(TCHAR* name);//每个视图一个摄像机
- Camera* GetCamera()const{return m_camera;};//得到当前摄像机的对象
- void SetScene(SceneTree*scene){this->m_scene=scene;};
- SceneTree* GetScene()const {return m_scene;};
- HWND GetHWnd()const{return m_hWnd;};
- void SetRect(RECT rect){
- if(m_rect!=NULL)
- {
- delete m_rect;
- }
- m_rect=new RECT(rect);
- };
- RECT* GetRect() const{return m_rect;};
- void SetSurface(Surface* suf){ this->m_surface=suf;};
- Surface* GetSurface()const{ return m_surface;};
- HRESULT Present();//渲染场景(在这里调用渲染处理管线的一系列函数并显示到当前平面)
- HRESULT Restore();//重新设置渲染状态
- HRESULT SetFullScreen(bool full);
- void CleanUp();
- private:
- HRESULT OnetimeInit();
- private:
- RECT * m_rect;//视图区域
- HWND m_hWnd;//视图所在的窗口或子窗口句柄
- Camera* m_camera;//当前摄像机
- Surface* m_surface;//当前渲染平面
- UIController* m_UC;
- GraphicController* m_GC;
- SceneTree* m_scene;
- bool m_primaryView;
- bool m_windowed;
- void(CALLBACK*m_guiFunc)(HDC hdc);
- void(CALLBACK*m_restoreFunc)(void);
- void(CALLBACK*m_renderFunc)(void);
- };
- class Surface{//可以存放图像数据的容器,可作为渲染平面,也可作为贴图表面用到UIController中
- friend class View;
- friend class UIController;
- friend class FileController;
- public:
- ~Surface();
- Surface(int width,int height,bool renderTarget=false);//renderTarget=true创建一个渲染表面(用于渲染)renderTarget=false创建一个普通表面(用于存放图像数据)
- void GetSize(int&tagWidth,int&tagHeight)const{tagWidth=m_width;tagHeight=m_height;} ;
- void CleanUp();
- private:
- int m_width;
- int m_height;
- IDirect3DSwapChain9* m_swapChain;//DX表面交换链(用于作为渲染表面)
- IDirect3DSurface9* m_dataSurface;//DX表面(用于存放图像数据)
- };
- #endif