Skip to content

Instantly share code, notes, and snippets.

@zester
Created April 17, 2012 01:13
Show Gist options
  • Save zester/2402714 to your computer and use it in GitHub Desktop.
Save zester/2402714 to your computer and use it in GitHub Desktop.
Maratis3D and SFML2
#include <SFML/Graphics.hpp>
#include <MCore.h>
#include <MEngine.h>
#include "MGLContext.h"
#include <iostream>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = new MGLContext();
render->disableScissorTest();
render->setViewport(0, 0, 200, 200);
engine->setRenderingContext(render);
MGame * game = new MGame();
engine->setGame(game);
// get level
MLevel * level = new MLevel();
engine->setLevel(level);
if(level->getScenesNumber() == 0)
{
MScene * scene = level->addNewScene();
MOCamera * camera = scene->addNewCamera();
camera->setClearColor(MVector3(1.0f, 0.075f, 1.0f)); // set grey clear color
camera->setPosition(MVector3(0.0f, -80.0f, 20.0f));
camera->setEulerRotation(MVector3(90.0f, 0.0f, 0.0f));
MMeshRef * meshRef = level->loadMesh("box.mesh");
MOEntity * box1 = scene->addNewEntity(meshRef);
box1->setPosition(MVector3(70, 65, 0));
box1->setScale(MVector3(4, 4, 0.2f));
MOLight * light = scene->addNewLight();
light->setPosition(MVector3(0.0f, 0.0f, 100.0f));
light->setRadius(1000.0f);
}
game->begin();
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
}
// Clear screen
window.Clear(sf::Color(255, 255, 255 ,255));
game->draw();
std::cout << game->isRunning() << std::endl;
// Update the window
window.Display();
}
game->end();
SAFE_DELETE(game);
SAFE_DELETE(level);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment