Sign in to follow this  
  • entries
    8
  • comments
    8
  • views
    11783

My current project - KGL

Sign in to follow this  
Kazade

289 views

Recently I've been working on a sort of consolidation of all of the useful code that I have lying around. I've called it KGL or Kazade's Game Library. It's a library that allows me to easily do common stuff when writing games. For example, it will create an OpenGL window for me, it comes with a built-in Quake-like console, I have 2D TTF fonts, TGA and 3D .obj model loading and a simple resource manager. It could do with more documenting and tidying up before I release it for others to use, but it seems to be working really well for me.

Here's a little example of how it works, below the code is a screen shot of what the output looks like:


#include
#include "MyGame.h"

using namespace kgl;

MyGame::MyGame():
Game("app-config.txt") {
m_ResourceManager = shared_ptr ( new resources::ResourceManager);
}

MyGame::~MyGame() {

}

bool MyGame::onInitialize() {
//Set the caption at the top of the window
getWindow().setTitle("KGL - Lesson 01");
getWindow().setWidth(1024);
getWindow().setHeight(768);
getWindow().applySettings();

createConsole();
getConsole().setBackgroundImage("console-back.tga");
getConsole().setBackgroundColour(colours::White);

getConsole().getFont().setHeight(12);

m_Model = m_ResourceManager->load("farn.obj", "fern_model");

BOOST_FOREACH(shared_ptr mat, m_Model->getMaterials()){
shared_ptr newTex = m_ResourceManager->load(mat->m_TextureFile, mat->m_Name);

if (!newTex) {
std::cout << "Could not load texture: " << mat->m_TextureFile << std::endl;
}
m_ModelTextures.push_back(newTex);
}

return true;
}

void MyGame::onRender() {
static float angle = 0.0f;

(angle > 360.0f)? angle -= 360.0f : angle+=0.5f;

//Clear the colour and depth buffer and clear to grey
getWindow().clear(colours::Grey);
//OpenGL code goes here
glLoadIdentity();

glPushMatrix();
glTranslatef(0, -0.5, -2.0f);
glRotatef(angle, 0, 1, 0);


glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.3);
for (uint i = 0; i < m_ModelTextures.size(); ++i) {
m_ModelTextures->bind();
m_Model->renderByMaterial(i);
}
glDisable(GL_ALPHA_TEST);

glPopMatrix();
}





Other stuff that you can't see includes:

* A strings namespace that contains a load of handy string functions
* A filesystem namespace that contains functions such as isFile(), isDir(), and path manipulation functions
* A game timer
* An ini config file reader
* An event handling system
* A load of predefined colours (see the Window::clear method above)
* Probably more stuff that I can't remember [smile]
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