16
Feature requests / Request getVerticalSyncEnabled()
« on: March 15, 2012, 07:59:37 am »
Title says it all. ;-)
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.
#include <SFML/Graphics.hpp>
class Singleton {
public:
static void instanciate() {
instance.reset( new Singleton );
}
private:
static std::tr1::shared_ptr<Singleton> instance;
sf::Texture texture;
};
std::tr1::shared_ptr<Singleton> Singleton::instance;
int main() {
Singleton::instanciate();
return 0;
}
#include <SFML/Graphics.hpp>
#include <vector>
#include <ctime>
#include <cmath>
#include <iostream>
static const std::size_t NUM_TEXTURES = 4;
static const unsigned int TEXTURE_SIZE = 128;
static const std::size_t NUM_STARS_PER_TEXTURE = 20;
static const std::size_t NUM_LAYERS = 6;
static const float SPEED = 150.0f;
static const float SLOWDOWN_FACTOR = 0.5f;
static const float Y_SHIFT = 15.0f;
static const unsigned int COLOR_SHIFT = 40;
static const unsigned int SCREEN_WIDTH = 800;
static const unsigned int SCREEN_HEIGHT = 600;
struct Layer {
float speed;
sf::Vector2f offset;
std::size_t texture_id;
};
typedef std::vector<sf::Texture> TextureArray;
typedef std::vector<Layer> LayerArray;
int main() {
sf::RenderWindow window( sf::VideoMode( SCREEN_WIDTH, SCREEN_HEIGHT ), "Stars example" );
window.SetFramerateLimit( 60 );
// Init randomizer.
std::srand( static_cast<unsigned int>( std::time( 0 ) ) );
// Prepare textures.
TextureArray textures( NUM_TEXTURES );
for( std::size_t texture_id = 0; texture_id < NUM_TEXTURES; ++texture_id ) {
sf::Image image;
image.Create( TEXTURE_SIZE, TEXTURE_SIZE, sf::Color::Black );
// Set stars.
for( std::size_t star_id = 0; star_id < NUM_STARS_PER_TEXTURE; ++star_id ) {
sf::Vector2<unsigned int> star_pos(
std::rand() % TEXTURE_SIZE,
std::rand() % TEXTURE_SIZE
);
image.SetPixel( star_pos.x, star_pos.y, sf::Color::White );
image.CreateMaskFromColor( sf::Color::Black );
}
textures[texture_id].LoadFromImage( image );
}
// Prepare layers.
LayerArray layers( NUM_LAYERS );
for( std::size_t layer_id = 0; layer_id < NUM_LAYERS; ++layer_id ) {
layers[layer_id].offset = sf::Vector2f( 0, static_cast<float>( layer_id ) * Y_SHIFT );
layers[layer_id].speed = SPEED / static_cast<float>( layer_id + 1 ) * SLOWDOWN_FACTOR;
layers[layer_id].texture_id = layer_id % NUM_TEXTURES;
}
sf::Event event;
while( window.IsOpened() ) {
while( window.PollEvent( event ) ) {
if( event.Type == sf::Event::Closed ) {
window.Close();
}
}
float frame_time( static_cast<float>( window.GetFrameTime() ) / 1000.0f );
window.Clear();
// Update offsets and render.
for( int layer_id = NUM_LAYERS - 1; layer_id >= 0; --layer_id ) {
layers[layer_id].offset.x += layers[layer_id].speed * frame_time;
while( layers[layer_id].offset.x >= static_cast<float>( TEXTURE_SIZE ) ) {
layers[layer_id].offset.x -= static_cast<float>( TEXTURE_SIZE );
layers[layer_id].texture_id =
(
layers[layer_id].texture_id +
static_cast<std::size_t>( std::ceil( (static_cast<float>( SCREEN_HEIGHT ) + layers[layer_id].offset.y) / static_cast<float>( TEXTURE_SIZE ) ) ) +
1
) % NUM_TEXTURES
;
}
static std::size_t texture_id;
static sf::Vector2f target_pos;
static sf::Sprite sprite;
// Init initial texture ID and color.
texture_id = layers[layer_id].texture_id;
sprite.SetColor(
sf::Color(
static_cast<sf::Uint8>( 255 - layer_id * COLOR_SHIFT ),
static_cast<sf::Uint8>( 255 - layer_id * COLOR_SHIFT ),
static_cast<sf::Uint8>( 255 - layer_id * COLOR_SHIFT )
)
);
for( target_pos.x = -layers[layer_id].offset.x; target_pos.x < static_cast<float>( SCREEN_WIDTH + TEXTURE_SIZE ); target_pos.x += static_cast<float>( TEXTURE_SIZE ) ) {
for( target_pos.y = -layers[layer_id].offset.y; target_pos.y < static_cast<float>( SCREEN_HEIGHT + TEXTURE_SIZE ); target_pos.y += static_cast<float>( TEXTURE_SIZE ) ) {
sprite.SetTexture( textures[texture_id], true );
sprite.SetPosition( target_pos );
window.Draw( sprite );
texture_id = (texture_id + 1) % NUM_TEXTURES;
}
}
}
window.Display();
}
}
#include <SFML/Graphics.hpp>
#include <iostream>
int main() {
sf::RenderWindow window( sf::VideoMode( 800, 600, 16 ), "Minimal" );
sf::Event event;
const sf::Input& input( window.GetInput() );
unsigned char print_count( 0 );
window.EnableVerticalSync( true );
while( window.IsOpened() ) {
while( window.PollEvent( event ) ) {
if( event.Type == sf::Event::Closed ) {
window.Close();
}
}
// Get mouse movement delta values.
sf::Vector2i mouse_delta(
input.GetMouseX() - (800 / 2),
input.GetMouseY() - (600 / 2)
);
if( mouse_delta.x || mouse_delta.y ) {
print_count = 2;
// Reset mouse cursor to window center (fake grabbing).
window.SetCursorPosition( 800 / 2, 600 / 2 );
}
// Print 'em.
if( print_count ) {
std::cout << mouse_delta.x << ", " << mouse_delta.y << std::endl;
--print_count;
}
window.Clear();
window.Display();
}
}
Suited for the industry... Not to a 100%... Got real world examples.
Legal issues are a pain. Massive Entertainment got sued for using a Open-Source implementation of Python.
Most companies lawyers start to cold-sweat if you mention Open-Source. Several game studios has been and will be screwed by the Open Source resulting in fee's much more expensive than just buying something properly licensed.
Also several Open Source projects are not stable enough for the industry or even the public.
OOo is a classical example.
Something else would be Open-Source IDE. Most things you find out there does not cut it for at least the Game Development Industry. Also the support for it is not as good as something you pay for.
Open-Source projects are mostly maintained by hobbyists, nonprofessionals, and people who have studied the field but never actually practiced it. *aerhm* my previous teacher *aerhm*. I'm no exception to this rule. I like Open Source, I support the concept. But as the community is now, it can't compete with the non-open-source world.
To quote Niklas Hansson (former Lead Developer at Massive Entertainment): Open Source has it's rare diamonds, but most of it is garbage.
Have you used an IDE like Code::Blocks or kdevelop? In my opinion, Code::Blocks is just as good as Visual Studio (with the added benefit that it runs on Linux, Mac, whatever), and kdevelop is massively better (although harder to use, once you get used to it, it's waay better).
I do give that closed-source software is generally easier to use for the average user though, but to say "has its rare diamonds, but most of it is garbage" is a very misleading (if probably true) statement. Because there are sooooo many open source projects, and maybe 10% of them aren't garbage, which means there are many, many good open source projects. Sure, they aren't always so easy to find.
Apparently you haven't worked that much with Visual Studio. There's nothing on the market that beats it's debugger interface.
Just like they did with their Office package.
sf::Shape line( sf::Shape::Line( 0.f, 0.f, 0.f, 100.f, 1.f, sf::Color( 255, 255, 0 ) );