#include #include using namespace Frontend; using namespace Frontend::Utils; using namespace Frontend::Utils::Simple; int main(int argc, char** argv) { // Initialize SimpleSetup SimpleSetup setup(GUI::CreateNativeWindowManager(), Graphics::OpenFrontendGL2CG()); setup.SetResolution(800, 600); setup.SetTitle("Hello Frontend!\n"); setup.Start(); // Hook mouse and keyboard events Keyboard keyboard(setup.GetWindow()); Mouse mouse(setup.GetWindow()); // Initialize painter and the sprite image Simple2D painter(setup.GetGraphicsDevice()); RTexture2D image("data/image.png"); // Initialize blend mode used to draw the sprite Graphics::BlendStateDescriptor blend; blend.BlendEnabled = true; blend.BlendSrcRGB = Graphics::BlendOperandSrcAlpha; blend.BlendDstRGB = Graphics::BlendOperandOneMinusSrcAlpha; // Initialize sprite position Math::Vector2 position(100, 100); while (setup.Update()) { // Clear the screen setup.GetGraphicsDevice()->Clear(Graphics::ClearBuffersAll, 0, 0, 0, 0, 1, 0); // Get the duration of last frame float frameTime = setup.GetFrameTime(); // Move the sprite using the arrow keys if (keyboard.KeyDown(GUI::KeyLeftArrow)) position.x -= frameTime * 300.0f; if (keyboard.KeyDown(GUI::KeyRightArrow)) position.x += frameTime * 300.0f; if (keyboard.KeyDown(GUI::KeyUpArrow)) position.y -= frameTime * 300.0f; if (keyboard.KeyDown(GUI::KeyDownArrow)) position.y += frameTime * 300.0f; // Lock the sprite inside the window position.x = Math::Max(0, position.x); position.y = Math::Max(0, position.y); position.x = Math::Min(position.x, setup.GetWindow()->GetWidth()-image->GetWidth()); position.y = Math::Min(position.y, setup.GetWindow()->GetHeight()-image->GetHeight()); // Set blend mode setup.GetState()->Blend.Push(blend); // Draw sprite painter.DrawQuad(setup.GetState(), position, image); // Restore blend mode setup.GetState()->Blend.Pop(); } }