Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 30 Jan 2011
Offline Last Active Nov 28 2013 08:49 PM

Topics I've Started

Game Architecture/Design Pattern?

20 February 2013 - 10:29 AM



I want to know if there are any game architectures that are recommended, well, actually I don't know if I can call them architectures or design patterns.


Basically what I want to know is how do you structure your games at a logical for example I tend to the following.


I create an object named GameMaster, this object controls the game (enemies, ambient, etc) and knows the state of everything in the game, the control is done through Managers, for example EnemieManager, AmbientManager, etc. This managers don't communicate directly, the communication has to go throught the GameMaster.


In a more plactical way say we have the following:


class GameMaster
	Player player;
	EnemyManager enemyManager;
	GameStatus status;

	void update()
		if(enemyManager.enemies == 0)
			status = GameStatus.EndGame;

		if(status == GameStatus.EndGame)

	void draw()


Sure, the managers can also have control of a few elements... what I see in some friends code is more like...


class Player
	GameStatus status;

	void update()
		if(status == GameStatus.EndGame)
        void draw()

class EnemiesManager
	Player player;
	int enemies; 

	void update()
		if(enemies == 0)
			player.status = GameStatus.EndGame;

So my doubt are, what is better? what is worse? are there any architecture/patterns for structuring the objects in the videogames?.


I follow the GameMaster pattern because it's easier to me to structure things like this, but maybe this is not the best pattern...



Any literature on the topic is appreaciated wub.png

Applying Look At matrix

29 December 2011 - 04:19 PM

I'm developing a camera class on OpenGL in C++, I want to see the position and rotation that the camera has when using gluLookAt(), for this I'm using glm::lookAt() function, it retrieves a matrix 4x4 and then I multiply the current stack matrix with the one that was retrieve, and then I translate the camera to the position.

So my code looks like this

void camera::drawDebug()
    glm::mat4 res = glm::lookAt(eye, target, up);
    glTranslatef(-eye.x, -eye.y, -eye.z);

with this code I get the following image, considering that the red cube is at the center(0, 0, 0), and the wire cube is the camera, eye is (0, 5, 5), target is (0, 0, 0), up is (0, 1, 0)

Posted Image

As you can see it appears that the rotation is applied correctly but the translation is not correct. I'm doing -eye translation because of what it says on the documentation of glulookat.

...gluLookAt is equivalent to glMultMatrixf(M); glTranslated (-eyex, -eyey, -eyez);

Any ideas on how to fix the translation?

Exporting obj on Maya 2012

06 November 2011 - 11:43 AM

I'm a total noob on Maya, so far I know how to place a cube and map it through UV Mapping editor :). I want to export the model in an .obj file with the texture (.dds) and then add it to the Game Engine (using Assimp). The obj loads correctly and the texture loads ok, but the model is black, so I try loading the obj on Assimp viewer and the model is black though it loads correctly the texture, so I'm thinking that there's something wrong with the obj file and the uv coords. Though in maya everything looks ok

Can you tell me how to export correctly the model? The steps I follow are, select the obj, then file>Export Selection>*.obj, save


OpenGL Model Tessellation

26 October 2011 - 02:21 PM

I'm trying OpenGL 4.0 Tessellation and I want to apply it to an stablished model, my model is on .md2 format, I'm assuming that a Bezier evaluation will do with the evaluation shader, though I may be very very wrong. Anyways I'm stuck with the following instructions

      glBindBuffer( GL_ARRAY_BUFFER, vboid)
 		glPatchParameteri(GL_PATCH_VERTICES, 3);
 		glDrawArrays( GL_PATCHES, 0, size ); // size = how many vertices the model has
  	glBindBuffer( GL_ARRAY_BUFFER, 0)

The problem is that when it renders the model looks all messy and it certainly doesn't look like when I rendered it using glDrawArrays(GL_TRIANGLES, 0, size). Any suggestions on what parameters to use on glPatchParam... and glDrawArrays?

Thank you

[GLSL] Problem with Simple Shading Example

14 August 2011 - 04:06 PM

Hello, I just got the 3rd Ed of the Orange book (learning GLSL) and I have some problems running the first example :(. The code is as follows:

int installBrickShaders(const GLchar *brickVertex, const GLchar *brickFragment)
	GLuint brickVS, brickFS, brickProg; // handles to objects
	GLint vertCompiled, fragCompiled;
	GLint linked;

	// Create a vertex shader object and a fragment shader object
	brickVS = glCreateShader(GL_VERTEX_SHADER);
	brickFS = glCreateShader(GL_FRAGMENT_SHADER);

	// load source code strings into shaders
	glShaderSource(brickVS, 1, &brickVertex, NULL);
	glShaderSource(brickFS, 1, &brickFragment, NULL);

	// Coompile the brick vertex shader and print out
	// the compiler log file

	glGetShaderiv(brickVS, GL_COMPILE_STATUS, &vertCompiled);

	// Compile the brick fragment shader and print out
	// the compiler log file

	glGetShaderiv(brickFS, GL_COMPILE_STATUS, &fragCompiled);

	if(!vertCompiled || !fragCompiled)
		return 0;

	// Create a program object and attach the two compiled shaders

	brickProg = glCreateProgram();
	glAttachShader(brickProg, brickVS);
	glAttachShader(brickProg, brickFS);

	// Bind user-defined in variable to vertex attribute

	glBindAttribLocation(brickProg, 1, "MCvertex");
	glBindAttribLocation(brickProg, 2, "MCnormal");

	// Bind user-defined out variable to data buffer

	glBindFragDataLocation(brickProg, 0, "FragColor");

	// Link the program object and print out the info log



	glGetProgramiv(brickProg, GL_LINK_STATUS, &linked);

	// Install program object as part of current state


	// Set up initial uniform values

	glUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, .3, .2);
	glUniform3f(getUniLoc(brickProg, "MortarColor"), .85, .86, .84);
	glUniform2f(getUniLoc(brickProg, "BrickSize"), .3, .15);
	glUniform2f(getUniLoc(brickProg, "BrickPct"), .90 , .85);
	glUniform3f(getUniLoc(brickProg, "LightPosition"), .0, .0, 4.0);
void main(int argc, char **argv)
	int success = 0;
	int gl_major, gl_minor;

	GLchar *VertexShaderSource, *FragmentShaderSource;

	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize( 500, 500);
	window = glutCreateWindow( "3Dlabs Brick Shader" );

	glutIdleFunc( play );
	glutDisplayFunc( display );
	glutKeyboardFunc( key );
	glutReshapeFunc( reshape );
	glutMotionFunc( motion );
	glutMouseFunc( mouse );
	glutSpecialFunc( special );

	glutTimerFunc(TIMER_FREQUENCY_MILLIS, timer, 0);

	// Initialize the "OpenGL Extension Wrangler" library

	// Make sure that OpenGL 2.0 is supported by the driver
	getGlVersion(&gl_major, &gl_minor);
	printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);

	if(gl_major < 2)
		printf("GL_VERSION major=%d minor=%d\n", gl_major, gl_minor);
		printf("Support for OpenGL 2.0 is required for this demo... exiting\n");


	key('?', 0, 0); // display help

	readShaderSource("shader", &VertexShaderSource, &FragmentShaderSource);
	success = installBrickShaders(VertexShaderSource, FragmentShaderSource);


#version 140

in vec4 MCvertex;
in vec3 MCnormal;

uniform mat4 MVMatrix;
uniform mat4 MVPMatrix;
uniform mat3 NormalMatrix;

uniform vec3 LightPosition;

const float SpecularContribution = .3;
const float DiffuseContribution = 1. - SpecularContribution;

out float LightIntensity;
out vec2 MCposition;

void main()
	vec3 ecPosition = vec3(MVMatrix * MCvertex);
	vec3 tnorm		= normalize(NormalMatrix * MCnormal);
	vec3 lightVec	= normalize(LightPosition - ecPosition);
	vec3 reflectVec	= reflect(-lightVec, tnorm);
	vec3 viewVec	= normalize(-ecPosition);
	float diffuse	= max(dot(lightVec, tnorm), 0.);
	float spec		= 0.;

	if(diffuse > 0.)
		spec = max(dot(reflectVec,viewVec), 0.);
		spec = pow(spec, 16.);

	LightIntensity =	DiffuseContribution * diffuse +
						SpecularContribution * spec;

	MCposition	= MCvertex.xy;
	gl_Position = MVPMatrix * MCvertex;

#version 140

uniform vec3 BrickColor, MortarColor;
uniform vec2 BrickSize;
uniform vec2 BrickPct;

in vec2 MCposition;
in float LightIntensity;

out vec4 FragColor;

void main()
	vec3 color;
	vec2 position, useBrick;

	position = MCposition / BrickSize;

	if (fract(position.y * .5) > .5)
		position.x += .5;

	position = fract(position);
	useBrick = step(position, BrickPct);

	color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);

	color *= LightIntensity;

	FragColor = vec4(color, 1.);

When the program reaches simpleShaderExample.cpp::::glBindFragDataLocation(brickProg, 0, "FragColor"); it gets an Unhandled Exception
Unhandled exception at 0x00000000 in emptyExample.exe: 0xC0000005: Access violation.

I have looked through google and I can't find any solution hope you can help me on what to do because I'm badly stuck in this error.

Thank you very much for your help