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.


Messages - sgehlich

Pages: [1]
1
Graphics / Upscaling pixel graphics: Force nearest neighbor method
« on: February 24, 2013, 10:37:00 am »
Hey,

right now I'm working on a 2D game in pixel style which has been designed for 400x300 pixels. Right now I'm scaling up all images to the actual screen size (right now that's 800x600), but SFML seems to automatically use bicubic or bilinear for resampling the image.

Is there a way to force SFML to just repeat the pixels so that it preserves the pixel style?

Here's the current code for my drawing:
https://gist.github.com/saschagehlich/ea934f7829b3055e47fe

Thanks,
Sascha

2
Graphics / Re: Scaled down sprite rendering
« on: August 29, 2012, 08:03:16 pm »
So I have to implement my own scaling algorithm, huh? Any recommendations on good and fast algorithms that are easy to implement?

3
Graphics / Re: Member function sprite call
« on: August 29, 2012, 03:11:42 pm »
Pass the window to your class and call window->draw(mySprite);, maybe? I'm pretty new to SFML, but that's kind of how I did it.

4
Graphics / Re: Scaled down sprite rendering
« on: August 29, 2012, 03:10:35 pm »

5
Graphics / Re: Scaled down sprite rendering
« on: August 29, 2012, 02:14:44 pm »
This is how it looks like with a scale of 1.0 (256x256 pixels)

[attachment deleted by admin]

6
Graphics / Scaled down sprite rendering
« on: August 29, 2012, 01:02:16 pm »
Hey,

This is the Screen class I use for rendering Sprites from a Spritesheet (given a source rect and a destination rect)

#include "Screen.hpp"
#include "ResourcePath.hpp"

Screen::Screen(sf::RenderWindow* window) {
    _mainWindow = window;
   
    // Load spritesheet
    if(!spriteSheet.loadFromFile(resourcePath() + "sprites.png")) {
        throw "We failed at loading the sprites.";
    }
   
    spriteSheet.setSmooth(true);
   
    sf::ContextSettings settings = _mainWindow->getSettings();
    printf("%d", settings.antialiasingLevel);
   
}

void Screen::render(sf::IntRect sourceRect, sf::IntRect destRect) {
    sf::Sprite sprite(spriteSheet);
    sprite.scale(1.0 / sourceRect.width * destRect.width, 1.0 / sourceRect.height * destRect.height);
    sprite.setTextureRect(sourceRect);
    sprite.setPosition(destRect.top, destRect.left);

    _mainWindow->draw(sprite);
}

void Screen::render(sf::IntRect sourceRect, sf::IntRect destRect, bool centered) {
    sf::Sprite sprite(spriteSheet);
   
    sprite.scale(1.0 / sourceRect.width * destRect.width, 1.0 / sourceRect.height * destRect.height);
    sprite.setTextureRect(sourceRect);
   
    if(centered)
        sprite.setOrigin(destRect.width / 2.0, destRect.height / 2.0);
   
    sprite.setPosition(destRect.left, destRect.top);
   
    _mainWindow->draw(sprite);
}

void Screen::clear() {
    _mainWindow->clear(sf::Color(13, 15, 30));
}

This works pretty fine when the source rect size equals the dest rect size or if the dest rect size is higher than the source rect size. But when I scale stuff down (e.g. sourceRect = 0,0,256,256  destRect = 0,0,50,50) it looks very pixelated (see Attachment).

I already tried setting sf::ContextSettings:antialiasingLevel for my renderWindow, that didn't change anything.

Is there a way to properly scale images down or is my approach of rendering sprites from a spritesheet / texture totally wrong?

[attachment deleted by admin]

Pages: [1]