comparison EXCLUDE/GLTSF/src/App.cpp @ 4738:381d402a5e90

Added support for On_Resized event to App. Added OpenGL code to draw a rotating triangle. Rearranged main loop code.
author dewyatt
date Sat, 12 Jun 2010 03:21:54 -0400
parents 0c7c67d4e6ee
children
comparison
equal deleted inserted replaced
4737:0e18c79c4111 4738:381d402a5e90
1 #include "App.hpp" 1 #include "App.hpp"
2 #include "TSF.hpp" 2 #include "TSF.hpp"
3 #include <GL/gl.h>
4 #include <GL/glu.h>
5
6 #pragma comment(lib, "glu32.lib")
7
8 GLfloat Rotation = 0.0f;
3 9
4 App::App() : my_Done(false) 10 App::App() : my_Done(false)
5 { 11 {
6 TSF::Initialize(); 12 TSF::Initialize();
7 } 13 }
17 Finalize(); 23 Finalize();
18 24
19 my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen); 25 my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen);
20 my_Window.Set_Listener(this); 26 my_Window.Set_Listener(this);
21 my_Window.Show(); 27 my_Window.Show();
28 my_Window.Hide_Cursor();
22 } 29 }
23 30
24 void App::Finalize() 31 void App::Finalize()
25 { 32 {
26 my_Window.Finalize(); 33 my_Window.Finalize();
29 void App::Run() 36 void App::Run()
30 { 37 {
31 Initialize(); 38 Initialize();
32 while (!my_Done) 39 while (!my_Done)
33 { 40 {
34 my_Window.Update(); 41 my_Window.Handle_Events();
35 my_Window.Clear(); 42
43 Update();
44 Draw();
36 my_Window.Display(); 45 my_Window.Display();
37 } 46 }
38 } 47 }
39 48
40 void App::On_Close() 49 void App::On_Close()
60 69
61 void App::On_Char(unsigned int Char) 70 void App::On_Char(unsigned int Char)
62 { 71 {
63 printf("Char: U+%04X\n", Char); 72 printf("Char: U+%04X\n", Char);
64 } 73 }
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 }