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

Pages: [1]
1
Graphics / Re: Text only drawing white
« on: August 28, 2012, 04:31:42 pm »
My code is too complicated. It turns out that I forgot that the RenderLayer class I was adding my text objects to was overwriting their properties. I got that fixed, so I now have working text and one less design flaw!

2
Graphics / Re: Text only drawing white
« on: August 28, 2012, 02:51:14 am »
Fixed  ::)

Anyhow, why is this happening?

3
Graphics / Re: Text only drawing white
« on: August 27, 2012, 08:35:57 pm »
You asked for it!  :) See the original post.

I'm 100% sure that all of the data is being parsed from the file correctly; I'm logging everything and it's behaving exactly as it should.

4
Graphics / Text only drawing white
« on: August 27, 2012, 08:06:47 pm »
Hey folks! My engine is speeding right along and I'm making great progress, but I've hit an odd issue.

Fonts are loading fine, but my text objects won't display as any color other than white.

I can move them around and set the font, but they won't scale, rotate, change colors, or anything else. Any idea what's going on?

I'm using SFML 2 in Windows Vista.

There's nothing wrong with line 42.


/// Array.h

#include <cstddef>

template<class T> class Array
{
protected:

        T* data;
        unsigned size;

public:

        Array() : data(NULL), size(0) { }
        Array(const unsigned Size);
        Array(const unsigned Size, const T& Init);

        /// The = operator doesn't resize the arrays!
        Array<T>& operator= (const Array<T>& A)
        {
                if(A.Size() < size)
                {
                        for(int i = 0; i < A.Size(); i++)
                        {
                                data[i] = A[i];
                        }
                }
                else
                {
                        for(int i = 0; i < size; i++)
                        {
                                data[i] = A[i];
                        }
                }
                return (*this);
        }

        T& operator[](const unsigned i) { return data[i]; }
        const unsigned Size() const { return size; }

        void ClearTo(const T& t) { for(int i = 0; i < size; i++) data[i] = t; }

        void Reset(unsigned s);
        void Reset(unsigned s, const T& Init);

        ~Array();
};

template<class T> Array<T>::Array(const unsigned Size) : data(NULL), size(Size)
{
        data = new T[size];
}

template<class T> Array<T>::Array(const unsigned Size, const T& Init) : data(NULL), size(Size)
{
        data = new T[size];
        for(unsigned i = 0; i < size; i++) data[i] = Init;
}

template<class T> Array<T>::~Array() { if(!data) return; delete [] data; size = 0; }

template<class T> void Array<T>::Reset(unsigned s)
{
        if(data) delete [] data;

        size = s;
        data = new T[size];
}

template<class T> void Array<T>::Reset(unsigned s, const T& Init)
{
        if(data) delete [] data;

        size = s;
        data = new T[size];

        for(unsigned i = 0; i < size; i++) data[i] = Init;
}

 


/// FontManager.h

struct Font
{
private:

        std::string name;

        sf::Font sfFont;

public:

        Font() { }

        bool Load(std::string n, std::string path)
        {
                name = n;

                if(sfFont.loadFromFile(path)) return true;
                else return false;
        }

        const std::string& Name() const { return name; }

        operator sf::Font&() { return sfFont; }
};

class FontManager
{
private:

        Array<Font> fonts;

        static std::ofstream log;

public:

        FontManager(std::string cfgPath);

        const sf::Font& operator[](const unsigned i) { return fonts[i]; }
};

 

/// FontManager.cpp

#include "FontManager.h"
#include "BaseClasses/Dependant.h"
#include "Utilities/Stream.h"
#include <SFML/Graphics/Font.hpp>

template<> FontManager * Dependant<FontManager>::ptr = NULL;

std::ofstream FontManager::log("logs/FontManager.txt");

FontManager::FontManager(std::string cfgPath) : fonts(true)
{
        log << "Attemping to open file: " << cfgPath << ", ";

        std::ifstream file(cfgPath.c_str(), std::ios::binary);
        if(!file)
        {
                log << "unable to open file!" << std::endl;
                return;
        }
        log << "opened file." << std::endl;

        std::string folder;

        Utilities::Stream::Fetch<std::string>("folder", file, folder);

        log << "Folder path: " << folder << std::endl;

        unsigned count = Utilities::Stream::Count("font", file);
        if(!count)
        {
                log << "No fonts found; Intended? (Probably not.)" << std::endl;
                return;
        }
        log << count << " fonts found. Loading..." << std::endl;

        fonts.Reset(count);

        std::string fontName, fontPath;

        for(unsigned i = 0; i < count; i++)
        {
                Utilities::Stream::Ignore("font", file);
                file >> fontName >> fontPath;

                if(fonts[i].Load(fontName, folder + fontPath))
                {
                        log << "Loaded " << fontName << std::endl;
                }
                else
                {
                        log << "Unable to load font: " << fontName << std::endl;
                }
        }
        log << "Fonts loaded." << std::endl;
}

 

/// Text.h

#include "BaseClasses/Graphical.h"
#include "BaseClasses/Component.h"
#include "Color.h"
#include "Primative.h"
#include <SFML/Graphics/Text.hpp>

namespace sf
{
        class Font;
}

class FontManager;
class Renderer;

class Text :
        public Graphical,
        public Component,
        public Dependant<FontManager>,
        public Dependant<Renderer>
{
protected:

        sf::Text text;

        Float *x, *y;

public:

        virtual ~Text() { }

        Text(std::string n);

        virtual void Activate() { draw = true; }
        virtual void Deactivate() { draw = false;}
        virtual bool Active() const { return draw; }

        virtual void Read(std::istream& file);
        virtual void Write(std::ostream& file);

        virtual void Connect(Object * const Owner);

        virtual void SetColor(const Color& Color);
        virtual const Color GetColor() const;
        virtual void Draw(sf::RenderWindow& window);

        bool OnEvent(Event& e) { return false; }

        virtual void SetPosition        (const XYPairF& XY)     ;
        virtual void SetRotation        (float R)                               ;
        virtual void SetScale           (const XYPairF& XY)             ;
        virtual void SetOrigin          (const XYPairF& XY)             ;
        virtual void Offset             (const XYPairF& XY)             ;
        virtual void Rotate                     (float R)                               ;
        virtual void Scale                      (const XYPairF& XY)             ;
        virtual void SetString          (const std::string& S)  ;
        virtual void SetFont            (const sf::Font& F)             ;
        virtual void SetCharSize        (unsigned S)                    ;
        virtual void SetStyle           (sf::Text::Style s)             ;
};

 

/// Text.cpp

void Text::Read(std::istream& file)
{
        std::string string;
        XYPairF scale;
        float rotation;
        unsigned charSize, layer, font;
        Color c;

        Utilities::Stream::FetchString("string", file, string);
        Utilities::Stream::Fetch<bool>("draw", file, draw);
        Utilities::Stream::Fetch<float>("offsetX", file, offset.x);
        Utilities::Stream::Fetch<float>("offsetY", file, offset.y);
        Utilities::Stream::Fetch<float>("scaleX", file, scale.x);
        Utilities::Stream::Fetch<float>("scaleY", file, scale.y);
        Utilities::Stream::Fetch<float>("rotation", file, rotation);
        Utilities::Stream::Fetch<unsigned>("charSize", file, charSize);
        Utilities::Stream::Fetch<unsigned>("layer", file, layer);
        Utilities::Stream::Fetch<unsigned>("fontIndex", file, font);
        Color::FetchColor("color", file, c);

        text.setFont((*Dependant<FontManager>::ptr)[font]);
        text.setCharacterSize(charSize);
        text.setString(string);
        text.setScale(scale.x, scale.y);
        text.setRotation(rotation);
        text.setColor(c);

        Dependant<Renderer>::ptr->Add(this, layer);
}

 

/// Dependant.h

template<typename T> class Dependant
{
protected:

        static T* ptr;

public:

        static void SetPtr(T* const p) { ptr = p; }
        virtual ~Dependant() { }
};

 

[attachment deleted by admin]

5
SFML projects / Re: Pioneers
« on: July 16, 2012, 04:35:44 am »
This is absolutely gorgeous! You've got some pixel skillz for sure.

Are you writing this using a pre-existing framework/recycling or all from scratch?

6
Graphics / Re: Textures & Images Load as Blank White
« on: July 07, 2012, 01:04:38 am »
I got it figured out. All it was:


/* From this: */

//...

Application app("config/Application.txt");
sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");

/* To this: */

sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
Application app("config/Application.txt");

 

Nobody said OpenGL is initialized by creating a window  ??? That's kind of irritating, but at least it wasn't anything wrong in my code.

SFML 1.6 has great tutorials, but 2.0's don't cover the whole API yet. This might be something to stick in there  ;)

7
Graphics / Re: Textures & Images Load as Blank White
« on: July 06, 2012, 07:12:21 pm »
Ah okay, I see.
Do the examples that ship with the SDK work? (If so, we can be certain it's a bug in your code and not some OpenGL/SFML related problem.)
Do you get any errors on the std::err (= console)?

The only source of the problem I now could think of is the PtrMap, which could delete the texture too early or similar.


All the examples but the shader one work. I can also load Textures by themselves and things work, so it's probably some stupid mistake I'm making somewhere. I am getting "Failed to share the OpenGL context" messages on std::err. What does that mean?

It's sounds like it may be something in PtrMap to me too, which is weird because I haven't had any issues up to this point and I've been using it for a while.

8
Graphics / Re: Textures & Images Load as Blank White
« on: July 06, 2012, 03:33:47 am »

A white rectangle normally means that the texture the sprite is pointing at doesn't exist.
It's hard to tell where the problem is since the provided code contains a lot of unrelated stuff and other important things are left out.
What many programmers make wrong is not keeping track of the used texture resource. I can reakky recommend to use smart pointers and RAII so you won't have to deal with the deletion of your allocated memory. Although it seems like it gets handled correctly.

At this line:
return static_cast<const sf::Texture*>(textures.Find(Name));
You're making a cast, do you just 'add' the cons

You should post more cod on the TextureManager, it seems like something is going wrong in there...


That actually is all of the code for the TextureManager. Unless you want the header, in which case:


// TextureManager.h

#ifndef TextureManager_H_i
#define TextureManager_H_i

#include "PtrMap.h"

#include <fstream>
#include <string>

template<typename T> class DependantBase;

namespace sf
{
        class Texture;
}

class TextureManager
{
private:

        static std::ofstream log;

        typedef PtrMap<sf::Texture> TextureMap;

        TextureMap textures;

public:

        TextureManager(const std::string cfgPath);
        ~TextureManager();

        const sf::Texture * const Find(const std::string Name);
};

typedef DependantBase<TextureManager> TextureDependant;

#endif

 

Still lots of random stuff in there. Memory leaks aren't an issue though, take my word for it. PtrMap takes care of it in it's destructor; it deletes any pointers in the std::map that it wraps.

As for the white color, the sprite's size is being adjusted correctly; if the texture is 16x16, then the sprite is 16x16. It's just white, which is pretty irritating since it seems to be doing the other things correctly. It's just not reading the pixel data(apparently; I don't pretend to know how things work behind the scenes).

And yes, I just add the const :D
That wouldn't be the problem would it!?

9
Graphics / Textures & Images Load as Blank White
« on: July 06, 2012, 12:48:47 am »
Hey folks!

It's just like the subject says; I've recently switched to 2.0 from 1.6 and I'm having an issue with loaded textures or images being the correct dimensions but a blank rectangle of white.

My code:


// TextureManager.h

#include "EngineComponents/TextureManager.h"
#include "DependantBase.h"
#include "MyException.h"
#include "StreamUtilities.h"

#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Image.hpp>

std::ofstream TextureManager::log("logs/TextureManager.txt");

template<> TextureManager * TextureDependant::provider = NULL;

TextureManager::TextureManager(const std::string cfgPath) : textures(true)
{
        log << "Texture/Image manager initializing, config path: " << cfgPath << std::endl;

        std::ifstream file(cfgPath.c_str(), std::ios::binary);
        if(!file)
        {
                log << "Error: could not load file: " << cfgPath << std::endl;
                throw EngineException::fileNotFound;
        }

        std::string folderPath, extension;

        StreamUtilities::Fetch<std::string>("folderPath", file, folderPath);
        StreamUtilities::Fetch<std::string>("fileExtension", file, extension);

        log << "Folder path: " << folderPath << "\nFile extension: " << extension << std::endl;

        unsigned count = StreamUtilities::Count("image", file);
        if(!count)
        {
                log << "Warning: No image tags found in file. Intended? (Probably not.)" << std::endl;
                return;
        }

        std::string fileName;

        for(unsigned i = 0; i < count; i++)
        {
                StreamUtilities::Fetch<std::string>("image", file, fileName);
                StreamUtilities::Ignore("image", file);

                sf::Texture * t = new sf::Texture;

                if(!t->loadFromFile(folderPath + fileName + extension))
                {
                        log << "Warning: unable to load file: " << folderPath << fileName << extension << std::endl;
                        delete t;
                        continue;
                }
                textures.Add(fileName, t);
        }
        log << "\nImage manager successfully initialized! Number of images loaded: " << textures.Size() << '\n' << std::endl;
}

TextureManager::~TextureManager()
{
        log << "Image manager shutting down." << std::endl;
        textures.Clean();
        log << "Image manager freed memory; finished shutting down." << std::endl;
}

const sf::Texture * const TextureManager::Find(const std::string Name)
{
        return static_cast<const sf::Texture*>(textures.Find(Name));
}

 


// Main.cpp

#include "Application.h"
#include "EngineComponents/TextureManager.h"
#include "DependantBase.h"

#include <fstream>
#include <SFML/Graphics.hpp>

int main()
{
        Application app("config/Application.txt");

        sf::Sprite s;
        s.setTexture(*app.textures->Find(std::string("A")));

        sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(s);
        window.display();
    }
        return 0;
}

 

There are some parts there that don't make sense out of context; the Application class has a TextureManager* called textures. The TextureManager class has a PtrMap type I wrote that wraps the C++ list class; it's called textures and takes a bool on construction that determines whether the pointers should be deleted when the Manager goes out of scope.

I know that the textures' loadFromFile calls are returning true, so I don't know what's going on.

10
General / Re: Missing .dll: libgcc_s_dw2-1.dll
« on: April 11, 2012, 08:59:07 pm »
By the way, my name is Laurent :P

Hehe, whoops. Sorry about that.

11
General / Missing .dll: libgcc_s_dw2-1.dll
« on: April 10, 2012, 09:11:05 pm »
Hello people!

First, I'd like to say that SFML is a great library. I really appriciate the work that Laurence and everyone else has put into it.

But I have a problem. I had been using Microsoft Visual Studio 2010 with SFML and it worked fine. But my computer crashed, and I've gone the route of Code::Blocks this time. My own code compiles fine and everything, but when I try to use SFML it doesn't work. I downloaded the SDK and followed the instructions on the tutorial, and the test program compiles fine. But when I try to run it, I get a missing .dll error message about what looks like a gcc dll.

I'm assuming that the issue comes from the SFML binaries being built from a different version of gcc than what comes out of the box with codeblocks. I downloaded the gcc 4.4 zip from the tutorial, but I'm not sure what to do from here.

I tried building from source, but I got linking errors.

I would appriciate any help you guys can offer.

Edit:
Gosh I feel dumb. I just found the dll in the 4.4 zip and copied it to the directory of my program. Runs without a hitch now. Sorry for the disruption :P

By the way, this forum is nicer than the allegro forums. Just sayin'  ;D

Pages: [1]