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

Pages: 1 [2] 3 4
16
Graphics / Re: Pure black causes flickering when moving view?
« on: August 09, 2016, 01:05:37 pm »
Yes it's stuttering. I'll take a look to Kairos. Thanks.

17
Graphics / Re: Pure black causes flickering when moving view?
« on: August 08, 2016, 05:44:17 pm »
I've used your library for TileMap and using smoothscroll it solves the flickering but the slowdowns are there in both computers i'm using.

18
Graphics / Re: Pure black causes flickering when moving view?
« on: August 06, 2016, 11:46:56 pm »
Ralentization it's slowdown in spanglish.  :)

19
Graphics / Re: Pure black causes flickering when moving view?
« on: August 06, 2016, 10:43:23 pm »
Thank you, didn't know that. I quit the framerate checking and i keep with vsync activated.

I can see the view movement without flickering checking the best fullscreenmode and adapting the view dividing by an integer value. In my case the best screen size is 1920 x 1080 and the view is divided by 6: 320 x 180. It moves with a little ralentization each 20 seconds more or less. For me it's not acceptable that ralentization for a minimum example.

If I have to use different screen sizes, that makes imposible to fit the view to a multiple integer values in order to avoid artifacts. In other computer the best screen mode is 1366 x 768 then the 320 x 180 view causes artifacts.

I don't know how to make the game playable in different computers.


PD: The code is compiled with full optimization with Visual studio creating a release version.

20
Graphics / Re: Pure black causes flickering when moving view?
« on: August 06, 2016, 07:52:17 pm »
#include <SFML/Graphics.hpp>
#include <iostream>
#include <ctime>

class Map : public sf::Drawable, sf::Transformable
{
public:
        Map() { tileset_texture.loadFromFile("tilesets/tileset_01.png"); loadTileMap(); }
        void loadTileMap();

        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
               
                states.transform *= getTransform();
                states.texture = &tileset_texture;
                target.draw(tilemap, states);
               
        }

private:
        sf::VertexArray tilemap;
        sf::Texture tileset_texture;
        sf::RenderTexture render_texture;
        sf::RenderStates states;
};

void Map::loadTileMap()
{

        std::vector<int> tiles = { 1, 2, 3, 4, 8, 3, 3, 3, 4, 3, 1, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 135, 135, 135, 135, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 198, 199, 200, 3, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 277, 278, 277, 278, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 3, 4, 3, 3, 3, 3, 4, 3, 4, 3,3, 3 ,3, 2, 2, 2, 2, 2,
                1, 2, 3, 4, 3, 3, 3, 3, 4, 3, 4, 3,3, 3 ,3, 2, 2, 2, 2, 2,
                10, 10, 10, 10, 10, 3, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 6, 6, 6, 6, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 67, 67, 67, 67, 3, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 11, 11, 11, 11, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 3, 4, 3, 3, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2,
                1, 2, 3, 4, 3, 3, 3, 3, 4, 3, 4, 1,1, 1 ,1, 2, 2, 2, 2, 2 };


        unsigned int width = 21;
        unsigned int height = 12;

        sf::Vector2u tileSize(16, 16);

        tilemap.setPrimitiveType(sf::Quads);
        tilemap.resize(width * height * 4); // Each tile have 4 vertex

        for (unsigned int i = 0; i < width; ++i)
                for (unsigned int j = 0; j < height; ++j)
                {
                        // get the current tile number
                        int tileNumber = tiles[i + j * width];

                        // find its position in the tileset texture
                        int tu = tileNumber % (tileset_texture.getSize().x / 16);
                        int tv = tileNumber / (tileset_texture.getSize().x / 16);

                        // get a pointer to the current tile's quad
                        sf::Vertex* quad = &tilemap[(i + j * width) * 4];

                        // define its 4 corners
                        quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                        quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                        quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                        quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                        // define its 4 texture coordinates
                        quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                        quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                        quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                        quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                }

}


class Level
{
public:
        Level() { rectangle.setFillColor(sf::Color::Blue); rectangle.setSize(sf::Vector2f(30, 30));  }
        void render(sf::RenderWindow &c_window) { c_window.draw(map); c_window.draw(rectangle); }
       


private:
        sf::RectangleShape rectangle;
        Map map;
       
};


class GameApp
{

public:

        GameApp() : window(sf::VideoMode(800, 600), "SFML Graphic test", sf::Style::Fullscreen) { window.setVerticalSyncEnabled(true); view.setSize(200, 150); view.setCenter(100, 75); window.setView(view); }
        sf::Clock clock;
        sf::Time frame_time;

        void run()
        {
                while (!sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                {
                        frame_time = clock.restart();
                        frame_time += clock.getElapsedTime();

                        while (frame_time.asSeconds() < 1.f / FPS)
                        {
                                frame_time += clock.getElapsedTime();
                               
       
                        }

                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) view.move(1, 0);
                        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) view.move(-1, 0);
                        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) view.move(0, -1);
                        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) view.move(0, 1);

                        window.setView(view);  
                        render();
                }
        }

        void render() { window.clear(); level.render(window); window.display(); }

private:
        sf::RenderWindow window;
        Level level;
        sf::View view;
        const float FPS = 60.f;

};

int main()
{
        GameApp game_app;
        game_app.run();

        return 0;
}
 




Another issue is that my pc screen works at 30 hz interlazed by default and only looks ok when changing to 50 or 60hz not interlazed. The game run at 60Hz. I thought that this was managed by sfml.  Other games works in all frequencies.

¿I will need another library to detect the frecuencies of the screen and change it?


21
Graphics / Pure black causes flickering when moving view?
« on: August 06, 2016, 06:46:20 pm »
I was using pure black to draw tiles, i had problems with flickering and discovered that some tiles were flickering and other not (pure black ones). Then i changed the color and make it clearer and solved the issue.

My position and origins are all integers. The camera movement is in integer value.

In my laptop there is no problem with this color but in my Pc the problem exists.

22
Graphics / Re: How to detect in sfml that opengl driver fails?
« on: August 04, 2016, 12:50:05 pm »
Sorry i didn't explained myself correctly. The message told that hardware acceleration was not possible and vsync it's not possible, i think that could be the reason to not see the tilemap. I draw the vertexarray of each layer i want to draw into a sf::RenderTexture before drawing, but I see a black screen. Only the characters and text are showed. If I draw directly the vertxarray directly without using sf::RenderTexture it works but very slow and increasing cpu usage. The problem it's on the intel g41 graphics card.

I think that the error message is the reason of this issue.


The operating system it's windows 8.1 and it seems that the graphic card doesn't have driver support but 2 commercial games i played worked.

http://www.intel.com/content/www/us/en/support/graphics-drivers/000005526.html

Not sure what happens





I read this in sdl forums.

https://forums.libsdl.org/viewtopic.php?t=12014&sid=4e3df6ffcd258d5463eb4ae7ee6202af

Quote
urbo Sliders (http://www.turbosliders.com/) is my old indie project which I still sometimes update for a new version after players bombard me long enough with new feature requests. It is still using SDL 1.2 and I would really much not like to upgrade to 2.0 yet as I really don't have the time for that right now.

One known nasty bug currently is that for players with certain video cards - especially Intel's integrated ones (Intel G41 Express, Intel Q45/Q43 Express, Intel HD Graphics 5500) - if the game is in OpenGL mode (the default) and players Alt+Tab out of the game and back, the game doesn't work anymore. In the logs, I can see that glGetError keeps returning GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 after every operation.

Any ideas on what I should do? Players can use DirectDraw driver which works but with the horribly slow alpha blending ruining the game. With DD, there is manual texture reloading if blits start returning -2 after alt-tabbing but I understood that wouldn't be necessary with OpenGL? Is there something else I am missing or is OpenGL with SDL 1.2 inherently flawed?

Any ideas for quick fixes? Or is SDL2 the only way?

23
Graphics / [SOLVED] How to detect in sfml that opengl driver fails?
« on: August 03, 2016, 06:11:02 pm »
In intel g41 chipset my game is showing an error telling that "open gl cannot use vsync so i will see artifacts" I cannot access anymore to that computer so i cannot write the exact error message.

Something similar to this but not sure if is this message:

Quote
OpenGL extension SGIS_texture_edge_clamp unavailable
Artifacts may occur along texture edges
Ensure that hardware acceleration is enabled if available

I cannot use sf::RenderTextures in that computer and when i draw directily to the screen without render texture the cpu goes to 50% instead of 3%.

What can i do to detect this in my code and show the correct message for the player? By the moment the message is seen in the console.

The version of sfml is 2.3.2.


24



Look the black vertical lines in the red rectangle, they are bigger than the others.


There are some games that don't allow normal resizing, only to prefixed sizes like 800x600. Using multiples of my view solves the problem. But that forces me to use only a few sizes so doesn't allow custom sizes like other games.

I only need 3 sizes and the fullscreen mode, it's not a problem for me but i thing it's interesting to know the limitation.

25
What other result would you expect? Pixel is the base unit, you can't have one pixel stretched by a factor of x1.5, it is either x1 or x2.

What does it mean that?

Clicking to resize the window horizontally forces to choise between a multiple of the view like 1280x960 or 768x576? I use a 256 x 192 view. Using that sizes works.

If I'm right I have to avoid the mouse resizing option and doing it manually with an option inside the game. Using in the constructor of the window this styles:

window(game_screen_size, "Game", sf::Style::Close | sf::Style::Titlebar)

Another option is to use the sf::Event::Resized to control the window resizing calculating the size correctly.

26
This graphics are ok, all pixels have the same size.





Pixels with different sizes. It is caused when changing the window size horizontally or vertically. It happens resizing clicking on the windoiw borders and also resizing manually inside rezize event.




I've found that only works fine with this configuration.

window.setSize(1024, 768);
view.setSize(256, 192):


Smooth it's not good in a pixelated retro game.

27
Graphics / Graphics Glitch depending on game view and screen size
« on: May 09, 2016, 01:23:21 am »
The glitch is  pixels not stretching proportionally. The only way i found to avoid the issue it's to use view size thar are multiple of the screen size. For example:

window.setSize(1024, 768);
view.setSize(256, 192)

In this case the window is multiple of four. Other example is:

window.setSize(800, 600);
view.setSize(200, 150)

I'm using integer values in the view position.

28
Finally I solved the tearing problem. Now I don't need the render texture and do the double buffering. The solution was to not use decimals in the setPosition. The collision problem was in slope moving but using floating points in this movements don't cause tearing. Not using double buffer consumes less cpu and I prefer that.

void Movement::moveNowInteger(sf::Vector2f n)
{
        if (n.x > 0) process_move_right += n.x;
        if (n.x < 0) process_move_left += (-n.x);
        if (n.y > 0) process_move_down += n.y;
        if (n.y < 0) process_move_up += (-n.y);
       

        if (process_move_right > 1.f)
        {
                moveNow(sf::Vector2f(std::floor(process_move_right), 0.f));
                process_move_right -= std::floor(process_move_right);
        }

        if (process_move_left > 1.f)
        {
                moveNow(sf::Vector2f(-std::floor(process_move_left), 0.f));
                process_move_left -= std::floor(process_move_left);
        }

        if (process_move_down > 1.f)
        {
                moveNow(sf::Vector2f(0.f, std::floor(process_move_down)));
                process_move_down -= std::floor(process_move_down) ;
        }

        if (process_move_up > 1.f)
        {
                moveNow(sf::Vector2f(0.f, -std::floor(process_move_up)));
                process_move_up -= std::floor(process_move_up);
        }
}
 

29
Now I can mix the entities with the map render texture but only on the back of the map.

Just making: window.draw(*entity).

I need to render it between layers. By the moment if I draw between layers it draws on the back.


Here is where I create the render texture and draw it with the entities. There are 4 layers and entities are drawn in the second.

void Map::draw_layer(int layer_id,  sf::RenderWindow &window)
{
        if (tmx_info.num_layers >= layer_id)
        {
                sf::RenderStates states;
                states.texture = &map_layers[layer_id].texture;
                texture_map.draw(map_layers[layer_id].map_vertex_array, states);
              texture_map.display();

                sf::Sprite draw_map(texture_map.getTexture());
                window.draw(draw_map,);

                if (layer_id == 2)
                {
                        for (auto &j : World::current_level->getSceneVector())
                        {
                                assert(j != nullptr);
                                window.draw(*j);
                        }
                }
        }
}

 

Here it's where I display it. I draw everything but first the entities and later the map causing that I cannot insert between layers.


window.clear();

for (unsigned int i = 1; i <= current_level->getNumLayers(); i++)
{      
        map->draw_layer(i,  window);           
}
       
window.display();
 



30
I draw my entities to a sf::RenderTextures and it caused a "vibration effect". That is solved using std::floor in my moving functions. But this affects to my collision system, I want to avoid to use render textures to draw entities but keep the map as a sf::RenderTexture.

I'm drawing my map into a sf::RenderTexture because I was having tearing problems and that solved the issue. So it seems that I'm forced to draw my entities also in the render texture The problem it's that I use 5 map layers, entities are drawn in the third ¿There is a way to render my entities without using a sf::RenderTexture? Using normal draw without the render texture doesn't show my entities, only after the last layer is drawn.

I cannot draw the entities between layers, and if I use render texture it causes the vibration effect.

PD: Forum quotes aren't working. The code draws map and entites into the buffer and display it.

void Map::draw_layer(sf::RenderTarget &target, int layer_id)
{
        if (tmx_info.num_layers >= layer_id)
        {
                sf::RenderStates states;
                states.texture = &map_layers[layer_id].texture;

                if (layer_id == 2)
                {
                        for (auto j : World::current_level->getSceneVector())
                        {
                                assert(j != nullptr);
                                texture_map.draw(*j);                  
                        }
                }

                texture_map.draw(map_layers[layer_id].entity_vertex, states);
                texture_map.display();
                sf::Sprite draw_map(texture_map.getTexture());
                target.draw(draw_map);
        }      
}
 

Pages: 1 [2] 3 4