Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.






My current project - KGL

Posted by Kazade, 28 December 2007 · 126 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 <boost/foreach.hpp>
#include "MyGame.h"

using namespace kgl;

MyGame::MyGame():
Game("app-config.txt") {
m_ResourceManager = shared_ptr<resources::ResourceManager> ( 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<resources::StaticModel3D>("farn.obj", "fern_model");

BOOST_FOREACH(shared_ptr<resources::ModelMaterial> mat, m_Model->getMaterials()){
shared_ptr<Texture2D> newTex = m_ResourceManager->load<resources::Texture2D>(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[i]->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]




December 2014 »

S M T W T F S
 123456
78910111213
14151617 18 1920
21222324252627
28293031   

Recent Entries

Recent Comments

Recent Entries

Recent Comments

PARTNERS