int main() { sgb::Chip8 chip8; chip8.loadGame("PONG2"); back.create(64, 32, sf::Color::Black); backshape.setPosition(0, 0); backtext.loadFromImage(back); backshape.setTexture(&backtext); while(window.isOpen()){ sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } // emulate one cycle chip8.emulateCycle(); // if drawflag is set, update screen; if (chip8.drawFlag) updateGraphics(chip8); //query keys chip8.setKeys(); sf::sleep(sf::seconds(1.0f/500.0f)); } return 0; }
//This is the primary graphics loop int graphicsLoop(const terrain* map) { image.create(map->h_map[0].size(), map->h_map.size()); sf::Texture texture; texture.loadFromImage(image); sf::Sprite sprite(texture); Event event; bool drag = false; Vector2f refCrsrCoords(-1, -1); image = renderMap(map, image); texture.loadFromImage(image); while (window.isOpen()) { while (window.pollEvent(event)) { if (event.type == Event::Closed) return closeWindow(); if (event.type == Event::KeyReleased && event.key.code == sf::Keyboard::Key::Q) return closeWindow(); if (event.type == Event::KeyReleased && event.key.code == sf::Keyboard::Key::Space) return 2; keyMove(event); mouseMove(event, drag, refCrsrCoords); } window.clear(sf::Color::Black); window.draw(sprite); window.display(); } return 0; }
int main() { sf::RenderWindow App(sf::VideoMode(imageWidth, imageHeight), "SFML Graphics",sf::Style::Fullscreen); // This is the SFML application initialization with the app's parameters cx[0] = 255; cx[1] = 0; cx[2] = 0; // The initial colors for the shifting kradius = 0.1; imagen.create(imageWidth,imageHeight); mandtex.create(imageWidth,imageHeight); // The scaling factor, defined by the ranges in Real and Imaginary axis, // divided by the respective axis real length. mandelb.setOrigin(imageWidth/2,imageHeight/2); mandelb.setPosition(640,400); mandelb.scale(1.5,1.5); // Set the image positioning, centering and scaling. k.real = 0; k.imag = 0; // Original K seed values. dir = false; // Direction of scan over the complex plane mandel = false; // false if painting Julia Set, true if Mandelbrot Set. draw = true; // To tell the application to pause or continue drawing, its switched by // pressing the right click. while (App.isOpen()) { sf::Event Event; while (App.pollEvent(Event)) { // SFML works with an event loop if (Event.type == sf::Event::Closed){ // If the window is closed, close the application App.close(); } if( Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Left){ // If the left mouse is pressed and released, close the application App.close(); } if( Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Right){ // If the right mouse is pressed and released, toggle randomness. draw = !draw; } } App.clear(); if(!draw) continue; // If false, then stop animating and freeze in the last generated frame. resolve(); //radialScan(); horizontalScan(); mandelb.setColor(sf::Color(cx[0], cx[1], cx[2])); // Shift the image hue. App.draw(mandelb); App.display(); } return EXIT_SUCCESS; }
//initialize muparser and graphics void init() { p.DefineVar("theta", &t); p.DefineConst("pi", pi); graph.create(size,size,sf::Color::Transparent); graphTx.loadFromImage(graph); graphSpr.setTexture(graphTx); //center on screen graphSpr.setOrigin(size/2,size/2); graphSpr.setPosition(windowsize.x/2, windowsize.y/2); }
void configure( const std::string& jsonPath ) { mappings.clear(); std::ifstream schemaFile; // std::ifstream::failure schemaFile.exceptions( std::ios::failbit | std::ios::badbit ); schemaFile.open( jsonPath ); Json::Value schema; Json::Reader reader; if( !reader.parse( schemaFile, schema ) ) { throw CannotLoadFileException(); } // Create a base image on which to overlay existing images Json::Value baseProps = schema[ "base" ]; Json::Value components = schema[ "mappings" ]; // Dispose of any old image base = sf::Image(); if( baseProps[ "image" ].isString() ) { if( !base.loadFromFile( baseProps[ "image" ].asString() ) ) { throw CannotLoadFileException(); } } else { base.create( baseProps[ "width" ].asInt(), baseProps[ "height" ].asInt() ); } // Load all components into mappings for( Json::Value::iterator jsonIterator = components.begin(); jsonIterator != components.end(); ++jsonIterator ) { std::string key = jsonIterator.key().asString(); Json::Value value = *jsonIterator; mappings[ key ] = AtlasMapping{ ( unsigned int ) value[ "x" ].asInt(), ( unsigned int ) value[ "y" ].asInt(), ( unsigned int ) value[ "width" ].asInt(), ( unsigned int ) value[ "height" ].asInt(), "" }; } }
void FractalVis::drawFrame(sf::Texture& screen) { frame.create(256, 256, &(*colors1DUint8)); //set the Image frame to the known display array frame.setPixel(128, 128, sf::Color::Yellow); //put a dot in the center screen.loadFromImage(frame); //display the image };
Tile() : map_x(0), map_y(0) { image.create(Tile::WIDTH, Tile::HEIGHT); texture.create(Tile::WIDTH, Tile::HEIGHT); sprite.setTexture(texture); }