Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Mar 2007
Offline Last Active Jan 13 2015 11:23 AM

Topics I've Started

Connectrix [iOS] -- our first release

28 May 2014 - 01:10 PM

Hi all,


I am proud to present Connectrix. This project was completed by a team of 2 and took over a year to develop -- trying to find time alongside full-time jobs, theses, new family....


Connectrix is straight forward to play. Tap the boxes as they fall to rotate them and cycle through its colors. Try to connect boxes of the same color to destroy them. 



- Game center achievements and leaderboards

- iCloud synchronisation of completion data and stats across your devices

- Universal app

- 3 game modes

- 3 explosive power-ups

- No in app purchases




The implementation features a mix of cocos2d and raw OpenGL ES.


If anyone wants more detail or has any comments, please let me know smile.png



Attached File  Screenshot1_iPhoneRetina3-5Inch.png   560.61KB   3 downloads


Attached File  Screenshot3_iPhoneRetina3-5Inch.png   543.46KB   3 downloads



Hybrid ortho/perspective view frustum

20 December 2012 - 02:27 PM

I am trying to create an effect where the view frustum provides a perspective effect along the x-axis, but an orthographic effect along the y-axis.

Think of a perspective view frustum but where the top and bottom faces run parallel to each other. Does anyone know how I an achieve this effect?

Atmospheric Scattering

30 June 2011 - 06:30 PM

I'm trying to implement atmospheric scattering using O'Neill's algorithm from GPU gems 2. I only need to render the atmosphere from the ground. To do this I create a half sphere of radius 6.53745. In the shaders I have hard-coded all of the parameters while I try and get something working. Due to the player remaining at ground level I have also hard-coded the camera position within the vertex shader to be at the planet radius.

Here is the vertex shader (GLSL):
uniform mat4 mvp;
uniform mat4 mv;

const vec3 v3CameraPos   		= vec3(0.0, 0.0, 6.378);																			// The camera's current position
const vec3 v3LightPos                 = normalize(vec3(0.0, 0.0, 1.0));																// The direction vector to the light source
const vec3 v3InvWavelength   	= vec3(1.0 / pow(0.650, 4.0), 1.0 / pow(0.570, 4.0), 1.0 / pow(0.475, 4.0));		// 1 / pow(wavelength, 4) for the red, green, and blue channels
const float fCameraHeight        = 6.378;																									// The camera's current height
const float fCameraHeight2   	= 6.378 * 6.378;																						// fCameraHeight^2
const float fOuterRadius 		= 6.53745;																								// The outer (atmosphere) radius
const float fOuterRadius2        = 6.53745 * 6.53745;																					// fOuterRadius^2
const float fInnerRadius 		= 6.378;																									// The inner (planetary) radius
const float fInnerRadius2        = 6.378 * 6.378;																						// fInnerRadius^2
const float fKrESun              = 0.0025 * 15.0;																						// Kr * ESun
const float fKmESun              = 0.0015 * 15.0;																						// Km * ESun
const float fKr4PI   			= 0.0025 * 4.0 * 3.1415;																			// Kr * 4 * PI
const float fKm4PI   			= 0.0015 * 4.0 * 3.1415;																			// Km * 4 * PI
const float fScale   			= 1.0 / (6.53745 - 6.378);																			// 1 / (fOuterRadius - fInnerRadius)
const float fScaleDepth          = 0.25;																									// The scale depth (i.e. the altitude at which the atmosphere's average density is found)
const float fScaleOverScaleDepth = (1.0 / (6.53745 - 6.378)) / 0.25;																// fScale / fScaleDepth

const int nSamples = 2;
const float fSamples = 2.0;

varying vec3 v3Direction;

float scale(float fCos)
	float x = 1.0 - fCos;
	return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));

void main(void)
	// Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
	vec3 v3Pos = gl_Vertex.xyz;
	vec3 v3Ray = v3Pos - v3CameraPos;
	float fFar = length(v3Ray);
	v3Ray /= fFar;

	// Calculate the ray's starting position, then calculate its scattering offset
	vec3 v3Start = v3CameraPos;
	float fHeight = length(v3Start);
	float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight));
	float fStartAngle = dot(v3Ray, v3Start) / fHeight;
	float fStartOffset = fDepth*scale(fStartAngle);

	// Initialize the scattering loop variables
	float fSampleLength = fFar / fSamples;
	float fScaledLength = fSampleLength * fScale;
	vec3 v3SampleRay = v3Ray * fSampleLength;
	vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;

	// Now loop through the sample rays
	vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
	for(int i=0; i<nSamples; i++)
		float fHeight = length(v3SamplePoint);
		float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
		float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
		float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
		float fScatter = (fStartOffset + fDepth*(scale(fLightAngle) - scale(fCameraAngle)));
		vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
		v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
		v3SamplePoint += v3SampleRay;

	// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
	gl_FrontSecondaryColor.rgb = v3FrontColor * fKmESun;
	gl_FrontColor.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
	gl_Position = mvp * gl_Vertex;
	v3Direction = v3CameraPos - v3Pos;

and the fragment shader:

const vec3 v3LightPos = normalize(vec3(0.0, 0.0, 1.0));
const float g 		= -0.95;
const float g2        = -0.95 * -0.95;

varying vec3 v3Direction;

void main (void)
	float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
	float fRayleighPhase = 0.75 * (1.0 + fCos*fCos);
	float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
	gl_FragColor = fRayleighPhase * gl_Color + fMiePhase * gl_SecondaryColor;

This is the output I get (when looking up). Just a hit of blue at the top of the sky dome and a grey-white color everywhere else:

Posted Image

Can anyone see where I am going wrong?

Rendering the depth buffer to texture using a FBO

10 January 2010 - 02:07 AM

Hi guys, I'm having trouble implementing a basic shadow mapping algorithm. At the moment I am trying to render the depth buffer to a texture and then render it to see if it is correct. I have been following the guide from here: http://www.fabiensanglard.net/shadowmapping/index.php When I render the depth texture to a quad I'm getting nothing. I have had render to texture working by rendering the colour buffer to texture and using the a renderbuffer for the depth. Here is the code I use to set up the texture and the FBO:-
void Scene::generateShadowFBO()
	int shadowMapWidth = 512;
	int shadowMapHeight = 512;
	GLenum FBOstatus;
	glGenTextures(1, &m_depthTexture);
	glBindTexture(GL_TEXTURE_2D, m_depthTexture);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
	// create a framebuffer object
	glGenFramebuffers(1, &m_shadowFBO);
	glBindFramebuffer(GL_FRAMEBUFFER, m_shadowFBO);
	// Instruct openGL that we won't bind a color texture with the currently binded FBO
	// attach the texture to FBO depth attachment point
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, m_depthTexture, 0);

	// check FBO status
	FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
	// switch back to window-system-provided framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glBindTexture(GL_TEXTURE_2D, 0);

I then render the fbo pass using:-
	glBindTexture(GL_TEXTURE_2D, 0);
	glBindFramebuffer(GL_FRAMEBUFFER, m_shadowFBO);
	glColorMask(false, false, false, false);
Then to render the texture to a quad I use:-
	glBindTexture(GL_TEXTURE_2D, m_depthTexture);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glColorMask(true, true, true, true);
The texture and viewport sizes are all the same and the fbo status test is saying it is complete. Can anyone see anything glaringly obvious that I am missing?

Problems creating new application with VS on Vista

11 July 2009 - 09:31 AM

Not strictly a programming problem but couldn't see of a more appropriate board to post on. Anyway.... I'm having a problem creating Win32 console or Windows apps. When I try to create the application two windows pop up -- One saying the navigation to the current page has been cancelled and the other opening up my browser with the project settings. However, the browser with the settings is not complete (there are actually no option, whereas you usually get MFC, blank proj etc..) . There is a finish button but it does nothing. This problem occurs on both VS2005 pro and VS2008 pro and is really p*ssing me off. It's a pain having to create a project on my laptop so that I can transfer it onto my main dev machine. However, I can create c# Windows Forms Applications just fine : I get the feeling this is actually some permission problem with Vista as a very similar thing happened when installing SP1 and repairing the VS installation. Anyone seen this or have any idea on how to fix it. I came across one guy who had the same problem after many hours of trying to fix it (and Ive lost the link now :@), but MS basically gave the response that they couldnt reproduce the problem and so no solution was given :( Uni