Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Multiple problems facing me !!  (Read 1409 times)

0 Members and 1 Guest are viewing this topic.

flynet0013

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Multiple problems facing me !!
« on: September 03, 2018, 12:43:23 am »
Hey there i'm new to SFML and C++ , I had many problems while i'm learning sfml and i'm gonna list them :

First :
    Whenever i try to load a texture or any other resource on debug mode ,it always return false when i make
    if condition to check if res loaded or not :
   
     // Always return false on debug mode
     sf::Texture tx;
       
        if (!tx.loadFromFile("data/icon.jpeg"))
                return -1;
   
    but on release mode and without the condition it load and display on the screen without error :
   
     // Work on release mode
     sf::Texture tx;
       
      tx.loadFromFile("data/icon.jpeg");
   
     
Second :
    Whenever i use VertexArray (Quad,Triangles,TrianglesStrip) with texture always get white pixels on debug
    mode but on release mode i get nothing even LineStrips doesn't show up on release mode too !!
    Entity.cpp :
   
     void Entity::draw(sf::RenderTarget & target, sf::RenderStates states) const
{

                states.transform = this->m_trasform;
                states.texture = &this->m_texture;
                target.draw(this->m_vertexes, states);
        // Just to draw bounding box edges
        if (true) {
                sf::Vertex vert[5] = {
                        sf::Vertex(sf::Vector2f(this->m_boundingbox.x ,this->m_boundingbox.y)),
                        sf::Vertex(sf::Vector2f(this->m_boundingbox.x + this->m_boundingbox.width ,this-
  >m_boundingbox.y)),
                        sf::Vertex(sf::Vector2f(this->m_boundingbox.x + this->m_boundingbox.width ,this->m_boundingbox.y + this->m_boundingbox.height)),
                        sf::Vertex(sf::Vector2f(this->m_boundingbox.x ,this->m_boundingbox.y + this->m_boundingbox.height)),
                        sf::Vertex(sf::Vector2f(this->m_boundingbox.x ,this->m_boundingbox.y)),
                };

                vert[0].color = sf::Color::Red;
                vert[4].color = sf::Color::Blue;
                vert[2].color = sf::Color::Green;
                target.draw(vert, 5, sf::LinesStrip, states);
        }

};

Entity::Entity(std::string texture_file,Rect boundingBox ,float x, float y, float h, float w)
{
        this->m_boundingbox = Rect(boundingBox.x + x , boundingBox.y + y , boundingBox.height,boundingBox.width);

        isVisual = true;
        this->setPosition(x, y);

        this->m_texture.loadFromFile(texture_file);
               

        m_vertexes.setPrimitiveType(sf::Quads);
        m_vertexes.resize(w * h* 4);
        this->m_vertexes[0].position = sf::Vector2f(x,y);
        this->m_vertexes[1].position = sf::Vector2f(x + w, y);
        this->m_vertexes[2].position = sf::Vector2f(x + w, y + h);
        this->m_vertexes[3].position = sf::Vector2f(x , y + h);
       
        this->m_vertexes[0].texCoords = sf::Vector2f(0, 0);
        this->m_vertexes[1].texCoords = sf::Vector2f(w, 0);
        this->m_vertexes[1].texCoords = sf::Vector2f(w, h);
        this->m_vertexes[1].texCoords = sf::Vector2f(0, h);
       
}
     
     
      main.cpp :
     
      Entity e("data/icon.jpeg",Rect(0,0,400,500),50,50,100,200);
     
      // While loop
      window.draw(e);
     
     
Third :
     Sprite batch texture or imag get rendered on release mode but the opposite on debug i get nothing just
     blink window .

All my res  files are on correct directory stil getting the same problem , Also i love this Lib and i don't want to change it and another one ,i hope some one find a solution to this problem and thx  :-*

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: Multiple problems facing me !!
« Reply #1 on: September 04, 2018, 08:10:30 am »
I would recommend going back to the sfml configuration tutorial and meticulously checking every step of the way. If the problems only occur in debug mode it's likely that you made a mistake while configuring your project settings.

flynet0013

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Multiple problems facing me !!
« Reply #2 on: September 04, 2018, 01:53:36 pm »
I will try to do it again , thanks anyway for reply !!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10988
    • View Profile
    • development blog
    • Email
Re: Multiple problems facing me !!
« Reply #3 on: September 04, 2018, 03:23:09 pm »
#1
If resources can't be loaded, you get a error message on the console (or you can redirect sf::err()). Usually the cause is, that the working directory is not what you expect.

#2
You apply a texture to the line stripe via the state, so the texture is mapped to the lines and not colors are used. If you want to use colored lines (as you probably want for debug drawings), you shouldn't set a texture for the state.

#3
If the texture fails to load, you also won't see anything rendered.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything