4741
|
1 #include "App.hpp"
|
|
2 #include <GL/gl.h>
|
|
3 #include <GL/glu.h>
|
|
4
|
|
5 #pragma comment(lib, "glu32.lib")
|
|
6
|
|
7 GLfloat Rotation = 0.0f;
|
|
8
|
|
9 App::App() : my_Done(false)
|
|
10 {
|
|
11
|
|
12 }
|
|
13
|
|
14 App::~App()
|
|
15 {
|
|
16 Finalize();
|
|
17 }
|
|
18
|
|
19 void App::Initialize()
|
|
20 {
|
|
21 Finalize();
|
|
22
|
4743
|
23 my_Window.Initialize(L"GLIMM", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen);
|
4741
|
24 my_Window.Set_Listener(this);
|
|
25 my_Window.Show();
|
|
26 my_Window.Hide_Cursor();
|
|
27 }
|
|
28
|
|
29 void App::Finalize()
|
|
30 {
|
|
31 my_Window.Finalize();
|
|
32 }
|
|
33
|
|
34 void App::Run()
|
|
35 {
|
|
36 Initialize();
|
|
37 while (!my_Done)
|
|
38 {
|
|
39 my_Window.Handle_Events();
|
|
40
|
|
41 Update();
|
|
42 Draw();
|
|
43 my_Window.Display();
|
|
44 }
|
|
45 }
|
|
46
|
|
47 void App::On_Close()
|
|
48 {
|
|
49 my_Done = true;
|
|
50 my_Window.Hide();
|
|
51 }
|
|
52
|
|
53 void App::On_Key_Down(int Key)
|
|
54 {
|
|
55 switch (Key)
|
|
56 {
|
|
57 case VK_ESCAPE:
|
|
58 On_Close();
|
|
59 break;
|
|
60 }
|
|
61 }
|
|
62
|
|
63 void App::On_Key_Up(int Key)
|
|
64 {
|
|
65
|
|
66 }
|
|
67
|
|
68 void App::On_Char(unsigned int Char)
|
|
69 {
|
|
70 printf("Char: U+%04X\n", Char);
|
|
71 }
|
|
72
|
|
73 void App::On_Resized(unsigned int Width, unsigned int Height)
|
|
74 {
|
|
75 glViewport(0, 0, Width, Height);
|
|
76 glMatrixMode(GL_PROJECTION);
|
|
77 glLoadIdentity();
|
|
78
|
|
79 glMatrixMode(GL_MODELVIEW);
|
|
80 glLoadIdentity();
|
|
81 }
|
|
82
|
4744
|
83 void App::On_Mouse_Button_Down(Mouse_Button Button)
|
|
84 {
|
|
85 switch (Button)
|
|
86 {
|
|
87 case Mouse_Button_Left:
|
|
88 my_Window.Get_IMM().Toggle();
|
|
89 break;
|
|
90 }
|
|
91 }
|
|
92
|
4741
|
93 void App::Update()
|
|
94 {
|
|
95 Rotation += 0.2f;
|
|
96 }
|
|
97
|
|
98 void App::Draw()
|
|
99 {
|
|
100 glClear(GL_COLOR_BUFFER_BIT);
|
|
101
|
|
102 glLoadIdentity();
|
|
103 glRotatef(Rotation, 0.0f, 0.0f, -1.0f);
|
|
104
|
|
105 glBegin(GL_TRIANGLES);
|
|
106 glColor3f(0.7f, 0.0f, 0.0f);
|
|
107 glVertex3f(0.0f, 0.5f, 0.0f);
|
|
108 glColor3f(0.0f, 0.7f, 0.0f);
|
|
109 glVertex3f(-0.5f, -0.5f, 0.0f);
|
|
110 glColor3f(0.0f, 0.0f, 0.7f);
|
|
111 glVertex3f(0.5f, -0.5f, 0.0f);
|
|
112 glEnd();
|
|
113 }
|