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

About this blog

A journal of stuff i have done

Entries in this blog

My Text Renderer

So in the last month I have made, remade then scrapped and made again a text renderer for OpenGL using freetype2. I think I am finally happy with it but I am very sure that will change. I still want to add in a way to find available fonts but that can happen whenever I am not too bothered at the moment. After sorting out my renderer the first time I wanted to add a simple list option which triggered remake one when I realized the code was a mess and I needed to add stuff too it. Got that sorted then made a menu selection thingy which then made me change loads of code again and ultimately ended with me deleting the whole thing and starting again with my new knowledge of how i wanted it set out! As much as I know that this isn't all that productive I have done it as I can't decide what I want to make next and I wanted text I could generate on the fly rather than having a file sitting about to be loaded as a texture. Anywho it is done and now I can let it rot in the deep dark damp depths of my hdd!

Hackman Day 9

So this was my last day of working on Hackman it only took me 2 more than I thought which is quite good I think. What I had not accounted for was how long it takes to track down sounds! I am not fully happy with the sounds but they work and that is good enough for what was just a sharpening up exercise. Bugs I found and destroyed were OpenAL was crashing the game when it played a sound every now and then. This was caused by me adding to the sound vector when it was looking into that so I decided to change from using a vector in a seperate thread to using a class that mutex the list until it was finished with not that it could get touched as it was all running in one thread but it now can be used in a seperate one if i wanted yay me! I also made all the textures and sounds load up in multiple threads so the content loads quicker. This had a problem where it was crashing the game then I remembered that OpenGL hates multiple threads so reduced it just to loading the image then used the main thread to setup the texture for OpenGL. I added music this went without a hitch.

One of the most disappointing things about this has been that I set out to make the code readable and easy to navigate but as I found out today at some point that went out the window. I had to browse through a fair bit of the code till I found what I was looking for a couple of times. Function names could be a bit clearer also but it works yay! I could finish finish it by adding in the options menu but I am not sure I will.

Next up I think I am going to move to something 3d maybe a driving game I am not sure. First thing is first a couple of days ago I couldn't get the enthusiasm up to do this and decided to learn to do animation so I have been messing about with that a bit. Oh hackmans source and what not is on GitHub.

Hackman Day 8 And Late

Ok so I haven't made my 7 day deadline which im disappointed in but i will finish this I have not got much left to do. I have now finished my map editor all it needs is the same as the game the artwork for the 2 remaining characters. I have implemented my highscore saving with name entry I may add this name entry to the options screen that is yet to be implemented. There are no pictures today as nothing visually has changed but hopefully I will have this completed in two more days.

Things left to do:
Sound
2 pieces of art for enemys
make enemys switch modes
to decide when special item appears
make the power pill let me kill ghosts
difficulty levels
2 more levels

Hackman Day 7

Right so today I have sorted out a new enemy which is supposed to be a bear but looks nothing like it! Also I have a mostly working map editor all I need to do is add in a save option. I had a few problems like being so tired i couldn't work out how to invert my mouse position coordinates which was quite simple thanks to Tetriarch who made me realise I did not have to do (mousePosY - height / -1.0f) but i could do height - mousePosY! I added things such as left click selects whatever tile you are above if you haven't already got one selected. If you have a tile/character selected then it will change whatever is under it to that tile(unless it is off the map). To unselect a tile just right click might make this delete whatever is under it at some point.

supposedly bear thingy
bear.png

map editor
hackman7.png

Hackman Day 6

Ok so today I have updated hackman a bit more I now have finished my highscore board, I have implemented lives, sorted out a bug with my main menu, scoring system(if you had not guessed from the highscore board). Had a few piddly problems like the menu not displaying properly after playing the game.

Things left to do:
everything sound related still
3 more enemy types(bear, badger and snake)
4 more levels(may make more but this is a minimum)
enemy mode switching
create map maker

hackman6.png

Hackman First Enemy

Added a new enemy today its supposed to be a wolf but well it is not the best work artistically I haven't had alot of time recently and had a spare half hour so I made this in gimp quickly

Things left to do:
sound(adding it and creating it)
3 more enemy types(bear, badger and I dunno maybe snake)
4 more levels they will be in a loop
create scoring system
highscore board
make enemys switch between modes(chase, retreat and patrol)
create map maker
wolf.png

See not the best workmanship but it is better than using Geoff for all the enemys.

hackman5.png
Ok so today I decided to upgrade my Windows install which was 8.1 to Windows 10 because well it was free! So I shut down Debian rebooted to Windows and then the problems happened! I done all my updates checked for virus' and the like then I was ready. Varified with the Windows thing that I was allowed a free update then I downloaded the Windows creation tool and hit Update.... I was excited to see what the new look Windows had to offer. After 5 mins I had the download part of the update all complete then it varified the downloaded file all was going smoothly then the window disappered! Alt + Tab all around the place to make sure a reboot dialog had popped up nothing so I thought maybe it crashed or something so did it again and the exact same happened! I was really angry at this after the third try so I decided to have a look at the download myself and found a file called setup.exe in the hidden folder windows.WS or something like that. I ran this setup and it got me to a whole new screen that said it was checking stuff then BANG it said it couldn't decide if my computer could run Windows 10. I checked all the system requirements and was 100% sure I could so I tried again for the same message... I decided to give myself a bit more space on my windows partition as I have 1TB unallocated when I noticed it said one of my other hard drives partition was active. Why?! Well Windows is dumb thats why obviously when it booted up it assumed it was on the first primary partition WRONG! That would be where my stable Debian is stupid thing. So I activated the correct partition then ran the install again and realised why I hate updating Windows
A) It takes forever
B) It reboots a million times meaning I had to keep selecting boot to Windows
C) It takes forever
and D) It takes forever
Anyway it got to 75% after well pretty much forever I was feeling peckish so thought I would cook pizza and chips. Then Windows decided to lose the race between what was ready first my computer and my food. Now it is all installed and I am once again happy!

Once I had faffed about in Windows for a bit played a couple of games such as blueshogun96's looptil, cozzie's BooH! and endurion's WoA entry and decided minus VS I really am not a fan of the OS. Booted back to Debian and decided to carry on my adventure with Blender and created me a minion it is a bit of a rough model but I have only made that and a cup so I am pleased with it!
renderedMinion.png
I have today decided to start to learn how to use blender. I watched a tutorial and so far have made a cup and a wolf. The wolf turned out looking more like a pig so it got binned but oh well not bad for a first attempt! I think I need a step between the cup and the wolf so I am gonna start with a minion as they seem quite easy to do.

cup.png
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

Hackman Day 4

Ok so today I have implemented my A* pathfinding for my enemys which has worked a treat! It wasn't as hard as I first thought when starting out after I read a few articles on how it worked implementation only took a couple of hours including fixing the bugs! Now all I have left to do on the AI front is to make a few different modes which will be 3 states of Chase(main mode to kill Geoff), Retreat(when Geoff is armed and dangerous) and Patrol(going round a certain area). I'd like to also implement 4 chase types which would be DeadOn(aim for where Geoff is), Infront(Will aim for a square infront of Geoff), Behind(will aim a few squares behind Geoff) and Stalk(Will aim for the closest square at a certain distance from Geoff). All these seem easy enough to implement the hardest being Stalk which will require a bit more thought but sure it won't take too much.

After I have finished up the AI I think i'm going to make a map editor so I can design levels alot easier than drawing them out then manually editing .txt files. I also need to make some textures for the enemys which i think will be wolf, badger, bear and i'm not sure but one more. I need to do some collision work but that shouldn't be too hard as I have done this before. The biggy i'm leaving till last will be the text renderer I have made one before but lost it a while back so then I can add all my text to the game such as Score, level number maybe some other stuff but also ill then get to put in a highscore board and make a menu that isn't just a texture and hardcoded values.

The game looks the same so no need to upload a picture. 3 days remain to get this done hopefully one or two will be the weekend so I am not claiming 2-3 hours as a day. Oh and I need some sound but I have never done that before so that will be interesting.

Hackman Day 2

Ok so I had no time yesterday so i done some more today I have it loading and displaying now. Next up will be to get some movement and collision detection hopefully I will get some time tomorrow for that. I had a problem to begin with that nothing was being displayed. The problem was quite a simple one I had wrotestd::size_t offset(sizeof(float) * 2 * 6 * where);glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offset);
instead ofstd::size_t offset(sizeof(float) * 2 * 4 * where);
Then my biggest problem came with actually getting Geoff to display properly he was displaying as the full texture instead of just a corner of it and spent ages messing about with it! It turned when I added an extra variable to my character class I wrote it different in the constructor definition to the prototype all because I done them backwards! After adjusting that it worked fine. I really need to do some new graphics but that can wait!
hackman.png

Two days down. Three to go hopefully.

Hackman Day 3

Ok so today i spared a couple of hours for the creation of this and not everything has been skippy sad.png. I spent an hour trying to work out why when i rotated Geoff he was a touch off center i think it comes down to the fact he isnt very central in the artwork so i have put some magic numbers in to make him central poor programming i know but got very pissed off trying to work it out. I have made the trees get cut down now as you get to them and added in a win condition so when they are all gone you win! Next up AI im not looking forward to it but I have atleast made the control system easy enough for it to be keyboard, mouse or anything really so thats a win.
So today after reading load of great ideas for games by everyone entering Week of Awesome I got the urge to start a game. The idea is a pacman style game mixed with a game my brother made some 20 years ago on the spectrum +2. So you are Geoff a wood chopper that has to cut down all the trees before you get eaten by wolves or something. It will give me some time to look into A* for my ai which is something i have little experiance with.

I aim to complete the game with 5 levels, a high score board, a bonus level and a basic level editor within 2 weeks but hope to have it done in 1. You will start with 3 lives in normal mode 1 in hard and 5 in easy with the enemys getting harder to escape and time it takes them to start hunting lower. Ill have to decide on how the scoring works in how much you get per tree cut and how much you get per enemy killed maybe bonus points for more than one enemy killed per chainsaw(power pill). Ill again use C++, OpenGL and LodePNG with the window opening, shader program and texture loading functions I had from the TicTacToe game.
So today I decided I might aswell put an option of an AI player in my game. I have give the options of player vs player, player vs ai, ai vs player and ai vs ai. I haven't added any specific level of difficulty which does mean unless you mess up the game is a tie. I should probably add in a random move selector for a winnable mode or maybe a selector which doesn't select the move but if it is going for win/lose/draw that move I dunno. It was really not that hard to program and i also updated the way the game checked for wins it was using two for loops and an if statement to an array of wins and a for loop.bool Board::GetWin(int &winner) const{// All possible wins static int winLines[8][3] = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6} }; bool won(false); // loops through the winLines list and checks it across the board for(int i(0); i < 8; ++i) { if(mBoard[winLines[0]] > 0 && mBoard[winLines[0]] == mBoard[winLines[1]] && mBoard[winLines[1]] == mBoard[winLines[2]]) { winner = mBoard[winLines[0]]; won = true; break; } } return won;}
So my code for my ai i dont think is too bad but it could probably be improved by quite a bitint Move(std::array board, int player){/* set score to -2 which is 1 less than a loss so any move that is * found the score of the worst outcome -1(a loss) so even if the * only move is to lose it is the best move*/ int move(-1), score(-2); for(std::size_t where(0); where < board.size(); ++where) { if(board[where] == 0) { board[where] = player;/* The ai returns a score related to the player in that iteraton so * we need to get the inverse of that score to apply to the player * we are looking for a move for */ int tempScore(-AI::MiniMax(board, (player == 1 ? 2 : 1))); if(tempScore > score) { score = tempScore; move = where; } board[where] = 0; // change the square back to unused } } if(move == -1) { return 0; // Shouldn't ever be reached } return move;}
the MiniMax function is pretty much the same as the Move function except it returns the score rather than the move and checks if it is a winning positionint MiniMax(std::array board, int player){int score(-2);{ int win(AI::Win(board)); if(win > 0) score = (win == player ? 1 : -1);}
playerselectionscreenshot.png

That about wraps it up the game and source can be found at github
So today I had some spare time so decided to make a two player game of Tic-Tac-Toe. In all it took 8 hours but I was watching Criminal Minds whilst doing it. I have given the game winner screen and a play again screen which is about all that a game like this needs so I consider it complete. On the way I had a few problems like it kept saying I had an error when glGetError was used which turned out to be this beaut// had to add this is as GLEW was giving me an unknown enum error(1280) :(for(bool empty(false);!empty;){ GLenum err(glGetError()); if(err == GL_NO_ERROR) empty = true; else if(err != 1280) std::cerr << "ERROR I REPEAT ERROR: " << err << "\n"}
As the comment says it was throwing up an error code of 1280 which is an unknown enum error! Turns out this is a common problem one which I personally haven't ever come across so took a bit of time and a shed load of std::cerr's. Most of the other problems were unused variable warnings from callback funtions so I put a few things in to block these out such asvoid Resize(GLFWwindow * window, int width, int height){// really no point in window apart from killing the issue message of unused var if(width == height && window) { glViewport(0, 0, width, height); }
There was one more annoying error in that none of my play again screen would render right but that was because I passed the wrong value into it. Instead of passing the playing area i passed player this took an hour to solve which is alot longer than i wanted it to take but hay ho.

I might at some point add a computer player in to this game but that wont be today or tomorrow! If I do it will have three difficulty levels of easy, medium and hard. All in all I have enjoyed this although it isn't the best looking game ever I never have been much of an artist and it is Tic-Tac-Toe. If you wish to see the game/code it is on GitHub

TicTacToe.png
Sign in to follow this