annotate EXCLUDE/GLTSF/src/App.cpp @ 4740:abf528de6d2e

Added condition check macros to make the code clear and easier to debug. Updated code to use macros.
author dewyatt
date Sun, 27 Jun 2010 22:03:08 -0400
parents 381d402a5e90
children
rev   line source
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
1 #include "App.hpp"
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
2 #include "TSF.hpp"
4738
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
3 #include <GL/gl.h>
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
4 #include <GL/glu.h>
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
5
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
6 #pragma comment(lib, "glu32.lib")
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
7
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
8 GLfloat Rotation = 0.0f;
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
9
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
10 App::App() : my_Done(false)
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
11 {
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
12 TSF::Initialize();
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
13 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
14
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
15 App::~App()
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
16 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
17 Finalize();
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
18 TSF::Finalize();
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
19 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
20
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
21 void App::Initialize()
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
22 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
23 Finalize();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
24
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
25 my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen);
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
26 my_Window.Set_Listener(this);
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
27 my_Window.Show();
4738
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
28 my_Window.Hide_Cursor();
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
29 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
30
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
31 void App::Finalize()
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
32 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
33 my_Window.Finalize();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
34 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
35
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
36 void App::Run()
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
37 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
38 Initialize();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
39 while (!my_Done)
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
40 {
4738
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
41 my_Window.Handle_Events();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
42
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
43 Update();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
44 Draw();
4730
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
45 my_Window.Display();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
46 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
47 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
48
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
49 void App::On_Close()
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
50 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
51 my_Done = true;
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
52 my_Window.Hide();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
53 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
54
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
55 void App::On_Key_Down(int Key)
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
56 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
57 switch (Key)
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
58 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
59 case VK_ESCAPE:
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
60 On_Close();
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
61 break;
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
62 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
63 }
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
64
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
65 void App::On_Key_Up(int Key)
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
66 {
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
67
6032ada8b9e5 Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff changeset
68 }
4734
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
69
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
70 void App::On_Char(unsigned int Char)
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
71 {
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
72 printf("Char: U+%04X\n", Char);
0c7c67d4e6ee Added On_Char method to Window_Listener for WM_CHAR messages.
dewyatt
parents: 4730
diff changeset
73 }
4738
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
74
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
75 void App::On_Resized(unsigned int Width, unsigned int Height)
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
76 {
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
77 glViewport(0, 0, Width, Height);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
78 glMatrixMode(GL_PROJECTION);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
79 glLoadIdentity();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
80
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
81 glMatrixMode(GL_MODELVIEW);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
82 glLoadIdentity();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
83 }
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
84
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
85 void App::Update()
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
86 {
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
87 Rotation += 0.2f;
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
88 }
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
89
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
90 void App::Draw()
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
91 {
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
92 glClear(GL_COLOR_BUFFER_BIT);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
93
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
94 glLoadIdentity();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
95 glRotatef(Rotation, 0.0f, 0.0f, -1.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
96
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
97 glBegin(GL_TRIANGLES);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
98 glColor3f(0.7f, 0.0f, 0.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
99 glVertex3f(0.0f, 0.5f, 0.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
100 glColor3f(0.0f, 0.7f, 0.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
101 glVertex3f(-0.5f, -0.5f, 0.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
102 glColor3f(0.0f, 0.0f, 0.7f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
103 glVertex3f(0.5f, -0.5f, 0.0f);
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
104 glEnd();
381d402a5e90 Added support for On_Resized event to App.
dewyatt
parents: 4734
diff changeset
105 }