• ### Announcements

• entries
11
8
• views
14682

The Ups and Downs of my Graphics Engine development

## Bubblez! Still Here

Hi All.

I know I promised a few more screenshots yesterday, but I've been sidetracked unfortunately.

I've also discovered a rather major bug in the code which means the animations aren't frame-independent. I'm hoping I'm going to have time to sort all the bugs before release time (bearing in mind I have work 8am-5pm BST tomorrow (with the deadline being 6pm BST for me)).

## Bubblez! Update

Well I've gotten enemy collision detection in place, I'm not entirely happy with the way the game handles collisions (at the moment it takes off a live, resets the player to the beginning and then pauses the game, waiting for you). It just doesn't seem to streamline very well. I think I need to add in some sort of animation of the bubble bursting and then the player reappearing, and remove the pause.

I'm also thinking of having a Scoring mechanism, so people can post their scores and see how well they did. I'm going to make it an endless game, and the difficulty just increases the longer you survive - I think.

At the moment I just have a single background image, but I'm thinking if I have time I'll make groups of zones (each zone just has a different background, and maybe different images for the enemies). But that's all time dependent. The key is to get the game playable, looking good and being fun. I can add extra fluff at the end.

No screenshot this time, but there will be (or possibly a little movie) at the end of the day.

## Bubblez! End of Day 1 round-up, and start of Day 2

Well I had to go to go to bed at 2am last night (I'd been at work since 8am), but for the 8 hours work I put in (god was it that much!) I'm quite happy with the outcome. In the first hour this morning I've added in Enemy spawns (Bee's and Leave's) - see screenshot below.

You're going have 2 or 3 types of Enemies to contend with:
• Bees
• Leaves
• Undisclosed (no mystery, I just haven't thought of the third yet!)There's also some bonuses/power-ups that I'm going to include
• Extra Lives
• Time Lapse
• Undisclosed (again, can't think of a third)The goal is to control the bubble, against the wind, and avoiding all the enemies to collect 3 gold stars that will spawn in the levels. Once you've done that you move onto the next level. Simples!

## Bubblez!

Well, I've hammered out an idea, I've done some work in PS (I know I should wait till the end because gameplay is far more important, but I couldn't help myself), and I've gotten movement working.

Next I need to work on collision detection, bonuses, enemies, win conditions, and extra maps (plus the tutorial if I have time to fit it in).

In the mean time, here's a screen shot:

## Let it commence

Well the GameDev.Net Community Challenge is underway, and I'm really excited.

It's the first one of these I've ever competed in, and it'll put my engine to the test (and hopefully force me to iron out some bugs).

I'll be updating my progress here.

I haven't finalised my idea yet, but I'm close. Stay tuned!

## Progress Update

So I've been slowly working away on my Graphics Engine for past 5 years or so, going through various iterations. Since we've had the update to GD.Net I thought I'd post an update.

2010 has not been a good year for me (changing jobs, becoming single, various debt issues, etc) so I haven't been able to concentrate much on development hence the lack of updates, I'm hoping 2011 will be different.

At the moment I'm working on converting all my code so that I can compile my engine into a DLL and link it into any apps that require it. This seems easy enough, but I'm struggling for some reason...I must be out of progress. Also, since my Graphics Engine is geared towards Broadcast there are some other things to take into consideration which in turn just slows everything down.

Once I've finished the DLL migration I'm hoping to have some content to actually post here and get some feedback.

Anyway, just a short update to let you know how it's going.

## OpenGL Ruined My Life

I've just returned from my holiday in New York City. Firstly, I'm packing my suitcase and wandering what books I shall take. So in goes Ross Kemp's Gangs, followed by a book by Brian Jacques. Looking around my room I then pick up two more books. The OpenGL Shading Language (Orange) Book, and a C++ Programming book. I mentioned this to a friend, and the first words out of his mouth were "You sad git". I'm inclined to agree with him. And to make matters worse, I never read the other two books, only the programming books.

Next, and this really irritates me. I'm lying in bed with my girlfriend, and we're watching TV and chatting. We start to hug and 'boom' a new way to organise my Shader class pops into my mind. For the love of god!! When I'm lying in bed with my girlfriend, OpenGL is not what I want to be thinking about.

P.S. Just so you know, I have implemented that change to my Shader class, and it has really helped, so at least something good came out of it.

## Using Multitexturing With GLSL

Hi There!

Time for another entry in my o so very exciting Development Journal (It will become more interesting when I have decent screenshots to show you).

I recently implemented multitexturing into my graphics engine. Doing so with the Fixed Function Pipeline (FFP) is relatively straightforward, and indeed doing it with GLSL (or CG for that matter) is also relatively simple. However, there are a number of things that you need to watch out for.

My first mistake was that I assumed then when I declared a uniform sampler2d in my shader, that it would know which Texture Unit to reference, based on the order in which the samplers were declared. This is what I struggled with. I had told OpenGL to do multitexturing, binding different textures to different Texture Units, and I had my GLSL getting the Texel from each texture sampler based on the texture coordinates. (I've posted my code below).

Now in hindsight this seems like a really stupid, and I'm not entirely sure why I thought it. Anyway, after much searching on Google I finally came across the fact that I need to manually set which Texture Unit each Sampler refers to. This is done simply using the line:

glUniform1i(loc, texUnit);

Where loc is the value returned from glGetUniformLocation(), and texUnit is the Texture Unit you want to have assigned to that Sampler.

After I called this function, it all started working.

There are tutorials out there which deal with the FFP part of multitexturing, and there are tutorials out there which deal with the GLSL part of multitexturing. Howevere, those dealing with GLSL don't deal with the calls you need to perform within your application. Below is my code which allows me to do multitexturing. I hope that my mistakes will help benefit other people.

Code from my C++ App:
glActiveTextureARB(GL_TEXTURE0_ARB);glBindTexture(GL_TEXTURE_2D, models->Materials[j].textureID[0]);glUniform1i(glGetUniformLocation(models->EffectProgramID, "diff_Map"), 0);glActiveTextureARB(GL_TEXTURE1_ARB);glBindTexture(GL_TEXTURE_2D, models->Materials[j].textureID[1]);glUniform1i(glGetUniformLocation(models->EffectProgramID, "norm_Map"), 1);glActiveTextureARB(GL_TEXTURE2_ARB);glBindTexture(GL_TEXTURE_2D, models->Materials[j].textureID[2]);glUniform1i(glGetUniformLocation(models->EffectProgramID, "fx_Map"), 2);glActiveTextureARB(GL_TEXTURE3_ARB);glBindTexture(GL_TEXTURE_2D, models->Materials[j].textureID[3]);glUniform1i(glGetUniformLocation(models->EffectProgramID, "misc_Map"), 3);

uniform sampler2D diff_Map;	// Diffuse Mapuniform sampler2D norm_Map;	// Normal Mapuniform sampler2D fx_Map;	// FX Mapuniform sampler2D misc_Map;	// Misc Mapvoid main(){	vec4 diffuse = texture2D(diff_Map, gl_TexCoord[0].st);	vec4 normal = texture2D(norm_Map, gl_TexCoord[0].st);	gl_FragColor = diffuse * 0.5;}

## Frame Buffer Object

Yea, well since my graphics engine is designed for a multitude of purposes (Games, Offline Renderer, Realtime Broadcast Graphics, etc) it needs to be as flexible as possible.

So, I've just implemented Frame Buffer Objects in the engine. Basically, I have a Camera class (cRenderer) that has an output, up until this point the output has always gone to a screen. This has changed now a Frame Buffer Object.

What this means is that I can assign Shaders on a per-model object for effects/lighting etc on a model-by-model basis. But I can now assign a Shader to the Output FBO of the Camera for full-screen effects (such as SSAO, Depth-of-Field, Motion Blur etc).

This has been exposed a very simple SetEffect() function as a member of the Camera Class.

However, it was not as simple as that. I was following Phantom's Framebuffer 101 example and for the life of me could not get it work.

My code was basically identical to what was in Phamtom's tutorial. Still no joy. A quick trip into the Gamedev IRC channel where I posed the question, and a very helpful Zao showed me his source code.

I then realised that I was not calling glTexParameteri() before glTexImage2D(). After that, everything worked! Hurrah. I post my code below for completeness.

glGenFramebuffersEXT(1, &FramebufferID);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FramebufferID);glGenRenderbuffersEXT(1, &DepthBuffer);glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthBuffer);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, Width, Height);glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, DepthBuffer);glGenTextures(1, &TextureBuffer);glBindTexture(GL_TEXTURE_2D, TextureBuffer);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TextureBuffer, 0);GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

## C++ File I/O

This is just a short journal entry, again not featuring any code, simply because I'm not on my machine.

I have converted over my TGA image loader from VB(6) to C++ and now I am working on converting my Model Loader. I wrote my own exporter for 3d Studio Max which exports just the information I require for models. It is a binary format, which I'm particularly proud of.

For loading binary files in C++ I am using the ifstream procedures. And I must say that I'm having a good amount of success with it. When I had used C++ previously, I had been using the fopen, fread, etc commands and found them sufficient. However, ifstream stuff just seems much....better, for some reason.

As I said, texture loading is working, however I'm still trying to verify whether model loading is working, as since I'm avoiding all 'older' OpenGL code, I'm not using any Immediate Mode. So I'm not sure whether it's my Vertex Array code or Model code that is incorrect, since my debugger does want to co-operate.

I'm sure that it will be up and running in the next day or so and I will post the code that I've used.

EDIT: I have now attached my TGA Loader Code

#pragma pack(1)typedef struct{	GLbyte		identSize;			// 0	GLbyte		colourMapType;		// 1	GLbyte		imageType;			// 2	GLshort		colourMapStart;		// 3	GLshort		colourMapLength;	// 5	GLbyte		colourMapBits;		// 7	GLshort		xStart;				// 8	GLshort		yStart;				// 10	GLshort		width;				// 12	GLshort		height;				// 14	GLbyte		bits;				// 16	GLbyte		descriptor;			// 17} TGAHeader;GLuint LoadMaterialFromFile(LPCSTR sFilename){	TGAHeader 			header;	long				dataSize;	unsigned long		        i;        GLuint                          textureID;	ifstream file (sFilename, ios::in | ios::binary);	if (file.is_open())	{				file.seekg (0, ios::beg);		file.read ((char*) &header, 18);		dataSize = header.width * header.height * (header.bits / 8);				vData.clear();		vData.resize(dataSize, 0);						for (i = 0 ; i < vData.size() ; i++)		{			file.read ((char*) &vData, 1 );		}		file.close();		glGenTextures(1, &textureID );		glBindTexture(GL_TEXTURE_2D, textureID );		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);		if (header.bits == 32)		{			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, header.width, header.height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, &vData[0] );		} 		else 		{			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, header.width, header.height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, &vData[0] );		}		return textureID;	}	else	{		return 0;	}};

## C++ vs VB for OpenGL

This may sound like a stupid statement. However, I have extremely good success with OpenGL using VB as the coding language.

I have implemented a full 2D/3D Graphics Renderer using it with extremely good performance.

However, I am now starting to hit problems in terms of performance when loading objects. I want to have no loading/transition screens between different areas of the map when a player moves from say his, ship to the dock, to the sickbay etc. One continuous batch of gameplay.

This is not feasible with my current setup. Since my graphics engine to date is single-threaded. When a new object needs to be rendered, it must first be loaded into memory, if it is not already. With even a relatively small model 30k polygons, it can take a good 500ms in order to do this, especially with normal and bi-tangent calculations being added. This obviously will not do.

I have started migrating my graphics renderer over to C++ to make full use of the power of multithreading that will be presented to me. Being able to have one thread for rendering, and use another thread for loading my models and texture data into memory.

Of course this bring's it own bunch of problems and headaches, namely synchronisation. However, as long as this is taken into consideration, my loading screens should be completely removed.

As this is the first entry in my development journal, I have no code to add. I am currently busy writing a series of tutorials, based in C++ for OpenGL 3.0 and I shall post my progress with these here as well.

I will also post progress of my graphics engine, Velora, which I am developing for the game Destiny, that my company, neogroup, is developing.

I hope to have an update at least once a week, so check back often.