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

Pages: 1 2 [3]
31
Window / Re: [SOLVED] How to know if sprite is in view
« on: January 17, 2017, 07:12:59 pm »
FloatRects can also be constructed using a couple Vector2fs, which can make your usage even simpler with something like:
bool Sector::lightInView(sf::FloatRect spriteAABB)
{
        // these are both float vectors
        sf::Vector2f viewCenter(Game::GetWindow()->getView().getCenter());
        sf::Vector2f viewSize(Game::GetWindow()->getView().getSize());

        sf::FloatRect currentViewRect(viewCenter - viewSize / 2.f, viewSize);

        return (spriteAABB.intersects(currentViewRect));
}

You are right, I was converting sf::Vector2f to sf::Vector2i for no reason. Thanks. Cleaner code  :)

32
Window / Re: How to know if sprite is in view
« on: January 11, 2017, 08:28:32 pm »
Thanks eXpl0it3r! Solved! Here is the final code:

bool Sector::lightInView(sf::FloatRect spriteAABB)
{
        sf::Vector2i viewCenter(Game::GetWindow()->getView().getCenter()); // this returns the center of the view IN THE WORLD!
        sf::Vector2i viewSize(Game::GetWindow()->getView().getSize());

        sf::FloatRect currentViewRect
                (viewCenter.x - viewSize.x / 2, // left
                viewCenter.y - viewSize.y / 2, // top
                viewSize.x,
                viewSize.y);

        return (spriteAABB.intersects(currentViewRect));
}

Basically, as you said, I didn't understand what getCenter() returned. Also I was wrongly creating the FloatRect of the view (height and width was wrong).
The tutorial is great, thanks!

33
Window / [SOLVED] How to know if sprite is in view
« on: January 10, 2017, 11:28:58 pm »
Hi Guys, I'm having trouble trying to know if a sprite is inside the current view, this is my code:

bool Sector::lightInView(sf::FloatRect spriteAABB)
{
        sf::Vector2i viewCenter(Game::GetWindow()->getView().getCenter()); // global coords, right?
        sf::Vector2i viewSize(Game::GetWindow()->getView().getSize());  // in this case: 1680x1050
       
        // create the view Rect, are the -/+ ok?
        sf::FloatRect currentViewRect
                (viewCenter.x - viewSize.x / 2,
                viewCenter.y + viewSize.y / 2,
                viewCenter.x + viewSize.x / 2,
                viewCenter.y - viewSize.y / 2);

        // check if the sprite is in view
        return (spriteAABB.intersects(currentViewRect));
}

This isn't working, I know because the sprites are lights that I only draw when they are in view. They won't draw or draw when not in view, etc.
I'm having trouble understanding the coordinates system, it's probably an issue with that.

34
SFML projects / Re: Let There Be Light 2
« on: October 30, 2016, 01:02:05 am »
Cmdu76 I'm trying to use your version but I'm getting these errors:

(click to show/hide)

What do I have to do? :/

I also tried the original version but I can't compile that one either because make_unique and other c++14 stuff isn't supported on my compiler

Maybe you should rebuild the entire solution, VS might not have recognized that you changed some files.

35
SFML projects / Re: Let There Be Light 2
« on: September 25, 2016, 07:46:08 pm »
Thanks Cmdu76! I've been using LTBL2 for some time now ( video: [EDIT: new better video] ) It's great, the main problem I have is the performance though. I'm going to try your version and give you some feedback.

36
SFML projects / Re: Let There Be Light 2
« on: August 15, 2015, 08:50:09 pm »
Am I missing something?

You need to set the position of lightSprite when you move the camera.
lightSprite.setPosition(view.getCenter());
You will also need to set the sprite's origin so that the center of the sprite matches the center of he view.
lightSprite.setOrigin(view.getSize().x / 2.0f, view.getSize().y / 2.0f);
Do this before running the game.

Thanks! It is working now. LTBL2 is great :D

And this code compiles just fine. However, if I add any type of ltbl object (such as ltbl::LightSystem) anywhere in the code, the compiler just gives me three LNK2001 errors.

How do I fix this?

You need to add all cpp files of LTBL2 (those on /lighting, those on /quadtree and Math.cpp) to your project, you don't need to add anything to the Linker part, just to the C/C++ part "Additional Include Directories: C:\Users\Me\Desktop\Main\LTBL2-master\LTBL2\source\" as you did.

37
SFML projects / Re: Let There Be Light 2
« on: August 05, 2015, 12:07:38 am »
Hello,

Calling ls.render only renders the lights to an internal texture. You must then render the internal texture after calling ls.render. You can do this with ls.getLightingTexture. Make sure that the blending is set to multiplicative before you draw it on top of your scene!

Hey Lolz, thanks for the answer, I've been able to render lights like this:

Code: [Select]
lightSystem.render(Game::GetWindow().getView(), unshadowShader, lightOverShapeShader);

lightsSprite.setTexture(lightSystem.getLightingTexture());
Game::GetWindow().draw(lightsSprite, sf::BlendMultiply);

and works good except it doesn't update the view when I move my player (even when I'm passing it to the render()), you can see this on the right of the screen capture attached (don't mind the crappy graphics, they are temporary  :P).

Am I missing something?

38
SFML projects / Re: Let There Be Light 2
« on: July 21, 2015, 04:22:42 am »
Thanks Glosa, I'm using those textures but still not showing any light.

Lolz, it would be nice to see the source code of the demo so we can see how exactly to use this. I'm creating light and then drawing it with Nrender but nothing happens  :-\

Cmake generated without errors, the sln compiled without problems and this is my code:

Sector.h:
Code: [Select]
...

#include <ltbl/lighting/LightSystem.h>

class Sector
{
public:
Sector(int mapNumber, int sectorNumber);
~Sector();
        ...

private:
...

ltbl::LightSystem ls;
sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;
};

Sector.cpp (Constructor):
Code: [Select]
Sector::Sector(int mapNumber, int sectorNumber)
: static_objects_counter(0), enemies_counter(0), pickup_counter(0), _name(NumberToStr(sectorNumber))
{
belongsToMapNumber = mapNumber;

enemies.clear();
enemiesToRemove.clear();

unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");

sf::Texture penumbraTexture;
penumbraTexture.loadFromFile("resources/penumbraTexture.png");
penumbraTexture.setSmooth(true);

ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), Game::GetWindow().getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

// Below is an example for creating one point light and one directional light:
std::shared_ptr<ltbl::LightPointEmission> plight = std::make_shared<ltbl::LightPointEmission>();

sf::Texture pointLightTexture;
pointLightTexture.loadFromFile("resources/pointLightTexture.png");
pointLightTexture.setSmooth(true);

plight->_emissionSprite.setOrigin(sf::Vector2f(0.f, 0.f));
plight->_emissionSprite.setTexture(pointLightTexture);
plight->_emissionSprite.setColor(sf::Color::Blue);
plight->_emissionSprite.setPosition(sf::Vector2f(100, 100));
plight->_localCastCenter = sf::Vector2f(0.f, 0.f); // This is where the shadows emanate from relative to the sprite

ls.addLight(plight);

std::shared_ptr<ltbl::LightDirectionEmission> dlight = std::make_shared<ltbl::LightDirectionEmission>();

sf::Texture directionLightTexture;
directionLightTexture.loadFromFile("resources/directionLightTexture.png");
directionLightTexture.setSmooth(true);

dlight->_emissionSprite.setTexture(directionLightTexture);
dlight->_castDirection = sf::Vector2f(10.f, 10.f);

ls.addLight(dlight);
}

Sector.cpp (update):
Code: [Select]
void Sector::update(sf::Time timeElapsedSinceLastUpdate)
{
        ...

ls.render(Game::GetWindow().getView(), unshadowShader, lightOverShapeShader);
}

Textures and shaders load fine (I checked), update is called, render is called, I'm not drawing the map over the lights, so I don't know what is the problem, any ideas?

39
SFML projects / Re: Let There Be Light 2
« on: July 15, 2015, 03:57:51 pm »
Hey lolz123, nice demo! I would like to use this for my game, I was able to compile and add to my project but I'm having some troubles:

This is my code for the creation of a light (to test):

Quote
   // lights setup
   sf::Shader unshadowShader;
   sf::Shader lightOverShapeShader;
   unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
   lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");
   sf::Texture penumbraTexture;
   penumbraTexture.loadFromFile("resources/penumbraTexture.png");
   penumbraTexture.setSmooth(true);

   ltbl::LightSystem ls;
   ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), Game::GetWindow().getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

   std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

   light->_emissionSprite.setTexture(penumbraTexture);
   light->_castDirection = sf::Vector2f(25.f, 25.f);

   ls.addLight(light);

That's all I do and the light won't show, am I missing something? Maybe a call to draw every frame to show the light?

I followed your quick start (https://github.com/222464/LTBL2), I don't understand which texture I have to use in this line "light->_emissionSprite.setTexture(penumbraTexture);" one of your textures?

40
Graphics / Re: 8x8 tiles and big map, bad idea?
« on: June 25, 2015, 09:24:15 pm »
oops, my bad those are not called, this one is called:

Quote
void MapLoader::draw(sf::RenderTarget& rt, sf::RenderStates states) const
{
   sf::View view  = rt.getView();
   if(view.getCenter() != m_lastViewPos)
   {
      sf::FloatRect bounds;
      bounds.left = view.getCenter().x - (view.getSize().x / 2.f);
      bounds.top = view.getCenter().y - (view.getSize().y / 2.f);
      bounds.width = view.getSize().x;
      bounds.height = view.getSize().y;

      //add a tile border to prevent gaps appearing
      bounds.left -= static_cast<float>(m_tileWidth);
      bounds.top -= static_cast<float>(m_tileHeight);
      bounds.width += static_cast<float>(m_tileWidth * 2);
      bounds.height += static_cast<float>(m_tileHeight * 2);
      m_bounds = bounds;
   }
   m_lastViewPos = view.getCenter();

   for(auto& layer : m_layers)
      rt.draw(layer);
}

rt.draw(layer) is called 3 times, one for each layer I made on Tiled.

It might not be the draw calls. It could be your logical transformations. Are you altering each tile every frame (even if they stay the same)?

I think I'm not doing that, maybe the MapLoader is but I've been investigating the code and it doesn't seem to be doing any extra processing on the tiles, here it is the entire code (https://github.com/fallahn/sfml-tmxloader) and here it is the MapLoaderPrivate.cpp where the draw fuction is (https://github.com/fallahn/sfml-tmxloader/blob/master/src/MapLoaderPrivate.cpp)


EDIT: This is it!
On MapLayer.cpp:
Quote
void LayerSet::draw(sf::RenderTarget& rt, sf::RenderStates states) const
{
   for(auto& q : m_quads)
   {
      if(q->m_needsUpdate)
      {
         for(auto& i : q->m_indices)
         {
            m_vertices.position += q->m_movement;
         }
         q->m_needsUpdate = false;
      }
   }
   
   if(!m_vertices.empty() && m_visible)
   {
      states.texture = &m_texture;
      rt.draw(&m_vertices[0], static_cast<unsigned int>(m_vertices.size()), sf::Quads, states);
   }
}

Renderer would check *every* TileQuad each frame for any updates. This is corrected on the last update of April 2015 (here: http://trederia.blogspot.co.uk/2015/04/tmx-loader-for-sfml-update.html)

Thanks for the help!  ;)

41
Graphics / Re: 8x8 tiles and big map, bad idea?
« on: June 25, 2015, 08:57:31 pm »
Thanks all, I'm using this Tiled Map Editor to SFML/Box2D converter (http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.html) and apparently it uses Vertex Arrays to draw as seen here:

Quote
void MapLoader::Draw(sf::RenderTarget& rt, MapLayer::DrawType type, bool debug)
{
   m_SetDrawingBounds(rt.getView());
   switch(type)
   {
   default:
   case MapLayer::All:
      for(const auto& l : m_layers)
         rt.draw(l);
      break;
   case MapLayer::Back:
      {
      //remember front of vector actually draws furthest back
      MapLayer& layer = m_layers.front();
      m_DrawLayer(rt, layer, debug);
      }
      break;
   case MapLayer::Front:
      {
      MapLayer& layer = m_layers.back();
      m_DrawLayer(rt, layer, debug);
      }
      break;
   case MapLayer::Debug:
      for(auto layer : m_layers)
      {
         if(layer.type == ObjectGroup)
         {
            for(const auto& object : layer.objects)
               if (m_bounds.intersects(object.GetAABB()))
                  object.DrawDebugShape(rt);
         }
      }
      rt.draw(m_gridVertices);
      rt.draw(m_rootNode);
      break;
   }
}

void MapLoader::Draw(sf::RenderTarget& rt, sf::Uint16 index, bool debug)
{
   m_SetDrawingBounds(rt.getView());
   m_DrawLayer(rt, m_layers[index], debug);
}

Lines rt.draw(m_gridVertices); rt.draw(m_rootNode); and m_DrawLayer(rt, m_layers[index], debug); are called once.

I asked the creator anyway to make sure, he didn't answer yet.

So the problem might not be that? I'm confused here because when using less and bigger tiles it works fine  :o

42
Graphics / 8x8 tiles and big map, bad idea? [Solved]
« on: June 25, 2015, 05:22:25 am »
Hi, I've been working with SFML for some months now and some weeks ago I started to do the tileset for my game. I began by making 64x64 tiles and everything was working fine but now I need to do 8x8 tiles so I can create very detailed figures, but with tiles this small I need to do big maps, something like 300 * 120 tiles which gives a total of 36000 tiles!! of course this dropped my frames to a little bit more than 30 (before it was >200).

From what I know this 36000 tiles means 36000 calls to draw() which is expensive to the CPU, is that correct?

The question is: is there another way to do this or I need to go to bigger tile sizes?

It would be good to be able to use small tiles because I want to create circuits (like those of a motherboard), what I'm doing now is every tile is a small segment of a circuit (straight line, curve, circle, etc.) and I create different circuits with each segment.


Pages: 1 2 [3]