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 - loubeasley

Pages: [1]
1
Graphics / Re: How to use shaders more efficiently in c++/sfml?
« on: September 11, 2016, 12:28:02 pm »
I just now noticed your reply. I appreciate it.

I am using Visual Studio 2015.

The console screen is very quick! I am impressed. I was able to get about 30 fps on a grid of 150x50 characters (7x12 pixels for each character) running the crash method on every iteration of the game loop.

It's kind of ironic how taxing using ASCII graphics can be if you aren't careful with all the nested loops.  :P

Thanks again! If I stick with SFML and C++, I will definitely be using this.

2
Graphics / Re: How to use shaders more efficiently in c++/sfml?
« on: September 03, 2016, 11:20:33 pm »
Can you possibly point me in the direction of how to build the library so I can link it in my project?

Edit: I was able to make it work by adding the entire library to my project working directory. However, I feel like this set up is kind of messy.

3
Graphics / Re: How to use shaders more efficiently in c++/sfml?
« on: September 03, 2016, 09:13:42 pm »
Thank you for the link. This is exactly what I'm trying to do. I will definitely try it out.   :)

4
Graphics / How to use shaders more efficiently in c++/sfml?
« on: September 03, 2016, 11:34:23 am »
I'm working on a sort of ascii canvas for a game. I assumed it would be more efficient to to use a spritesheet of ascii glyphs in cp437 style to draw the ascii art. I needed a way to color the background and foreground of the glyphs so I'm using a fragment shader. Using the shader drops me to 7 fps. Not using the shader, I get about 131.

Am I doing something incorrectly? Is it just too expensive to loop through a vector of strings (and each character in the string), calculate the position of the glyph on the sheet, set the texture position, and then draw the sprite with a shader for each character?

int main() {
        sf::RenderWindow renderWindow(sf::VideoMode(1280, 720), "Demo Game");
       
        sf::Texture texture;
        texture.loadFromFile("Resources/courier_8x16.png");
        texture.setSmooth(false);
        sf::Sprite sprite(texture);
        sf::Shader shader;
        m_shader.loadFromFile("cycle.frag", sf::Shader::Fragment);
        m_shader.setUniform("texture", sf::Shader::CurrentTexture);
       
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
       
        std::vector<std::string> chars = std::vector<std::string>(50, std::string(100, 'X'));
        while (renderWindow.isOpen())
        {
                processEvents();

                timeSinceLastUpdate += clock.restart();

                while (timeSinceLastUpdate > TimePerFrame)
                {
                       
                        timeSinceLastUpdate -= TimePerFrame;
                        processEvents();
                        update(TimePerFrame);
                }
               
                //render();
        renderWindow.clear();
                for (int y = 0; y < chars.size(); y++)
                {
                        for (int x = 0; x < chars[y].size(); x++)
                        {
                                //bg and fg colors will be in a 2D vector and used here
                                shader.setUniform("foreground", sf::Glsl::Vec4(std::Color.White));
                                shader.setUniform("background", sf::Glsl::Vec4(std::Color.Black));
                               
                                //uses decimal value of char and dimensions
                                //to find location of appropriate glyph in sprite sheet
                                sprite.setTextureRect(sf::IntRect((chars[y][x] % 16) * 8, (chars[y][x] / 16) * 16, 8, 16));
                                sprite.setPosition(x * 8, y * 16);
                               
                                renderWindow.draw(sprite, &shader);
                        }

                }
        renderWindow.display();
               
        }
       
       
}

shader code:

uniform vec4 foreground;
uniform vec4 background;
uniform sampler2D texture;



void main()
{
        vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
        if (pixel.r < .1)
                pixel = background;
        else
                pixel = foreground;
                               
        gl_FragColor = pixel;
}

Here's the sprite sheet: (all the paragraph symbols are just placeholders)


Pages: [1]
anything