Created
January 17, 2014 23:59
-
-
Save Yatekii/8483963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <materialAdjuster.h> | |
| #include <iostream> | |
| #include <string> | |
| // Here is a small helper for you ! Have a look. | |
| #include "ResourcePath.hpp" | |
| #include "scene.h" | |
| //Utility for GUI stuff | |
| int main(int, char const**) | |
| { | |
| // Create the main window | |
| sf::RenderWindow window(sf::VideoMode(1250, 780), "Raytracer"); | |
| //SFGUI STUFF | |
| sfg::SFGUI sfgui; | |
| // Set the SFML Window's context back to the active one. SFGUI creates | |
| // a temporary context on creation that is set active. | |
| window.setActive(); | |
| // Load a sprite to display | |
| sf::Texture texture; | |
| texture.create(950, 780); | |
| sf::Sprite sprite(texture); | |
| sprite.setPosition(300, 0); | |
| Scene scene(Vector{0,0,-5}, Color{1, 1, 0}, Color{0.03, 0.7568, 1}, Color{0.3,0.3,0.3}); | |
| scene.AddLight(new Vector{0, 5, 5}); | |
| scene.AddLight(new Vector{2, 5, 1}); | |
| Material red(Color(1, 0.5, 0.5), Color(0.52, 0.02, 0), Color(0.8, 0.3, 0.3), 8, true, 1); | |
| Material green(Color(0.5, 1, 0.5), Color(0, 0.52, 0.02), Color(0.1, 0.1, 0.1), 20, true, 1); | |
| Sphere sphere(Vector{1, -0.8, 3}, 2.5, red); | |
| Sphere sphere2(Vector{-5.5, -0.5, 7}, 2, red); | |
| Sphere sphere3(Vector{2, 0.5, 4}, .5, red); | |
| Plane plane(Vector{0, 0, 4}, Vector{1, 0, 0}, Vector{0, 1, 0}, green); | |
| Plane plane2(Vector{0, -4.4, 0}, Vector{1, 0, 0}, Vector{0, 0, 1}, green); | |
| scene.AddShape(&sphere); | |
| scene.AddShape(&sphere2); | |
| scene.AddShape(&plane2); | |
| texture.update(scene.render(950, 780)); | |
| MaterialAdjuster materialAdjuster(red, "Red"); | |
| sfg::Desktop desktop; | |
| desktop.Add(materialAdjuster.getWindow()); | |
| sf::Clock clock; | |
| // Start the game loop | |
| while (window.isOpen()) | |
| { | |
| // Process events | |
| sf::Event event; | |
| while (window.pollEvent(event)) | |
| { | |
| // Close window : exit | |
| if (event.type == sf::Event::Closed) { | |
| window.close(); | |
| } | |
| else { | |
| desktop.HandleEvent( event ); | |
| } | |
| // Espace pressed : exit | |
| if (event.type == sf::Event::KeyPressed) { | |
| if (event.key.code == sf::Keyboard::Escape) { | |
| window.close(); | |
| } | |
| } | |
| if (event.type == sf::Event::MouseWheelMoved){ | |
| } | |
| } | |
| desktop.Update( clock.restart().asSeconds() ); | |
| materialAdjuster.update(); | |
| // Clear screen | |
| window.clear(); | |
| // Draw the sprite | |
| window.draw(sprite); | |
| // SFGUI rendering. | |
| sfgui.Display( window ); | |
| // Update the window | |
| window.display(); | |
| clock.restart(); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment