Mercurial > sdl-ios-xcode
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 | 3 #include <GL/gl.h> |
4 #include <GL/glu.h> | |
5 | |
6 #pragma comment(lib, "glu32.lib") | |
7 | |
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 | 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 | 41 my_Window.Handle_Events(); |
42 | |
43 Update(); | |
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 | 74 |
75 void App::On_Resized(unsigned int Width, unsigned int Height) | |
76 { | |
77 glViewport(0, 0, Width, Height); | |
78 glMatrixMode(GL_PROJECTION); | |
79 glLoadIdentity(); | |
80 | |
81 glMatrixMode(GL_MODELVIEW); | |
82 glLoadIdentity(); | |
83 } | |
84 | |
85 void App::Update() | |
86 { | |
87 Rotation += 0.2f; | |
88 } | |
89 | |
90 void App::Draw() | |
91 { | |
92 glClear(GL_COLOR_BUFFER_BIT); | |
93 | |
94 glLoadIdentity(); | |
95 glRotatef(Rotation, 0.0f, 0.0f, -1.0f); | |
96 | |
97 glBegin(GL_TRIANGLES); | |
98 glColor3f(0.7f, 0.0f, 0.0f); | |
99 glVertex3f(0.0f, 0.5f, 0.0f); | |
100 glColor3f(0.0f, 0.7f, 0.0f); | |
101 glVertex3f(-0.5f, -0.5f, 0.0f); | |
102 glColor3f(0.0f, 0.0f, 0.7f); | |
103 glVertex3f(0.5f, -0.5f, 0.0f); | |
104 glEnd(); | |
105 } |