2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Headers
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#include <SFML/Window.hpp>
|
2009-03-29 00:22:58 +08:00
|
|
|
#include <SFML/OpenGL.hpp>
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// Entry point of application
|
|
|
|
///
|
|
|
|
/// \return Application exit code
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Create the main window
|
2011-04-05 05:37:20 +08:00
|
|
|
sf::Window window(sf::VideoMode(640, 480, 32), "SFML Window", sf::Style::Default, sf::ContextSettings(32));
|
2009-03-05 02:42:11 +08:00
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
// Create a clock for measuring the time elapsed
|
2009-07-12 06:17:24 +08:00
|
|
|
sf::Clock clock;
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Set the color and depth clear values
|
|
|
|
glClearDepth(1.f);
|
|
|
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
|
|
|
|
|
|
// Enable Z-buffer read and write
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
|
|
|
|
// Setup a perspective projection
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPerspective(90.f, 1.f, 1.f, 500.f);
|
|
|
|
|
|
|
|
// Start the game loop
|
2012-01-13 21:53:36 +08:00
|
|
|
while (window.IsOpen())
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
// Process events
|
2009-07-12 06:17:24 +08:00
|
|
|
sf::Event event;
|
2011-04-12 00:20:21 +08:00
|
|
|
while (window.PollEvent(event))
|
2009-01-29 00:18:34 +08:00
|
|
|
{
|
|
|
|
// Close window : exit
|
2009-07-12 06:17:24 +08:00
|
|
|
if (event.Type == sf::Event::Closed)
|
|
|
|
window.Close();
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Escape key : exit
|
2011-07-04 14:21:40 +08:00
|
|
|
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Keyboard::Escape))
|
2009-07-12 06:17:24 +08:00
|
|
|
window.Close();
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Resize event : adjust viewport
|
2009-07-12 06:17:24 +08:00
|
|
|
if (event.Type == sf::Event::Resized)
|
|
|
|
glViewport(0, 0, event.Size.Width, event.Size.Height);
|
2009-03-05 02:42:11 +08:00
|
|
|
}
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2009-10-27 17:20:20 +08:00
|
|
|
// Activate the window before using OpenGL commands.
|
|
|
|
// This is useless here because we have only one window which is
|
|
|
|
// always the active one, but don't forget it if you use multiple windows
|
2009-10-04 21:00:59 +08:00
|
|
|
window.SetActive();
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
// Clear color and depth buffer
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
// Apply some transformations
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(0.f, 0.f, -200.f);
|
2011-05-19 14:18:40 +08:00
|
|
|
glRotatef(clock.GetElapsedTime() * 0.05f, 1.f, 0.f, 0.f);
|
|
|
|
glRotatef(clock.GetElapsedTime() * 0.03f, 0.f, 1.f, 0.f);
|
|
|
|
glRotatef(clock.GetElapsedTime() * 0.09f, 0.f, 0.f, 1.f);
|
2009-01-29 00:18:34 +08:00
|
|
|
|
|
|
|
// Draw a cube
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
glColor3f(1.f, 0.f, 0.f);
|
|
|
|
glVertex3f(-50.f, -50.f, -50.f);
|
|
|
|
glVertex3f(-50.f, 50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, 50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, -50.f, -50.f);
|
|
|
|
|
|
|
|
glColor3f(1.f, 0.f, 0.f);
|
|
|
|
glVertex3f(-50.f, -50.f, 50.f);
|
|
|
|
glVertex3f(-50.f, 50.f, 50.f);
|
|
|
|
glVertex3f( 50.f, 50.f, 50.f);
|
|
|
|
glVertex3f( 50.f, -50.f, 50.f);
|
|
|
|
|
|
|
|
glColor3f(0.f, 1.f, 0.f);
|
|
|
|
glVertex3f(-50.f, -50.f, -50.f);
|
|
|
|
glVertex3f(-50.f, 50.f, -50.f);
|
|
|
|
glVertex3f(-50.f, 50.f, 50.f);
|
|
|
|
glVertex3f(-50.f, -50.f, 50.f);
|
|
|
|
|
|
|
|
glColor3f(0.f, 1.f, 0.f);
|
|
|
|
glVertex3f(50.f, -50.f, -50.f);
|
|
|
|
glVertex3f(50.f, 50.f, -50.f);
|
|
|
|
glVertex3f(50.f, 50.f, 50.f);
|
|
|
|
glVertex3f(50.f, -50.f, 50.f);
|
|
|
|
|
|
|
|
glColor3f(0.f, 0.f, 1.f);
|
|
|
|
glVertex3f(-50.f, -50.f, 50.f);
|
|
|
|
glVertex3f(-50.f, -50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, -50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, -50.f, 50.f);
|
|
|
|
|
|
|
|
glColor3f(0.f, 0.f, 1.f);
|
|
|
|
glVertex3f(-50.f, 50.f, 50.f);
|
|
|
|
glVertex3f(-50.f, 50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, 50.f, -50.f);
|
|
|
|
glVertex3f( 50.f, 50.f, 50.f);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Finally, display the rendered frame on screen
|
2009-07-12 06:17:24 +08:00
|
|
|
window.Display();
|
2009-01-29 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|