Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //download - http://www.mediafire.com/?1fl2lt5ctxwtdra
- ////////////////////////////////////////////////////////////
- // Headers
- ////////////////////////////////////////////////////////////
- #include <SFML/Window.hpp>
- ////////////////////////////////////////////////////////////
- /// Entry point of application
- ///
- /// \return Application exit code
- ///
- ////////////////////////////////////////////////////////////
- int main()
- {
- // Create the main window
- sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
- // Create a clock for measuring time elapsed
- sf::Clock Clock;
- // Set color and depth clear value
- glClearDepth(1.f);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- // Enable Z-buffer read and write
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHTING); //Enable lighting
- glEnable(GL_LIGHT0); //Enable light #0
- glEnable(GL_LIGHT1); //Enable light #1
- glEnable(GL_NORMALIZE); //Automatically normalize normals
- //glShadeModel(GL_SMOOTH); //Enable smooth shading
- glDepthMask(GL_TRUE);
- // Setup a perspective projection
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(90, 4.0/3.0, 1, 500);
- // Start game loop
- while (App.IsOpened())
- {
- // Process events
- sf::Event Event;
- while (App.GetEvent(Event))
- {
- // Close window : exit
- if (Event.Type == sf::Event::Closed)
- App.Close();
- // Escape key : exit
- if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
- App.Close();
- // Resize event : adjust viewport
- if (Event.Type == sf::Event::Resized)
- {
- glViewport(0, 0, Event.Size.Width, Event.Size.Height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(90, (double) Event.Size.Width / (double) Event.Size.Height, 1, 500);
- }
- }
- // Set the active window before using OpenGL commands
- // It's useless here because active window is always the same,
- // but don't forget it if you use multiple windows or controls
- App.SetActive();
- // Clear color and depth buffer
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Apply some transformations
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -5.0f);
- //Add ambient light
- GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color (0.2, 0.2, 0.2)
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
- //Add positioned light
- GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5)
- GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8)
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
- //Add directed light
- GLfloat lightColor1[] = {2.0f, 0.0f, 0.0f, 0.0f}; //Color (0.5, 0.2, 0.2)
- //Coming from the direction (-1, 0.5, 0.5)
- GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, -0.0f};
- glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
- glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
- glRotatef(Clock.GetElapsedTime() * 100, 1.0f, 0.0f, 0.0f);
- glRotatef(Clock.GetElapsedTime() * 100, 0.0f, 1.0f, 0.0f);
- glRotatef(Clock.GetElapsedTime() * 100, 0.0f, 0.0f, 1.0f);
- glColor3f(1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- //Front
- glNormal3f(0.0f, 0.0f, 1.0f);
- //glNormal3f(-1.0f, 0.0f, 1.0f);
- glVertex3f(-1.5f, -1.0f, 1.5f);
- //glNormal3f(1.0f, 0.0f, 1.0f);
- glVertex3f(1.5f, -1.0f, 1.5f);
- //glNormal3f(1.0f, 0.0f, 1.0f);
- glVertex3f(1.5f, 1.0f, 1.5f);
- //glNormal3f(-1.0f, 0.0f, 1.0f);
- glVertex3f(-1.5f, 1.0f, 1.5f);
- //Right
- glNormal3f(1.0f, 0.0f, 0.0f);
- //glNormal3f(1.0f, 0.0f, -1.0f);
- glVertex3f(1.5f, -1.0f, -1.5f);
- //glNormal3f(1.0f, 0.0f, -1.0f);
- glVertex3f(1.5f, 1.0f, -1.5f);
- //glNormal3f(1.0f, 0.0f, 1.0f);
- glVertex3f(1.5f, 1.0f, 1.5f);
- //glNormal3f(1.0f, 0.0f, 1.0f);
- glVertex3f(1.5f, -1.0f, 1.5f);
- //Back
- glNormal3f(0.0f, 0.0f, -1.0f);
- //glNormal3f(-1.0f, 0.0f, -1.0f);
- glVertex3f(-1.5f, -1.0f, -1.5f);
- //glNormal3f(-1.0f, 0.0f, -1.0f);
- glVertex3f(-1.5f, 1.0f, -1.5f);
- //glNormal3f(1.0f, 0.0f, -1.0f);
- glVertex3f(1.5f, 1.0f, -1.5f);
- //glNormal3f(1.0f, 0.0f, -1.0f);
- glVertex3f(1.5f, -1.0f, -1.5f);
- //Left
- glNormal3f(-1.0f, 0.0f, 0.0f);
- //glNormal3f(-1.0f, 0.0f, -1.0f);
- glVertex3f(-1.5f, -1.0f, -1.5f);
- //glNormal3f(-1.0f, 0.0f, 1.0f);
- glVertex3f(-1.5f, -1.0f, 1.5f);
- //glNormal3f(-1.0f, 0.0f, 1.0f);
- glVertex3f(-1.5f, 1.0f, 1.5f);
- //glNormal3f(-1.0f, 0.0f, -1.0f);
- glVertex3f(-1.5f, 1.0f, -1.5f);
- //Top
- glNormal3f(0.0f, 1.0f, 0.0f);
- glVertex3f(1.5f, 1.0f, -1.5f);
- glVertex3f(1.5f, 1.0f, 1.5f);
- glVertex3f(-1.5f, 1.0f, 1.5f);
- glVertex3f(-1.5f, 1.0f, -1.5f);
- //Back
- glNormal3f(0.0f, -1.0f, 0.0f);
- glVertex3f(1.5f, -1.0f, -1.5f);
- glVertex3f(1.5f, -1.0f, 1.5f);
- glVertex3f(-1.5f, -1.0f, 1.5f);
- glVertex3f(-1.5f, -1.0f, -1.5f);
- glEnd();
- // Finally, display rendered frame on screen
- App.Display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement