Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added support for On_Resized event to App.
Added OpenGL code to draw a rotating triangle.
Rearranged main loop code.
- Loading branch information
Showing
with
48 additions
and
3 deletions.
-
+5
−1
EXCLUDE/GLTSF/include/App.hpp
-
+43
−2
EXCLUDE/GLTSF/src/App.cpp
|
@@ -18,12 +18,16 @@ class App : public Window_Listener |
|
|
virtual void On_Key_Down(int Key); |
|
|
virtual void On_Key_Up(int Key); |
|
|
virtual void On_Char(unsigned int Char); |
|
|
virtual void On_Resized(unsigned int Width, unsigned int Height); |
|
|
|
|
|
private: |
|
|
void Update(); |
|
|
void Draw(); |
|
|
|
|
|
static const int Width = 800; |
|
|
static const int Height = 600; |
|
|
static const int Bits_Per_Pixel = 32; |
|
|
static const bool Fullscreen = false; |
|
|
static const bool Fullscreen = true; |
|
|
|
|
|
Window my_Window; |
|
|
bool my_Done; |
|
|
|
|
@@ -1,5 +1,11 @@ |
|
|
#include "App.hpp" |
|
|
#include "TSF.hpp" |
|
|
#include <GL/gl.h> |
|
|
#include <GL/glu.h> |
|
|
|
|
|
#pragma comment(lib, "glu32.lib") |
|
|
|
|
|
GLfloat Rotation = 0.0f; |
|
|
|
|
|
App::App() : my_Done(false) |
|
|
{ |
|
@@ -19,6 +25,7 @@ void App::Initialize() |
|
|
my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen); |
|
|
my_Window.Set_Listener(this); |
|
|
my_Window.Show(); |
|
|
my_Window.Hide_Cursor(); |
|
|
} |
|
|
|
|
|
void App::Finalize() |
|
@@ -31,8 +38,10 @@ void App::Run() |
|
|
Initialize(); |
|
|
while (!my_Done) |
|
|
{ |
|
|
my_Window.Update(); |
|
|
my_Window.Clear(); |
|
|
my_Window.Handle_Events(); |
|
|
|
|
|
Update(); |
|
|
Draw(); |
|
|
my_Window.Display(); |
|
|
} |
|
|
} |
|
@@ -62,3 +71,35 @@ void App::On_Char(unsigned int Char) |
|
|
{ |
|
|
printf("Char: U+%04X\n", Char); |
|
|
} |
|
|
|
|
|
void App::On_Resized(unsigned int Width, unsigned int Height) |
|
|
{ |
|
|
glViewport(0, 0, Width, Height); |
|
|
glMatrixMode(GL_PROJECTION); |
|
|
glLoadIdentity(); |
|
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
glLoadIdentity(); |
|
|
} |
|
|
|
|
|
void App::Update() |
|
|
{ |
|
|
Rotation += 0.2f; |
|
|
} |
|
|
|
|
|
void App::Draw() |
|
|
{ |
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
|
glLoadIdentity(); |
|
|
glRotatef(Rotation, 0.0f, 0.0f, -1.0f); |
|
|
|
|
|
glBegin(GL_TRIANGLES); |
|
|
glColor3f(0.7f, 0.0f, 0.0f); |
|
|
glVertex3f(0.0f, 0.5f, 0.0f); |
|
|
glColor3f(0.0f, 0.7f, 0.0f); |
|
|
glVertex3f(-0.5f, -0.5f, 0.0f); |
|
|
glColor3f(0.0f, 0.0f, 0.7f); |
|
|
glVertex3f(0.5f, -0.5f, 0.0f); |
|
|
glEnd(); |
|
|
} |