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 - ineed.help

Pages: [1] 2 3 4
1
General / Re: stb_image
« on: August 11, 2014, 02:53:38 pm »
I did look it up, but I didn't understand it.

I do understand it now, though, so thank you for the help!

2
General / Re: stb_image
« on: August 11, 2014, 02:40:18 pm »
Oh, do you mean that the methods themselves can't be used outside of one file, but the stb_image.h file can be included by multiple files? That would make sense.

3
General / Re: stb_image
« on: August 11, 2014, 02:31:52 pm »
Quote
Read the stb_image.h documentation
Do you mean the one that's in the header file?

Quote
And no, SFML only includes stb_image.h in a single file. It's then encapsulated so that the rest of the code never has to know about it.
I don't understand how you could include it in only one file yet use it in several...

4
General / stb_image
« on: August 11, 2014, 02:18:07 pm »
I've been trying to use stb_image.h to load PNG files, and it works fine when including it in one .cpp file, but if I try to include it in a .hpp file to which another .cpp file is linked, I can't call the methods without getting a linker error.

I noticed that SFML is using this file for most of its image loading, which is why I posted this here, since I would assume that some of SFML's many header files use it (?). I apologize if this is the wrong category or I shouldn't have posted this here, but I would like to know how, if possible, I could "fix" this.

5
General / Re: Problem with character positioning
« on: July 25, 2014, 12:06:42 pm »
You mean like this?:

yPos = 0 - font.getGlyph('A', fontSize, false).bounds.top;
 
This seems to work for me; it places the "l", which is one of the longest characters, at the y-position it's supposed to.

With "getLocalBounds().top", I do it like this:
tempSprite.setPosition(xPos + font.getGlyph(str[i], fontSize, false).bounds.left, yPos + font.getGlyph(str[i], fontSize, false).bounds.top - tempSprite.getLocalBounds().top);
 
Yet it does absolutely nothing.

Well, I guess it doesn't matter, since I seem to have fixed everything.

6
General / Re: Problem with character positioning
« on: July 25, 2014, 11:05:36 am »
What do you mean by the "highest possible glyph"? Can I do something with the base y-position to correct this for all characters?

7
General / Re: Problem with character positioning
« on: July 25, 2014, 10:25:28 am »
All right, it works... mostly. How come it doesn't start at (0, 0)? This happens with sf::Text as well; if you set its position to (0, 0), the y-position is never at 0.

8
General / Re: Problem with character positioning
« on: July 24, 2014, 11:36:07 pm »
Thank you, I will check this out first thing in the morning (it's nearly midnight in my country).

(Also, I checked "findCharacterPos()", not "ensureGeometryUpdate()".)

9
General / Re: Problem with character positioning
« on: July 24, 2014, 10:34:45 pm »
I don't know how these forums work, if people only generally reply to the top topic or not, as this is the case in some other forums. I did not mean to be disrespectful. I am just an impatient person.

As I said earlier, the problem is not one that can be debugged; it doesn't work with "findCharacterPos()", because sf::Text doesn't do automatic line breaks like my program does. For this to work, I would have to create a sf::Text object, assign a line break every time the automatic line break occurs, and then use "findCharacterPos()", and I feel that this is a bit reduntant, which is why I am asking for help from those more experienced with SFML.

10
General / Re: Problem with character positioning
« on: July 24, 2014, 09:25:20 pm »
Anyone?

11
General / Re: Problem with character positioning
« on: July 24, 2014, 05:06:17 pm »
I have read it. I did as it said, too, in my previous code:

xPos += font.getKerning(prevChar, str[i], fontSize);
tempSprite.setPosition(xPos, yPos + font.getGlyph(str[i], fontSize, false).bounds.top + font.getGlyph(0, fontSize, false).bounds.height);
chars.push_back(tempSprite);
xPos += font.getGlyph(str[i], fontSize, false).advance;
prevChar = str[i];
 

As the source code says... Am I missing something?

12
General / Re: Problem with character positioning
« on: July 24, 2014, 03:18:59 pm »
... I don't understand; how am I supposed to use it? I understand if it's just one line, but with multiple lines, how would I go about doing that?

13
General / Problem with character positioning
« on: July 24, 2014, 01:43:46 pm »
Hello!

I have been working for quite a while now on a system to draw a series of sprite as if they were an sf::Text.
However, I recently took notice of a problem: if you look at this picture...

As you can see, there are some rather large gaps between some of the characters, and I don't quite understand why.
There is also a very large difference between the y-coordinates of the lines.
This is a sample of the code I have been using which contains my problem.

int main()
{
        sf::RenderWindow window(sf::VideoMode(360, 240, 32), "Title");
        sf::Font font;
        font.loadFromFile("fonts/font.ttf");
        std::vector<sf::Sprite> chars;
        sf::Sprite tempSprite;
        std::string str = "Hello! This is a string! This string is rather long, so it needs to be divided into multiple lines.";
        unsigned short xPos = 0, yPos = 0;
        unsigned char prevChar = 'A';

        for (unsigned short i = 0; i < str.length(); i++)
        {
                tempSprite.setTexture(font.getTexture(24));
                tempSprite.setTextureRect(font.getGlyph(str[i], 24, false).textureRect);
                tempSprite.setColor(sf::Color::Black);

                if (xPos + (2 * tempSprite.getTextureRect().width) >= window.getSize().x)
                {
                        xPos = 0;
                        yPos += font.getLineSpacing(24);
                }

                else
                { if (i > 1) { xPos += font.getKerning(prevChar, str[i], 24); } }

                tempSprite.setPosition(xPos, yPos + font.getGlyph(str[i], 24, false).bounds.top + font.getGlyph('A', 24, false).bounds.height); // should this be 'A' (?)
                chars.push_back(tempSprite);
                xPos += font.getGlyph(str[i], 24, false).advance;
                prevChar = str[i];
        }

        unsigned short crtCharNo = 0;

        while(window.isOpen())
        {
                window.clear(sf::Color::White);
                if (crtCharNo < chars.size() - 1) { crtCharNo++; }
                for (unsigned short i = 0; i <= crtCharNo; i++)
                { window.draw(chars[i]); }
                window.display();
        }
}
 

What am I doing wrong? I thought "getKerning" moves the characters closer, and "advance" moved them apart, but I am clearly doing something wrong.
(This assumes there is nothing wrong with the font I am using, which is called "Linux Libertine", although I doubt that's the case.)

Hopefully I explained myself in a decent manner. I would greatly appreciate any help.

14
General / Re: Problem with waiting
« on: July 23, 2014, 05:59:44 pm »
Yes, I tried it out, and it seems to work perfectly! Thanks!

(On a side note, I can't believe I never realized how to do this myself...  :-[)

15
General / Re: Problem with waiting
« on: July 23, 2014, 05:51:21 pm »
I want it to change characters after pretty much EXACTLY 0.1 seconds, is this possible this way?

Pages: [1] 2 3 4
anything