Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Akrotrili

Pages: [1]
1
Window / [Solved] RenderWindow - Stack Overflow
« on: August 28, 2013, 02:04:07 am »
Hey there,

I just made a little program using the sieve of Eratosthenes to create an image which show if a number is prime or not (just like that).

It works just fine, but if the size of the window is over 498*498. There's a stack overflow, the error is supposed to be on the 16th line (where I'm creating the window).

Using SFML 2.1, and working with Visual Studio 2012.

Here's the source code :
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>

#include <cmath>

#define WIDTH 500
#define HEIGHT 500
#define MAX WIDTH*HEIGHT
#define SCALE 1

int WinMain()
{
   sf::RenderWindow window(sf::VideoMode(WIDTH*SCALE, HEIGHT*SCALE), "Primes");
      window.setVerticalSyncEnabled(true);

   sf::Event event;

   sf::Image image;
      image.create(WIDTH, HEIGHT);

   sf::Texture texture;
      texture.create(WIDTH, HEIGHT);

   sf::Sprite sprite;
      sprite.setTexture(texture);
      sprite.setScale(SCALE, SCALE);
     
   unsigned int numbers[MAX], primeBase = 2;
   
   // Initializing the array
   for(size_t i = 0 ; i < MAX ; ++i)
        numbers[i] = i+1;
   
   // Finding primes
   while(primeBase < sqrt(MAX))
   {
      // Replacing non-primes by 0
      for(size_t i = primeBase ; i*primeBase <= MAX ; ++i)
         numbers[i*primeBase-1] = 0;

      // Changing the value of primeBase
      for(size_t i = primeBase ; i < MAX ; ++i)
      {
         if(numbers[i] != 0)
         {
            primeBase = numbers[i];
            break;
         }
      }
   }
   
   // Creating the image
   for(size_t i = 0 ; i < MAX ; ++i)
   {
      if(numbers[i] > 1)
         image.setPixel(i%WIDTH, i/WIDTH, sf::Color::Green);
   }

   texture.update(image);
   
   // Main loop
   while(window.isOpen())
   {
      // Event loop
      while(window.pollEvent(event))
      {
         if(event.type == sf::Event::Closed)
            window.close();
      }

      // Displaying the image
      window.clear();
      window.draw(sprite);
      window.display();
   }
}

Thank you for the help. \o

2
SFML projects / [SFML Game Jam #1] Horton's Odyssey
« on: August 05, 2013, 08:44:46 pm »
Yo,

Here's the game that piticroissant and me developped during this first SFML Game Jam about "Lights and Shadows". It's a platformer, mostly inspired by Super Meat Boy.

We used SFML 2.1 and Box2D to create the game. And for the moment it's not available on Linux, but Lo-X told me that it works fine with Wine.

We will improve the game, because there are a lot of things we couldn't add or change due to delays. So we'd like to know you remarks/bugs.

Download Horton's Odyssey (.7z - 5.48 Mo)
Source code of the game (.7z - 22.6 Ko)

Some screenshots:



We hope you'll like it. :D

Pages: [1]
anything