add simple fixed-functionality OpenGL demo to client for now

This commit is contained in:
Josh Holtrop 2012-08-14 22:11:31 -04:00
parent 34e909fca8
commit aedc9b664c
2 changed files with 55 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#include "Client.h"
#include <SFML/OpenGL.hpp>
Client::Client(bool fullscreen)
{
@ -10,6 +11,7 @@ Client::Client(bool fullscreen)
? sf::Style::Fullscreen
: sf::Style::Resize | sf::Style::Close;
m_window = new sf::Window(mode, "Treacherous Terrain", style);
resize_window(m_window->getSize().x, m_window->getSize().y);
}
void Client::run()
@ -19,14 +21,59 @@ void Client::run()
sf::Event event;
while (m_window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
m_window->close();
if ( (event.type == sf::Event::KeyPressed)
&& (event.key.code == sf::Keyboard::Escape) )
switch (event.type)
{
case sf::Event::Closed:
m_window->close();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::Escape:
m_window->close();
break;
default:
break;
}
break;
case sf::Event::Resized:
resize_window(event.size.width, event.size.height);
break;
default:
break;
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* simple fixed-functionality drawing demo for now */
glPushMatrix();
glRotatef(m_clock.getElapsedTime().asSeconds() * 180.0f, 0, 0, 1);
glBegin(GL_QUADS);
glColor3f(1, 0.6, 0.1);
glVertex2f(1, 1);
glColor3f(0, 0, 1);
glVertex2f(-1, 1);
glColor3f(1, 0, 0);
glVertex2f(-1, -1);
glColor3f(0, 1, 0);
glVertex2f(1, -1);
glEnd();
glPopMatrix();
m_window->display();
}
}
void Client::initgl()
{
glShadeModel(GL_SMOOTH);
glDisable(GL_LIGHTING);
}
void Client::resize_window(int width, int height)
{
glViewport(0, 0, width, height);
float aspect = (float)width / (float)height;
glOrtho(-1.2 * aspect, 1.2 * aspect, -1.2, 1.2, 1, -1);
}

View File

@ -11,7 +11,10 @@ class Client
Client(bool fullscreen);
void run();
protected:
void initgl();
void resize_window(int width, int height);
refptr<sf::Window> m_window;
sf::Clock m_clock;
};
#endif