PageRenderTime 32ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Example_RendererSGUsage/Example_RendererSGMain.h

http://github.com/Akranar/daguerreo
C Header | 130 lines | 102 code | 26 blank | 2 comment | 15 complexity | 039444c51e8565c942a227e96c699c71 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, LGPL-3.0, GPL-2.0
  1#ifndef _EXAMPLE_RENDERER_SG_MAIN_H_
  2#define _EXAMPLE_RENDERER_SG_MAIN_H_
  3
  4#include "ExLib_RendererBaseUsage.h"
  5#include "ExLib_RendererBase.h"
  6#include "ExLib_Eigen.h"
  7#include "ExLib_WindowEvents.h"
  8
  9#include "ApplicationLoop.h"
 10#include "Projector.h"
 11#include "MouseLookController.h"
 12
 13
 14
 15
 16class Example_Main
 17{
 18public:
 19	RendererBase renderer;
 20	Example_SceneData scene_data;
 21	Example_RenderStates render_state_set;
 22	Example_TorusMesh mesh_torus;
 23	Example_EffectFragmentLighting effect_fragmentlighting;
 24	Example_MeshQuad mesh_quad;
 25	Example_MeshBox mesh_box;
 26	Example_EffectCubeMap effect_cubemap;
 27
 28	void Init(WindowEvents * window)
 29	{
 30		renderer.Initialize(window);
 31		renderer.ClearColor(0.4f, 0.4f, 1.0f, 1.0f);
 32
 33		scene_data.Init();
 34		mesh_torus.Init(&renderer);
 35		mesh_torus.InitWithShader(effect_fragmentlighting.Init(&renderer, &scene_data.camera, &scene_data.light_source));
 36		mesh_torus.InitWithShader(effect_cubemap.Init(&renderer, &scene_data.camera));
 37
 38		mesh_quad.Init(&renderer);
 39		mesh_quad.InitWithShader(&effect_fragmentlighting.shader_program);
 40		mesh_quad.InitWithShader(&effect_cubemap.shader_program);
 41
 42		mesh_box.Init(&renderer);
 43		mesh_box.InitWithShader(&effect_fragmentlighting.shader_program);
 44		mesh_box.InitWithShader(&effect_cubemap.shader_program);
 45		
 46		render_state_set.Init(&renderer);
 47		render_state_set.Set();
 48		
 49	}
 50	void Deinit()
 51	{ 
 52		render_state_set.Deinit();
 53		effect_cubemap.Deinit();
 54		effect_fragmentlighting.Deinit();
 55		mesh_box.Deinit(renderer);
 56		mesh_quad.Deinit(renderer);
 57		mesh_torus.Deinit(renderer);
 58	}
 59
 60	void Draw()
 61	{	
 62		renderer.PreRender();
 63		{
 64			renderer.ClearAllBuffer();
 65
 66			
 67			mesh_torus.PreRender();
 68			mesh_torus.PreRenderWithShader(effect_fragmentlighting.PreRender());
 69			renderer.Draw();
 70
 71			mesh_quad.PreRender();
 72			mesh_quad.PreRenderWithShader(&effect_fragmentlighting.shader_program);
 73			renderer.Draw();
 74			
 75
 76			mesh_box.PreRender();
 77			//mesh_box.PreRenderWithShader(&effect_fragmentlighting.shader_program);
 78			mesh_box.PreRenderWithShader(effect_cubemap.PreRender());
 79			renderer.Draw();
 80			
 81		}
 82		renderer.PostRender();
 83	}
 84
 85	void Update(double seconds_elapsed, WindowEvents * active_window)
 86	{
 87		if (active_window)
 88		{
 89			InputManager * input_manager = &active_window->GetInputManager();
 90			while (input_manager->HasEvents())
 91			{
 92				input_manager->ProcessNext();
 93				const InputEvent & input_event = input_manager->PeekNext();
 94
 95				if (input_event.GetType() == InputEvent::KEYBOARD && input_event.data.key.GetType() == KeyEvent::KEY_DOWN)
 96				{
 97
 98				}
 99				else if (input_event.GetType() == InputEvent::KEYBOARD && input_event.data.key.GetType() == KeyEvent::KEY_UP)
100				{
101					switch (input_event.data.key.GetKey())
102					{
103
104						case KeyID::KEY_ESCAPE:
105						{
106							//Temporary hack to fix problem in windows where after Q down to close window, the up key isn't caught.
107							active_window->Close();
108						}
109						break;
110						default:
111						break;
112					}
113				}
114				else if (input_event.GetType() == InputEvent::RESIZE)
115				{
116					renderer.OnViewportUpdate(0, 0, input_event.data.resize.GetWidth(), input_event.data.resize.GetHeight());
117					scene_data.camera.SetPerspective(45.0f, float(input_event.data.resize.GetWidth()) /  float(input_event.data.resize.GetHeight()), 1.0f, 5000);
118				}
119				scene_data.UpdateCameraOrientation(active_window, seconds_elapsed);
120				input_manager->PopEvent();
121			}
122			scene_data.UpdateCameraPosition(active_window, seconds_elapsed);
123		}
124		mesh_torus.Update(seconds_elapsed);
125	}
126
127	
128};
129
130#endif