Sign in to follow this  
  • entries
    15
  • comments
    6
  • views
    15205

Hackman Day 5 : Finally Text

Sign in to follow this  
Gooey

905 views

Ok so I had a few hours to kill today so I decided to get on with hackman and being the productive fool I am I procrastinated most of the day away. After hours of doing anything but get on with what I had planned I finally started working on my text renderer which looks like:class TextRenderer{public: enum Alignment { Top, Bottom, Left, Right, Center }; TextRenderer(const char * textureFilename = nullptr); ~TextRenderer(); void DrawAll(); void Draw(const std::string &text);// The offset is from the center of the text void AddText(const std::string &text, const float xOffset, const Alignment vertical, const float size, const glm::vec4 &colour); void AddText(const std::string &text, const Alignment horizontal, const float yOffset, const float size, const glm::vec4 &colour);// Adds text to the renderer at a certain alignment always stays at that alignment until it is changed void AddText(const std::string &text, const Alignment horizontal, const Alignment vertical, const float size, const glm::vec4 &colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));// Adds text to the renderer at a certain position in pixels from the bottom left void AddTextBottomLeft(const std::string &text, const float leftOffset, const float bottomOffset, const float size, const glm::vec4 &colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); void AddTextTopRight(const std::string &text, const float rightOffset, const float topOffset, const float size, const glm::vec4 &colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));// Removes the text from the vector void RemoveText(const std::string &text);// Moves text if it exists in vector from posititon in pixles void MoveTextWithAlignment(const std::string &text, const Alignment horizontal, const Alignment vertical); void MoveTextVerticallyFromTop(const std::string &text, const float whereFromTop); void MoveTextVerticallyFromBottom(const std::string &text, const float whereFromBottom); void MoveTextVerticallyWithAlignment(const std::string &text, const Alignment alignment); void MoveTextHorizontallyFromLeft(const std::string &text, const float whereFromLeft); void MoveTextHorizontallyFromRight(const std::string &text, const float whereFromRight); void MoveTextHorizontallyWithAlignment(const std::string &text, const Alignment alignment);// Changes text colour if it is in vector void ChangeTextColour(const std::string &text, const glm::vec4 &colour); void ChangeAllTextColour(const glm::vec4 &colour);// Changes the text size void ChangeTextSize(const std::string &text, const float size); void ChangeAllTextSizes(const float size); void IncrementTextSize(const std::string &text, const float increment); void IncrementAllTextSize(const float increment);private: class Text { public: Text(const std::string &text, const glm::vec4 &colour, const float xOffset, const float yOffset, const float size); ~Text(); glm::mat4 mModel; glm::vec4 mColour; std::string mText; float mSize; float mXOffset; float mYOffset; unsigned int mVao; unsigned int mVbo; void UpdateModel(); private: void CreateVao(const std::string &text); void CreateVbo(const std::string &text, std::vector &posVec); void AddTexCoords(const std::string &text, std::vector &posVec); void GetTexCoordLocation(const char &letter, float &x, float&y); }; std::vector>::iterator GetPositionOfText(const std::string &text); float AlignVertically(const Alignment vertAlign, const float size); float AlignHorizontally(const Alignment horiAlign, const size_t stringLength, const float size); bool IsTextInVector(const std::string &text); void Draw(const Text &text); void UpdateSizeAndPosition(Text &text, const float size); std::vector> mTextVec; glm::mat4 mView; unsigned int mProgram; unsigned int mTexture; int mWidth; int mHeight;};
It works and I am happy with it for now! There are some changes I'll make to it in the future as I am going to keep it for other projects. I had a few problems with it not displaying which turned out after an hour of searching in my vao creation when setting the attribute pointers up instead of GL_FLOAT i put GL_FALSE that will teach me to talk to people when I should be concentrating! Worst thing was I checked them two lines more than once in the hour. Oh well I have come away today happy not much left to do to now.

Things left to do:
[s]Text Renderer[/s]
Enemy Textures
Finish Enemy AI(add in different types)
Menu
Highscores?
Map Editor
Getting Geoff & Co walking through the pass throughs
Sound

hackman4.png
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now