Question

Edit: Changed the title to better reflect the current issue.

Right i know now were the source of the issue lies, it's with the text splitting part of the function. I remember now what i did, i changed the splitting text because the tutorial for me was returning an error.

for(const char *c=text;*c;c++) 
{
    if(*c=='\n') {
        string line;
        for(const char *n=start_line;n<c;n++) line.append(1,*n);
        lines.push_back(line);
        start_line=c+1;
    }
}

if(start_line)
{
    string line;
    for(const char *n=start_line; n < c;n++) line.append(1,*n);
    lines.push_back(line);
}

The 'c' was returning undeclared, and there's no mention for any other c, so i guess it's referring to the pointer in the for loop above. Though bring the "if (start_line)" into the first code block, kept returning me each character in the text, instead of just the whole thing.
So i changed the code to the following:

for(const char *c=text;*c;c++) 
{
    if(*c=='\n') 
    {
        string line;
        for(const char *n=start_line;n<c;n++) line.append(1,*n);
        lines.push_back(line);
        start_line=c+1;

        if(start_line) 
        {
            string line;
            for(const char *n=start_line;n<c;n++) line.append(1,*n);
                lines.push_back(line);
        }
    }
    else if (*c == *start_line)
    {
        lines.push_back(text);
    }
}

I pretty sure that the "else if (*c == *start_line)" comparsion is what's causing me the issue. Unsure though what to replace it with. I guess though because i'm not using any newlines or don't plan to i can just go with:

for(const char *c=text;*c;c++) 
{
    lines.push_back(text);
    break;
}

But it would still be nice to know were i was going wrong. *Note: That the above code works fine now, no issue with that and the doubling effect. So i'm sure that it was my text splitting code.

Was it helpful?

Solution

Here's an idea for you: in your text rendering method, add a static counter and use it to set the color of each string rendered. Since you don't seem to have that many strings per frame, you can use the 8 bits of one color component (e.g. red) for the counter and set the 2 other components to 255. If you had more than 255 strings, you could still encode the counter value over 2 or 3 color components.

With this little debug aid, you will be able to see in which order each piece of text is rendered. You can use pixie and/or zoomin to see the pixel values "live". Otherwise, just take a screenshot and examine the result.

OTHER TIPS

It looks like the erroneously drawn text in that capture is "50b" which I doubt is a string that would normally appear in your game. It looks like you're drawing something that's normally an empty string, but sometimes picks up junk values - in other words, undefined behavior.

I can't be sure, of course, because I simply don't have enough information to find your problem. Your glClear looks fine to me, so you can be assured that the extra text is being drawn in the same frame as your intended text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top