105 lines
3.0 KiB
C++
105 lines
3.0 KiB
C++
|
|
#include <SFML/Window.hpp>
|
|
|
|
int main()
|
|
{
|
|
sf::Clock Clock;
|
|
sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
|
|
App.UseVerticalSync(true);
|
|
App.SetActive();
|
|
|
|
// Set color and depth clear value
|
|
glClearDepth(1.f);
|
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
glEnable(GL_LIGHTING);
|
|
glEnable(GL_LIGHT0);
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
glColor3f(1.f, 1.f, 1.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);
|
|
|
|
while (App.IsOpened())
|
|
{
|
|
sf::Event Event;
|
|
while (App.GetEvent(Event))
|
|
{
|
|
if (Event.Type == sf::Event::Closed)
|
|
App.Close();
|
|
|
|
if ( (Event.Type == sf::Event::KeyPressed)
|
|
&& (Event.Key.Code == sf::Key::Escape) )
|
|
App.Close();
|
|
|
|
if (Event.Type == sf::Event::Resized)
|
|
{
|
|
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
gluPerspective(90.f,
|
|
(float)Event.Size.Width / (float)Event.Size.Height,
|
|
1.f, 500.f);
|
|
}
|
|
|
|
}
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
glTranslatef(0.f, 0.f, -200.f);
|
|
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
|
|
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
|
|
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glNormal3f(0, 0, -1);
|
|
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);
|
|
|
|
glNormal3f(0, 0, 1);
|
|
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);
|
|
|
|
glNormal3f(-1, 0, 0);
|
|
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);
|
|
|
|
glNormal3f(1, 0, 0);
|
|
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);
|
|
|
|
glNormal3f(0, -1, 0);
|
|
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);
|
|
|
|
glNormal3f(0, 1, 0);
|
|
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();
|
|
|
|
App.Display();
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|