Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mr. Big

Member Since 02 Apr 2011
Offline Last Active May 02 2013 08:34 PM

Topics I've Started

Drawing 2D in 3D World (2.5D)

27 April 2013 - 12:03 AM

Basically I've come across a few games that use this convention, and I'm curious on how its done and want to implement it.


Something similar to this;

This video seems to have accomplished it really well. There are a lot of pretty bad implementations of it too.


I just want to know where to start, what to look out for, any tips or advice.



Terrain generation in 3D Tile Based Game

23 April 2013 - 07:37 AM

Hello everyone. First time XNA project here, so still learning the ropes.


My first idea for a starter project was to make a tile based game. Each movable terrain square would be one quad (or 2 triangles).

Then use some method to determine which tile the mouse is over and clicking it moves the player there.



So what would be the ideal way to do this in XNA? My first thought was to create a triangle strip and a text file with all the vertices and heights and load it in and draw it.


Any other suggestions?

Passing Lua Array to C++ Array

28 October 2011 - 08:45 PM

I have no idea why this wont work. Needs a new set of (more experienced) eyes to take a look at it.

Lua table;
maplist = {"sand.obj", "jungle.obj", "cubes.obj"}


	//populate the map list array
	stringw maplist[50];
	int i = 0;

	lua_getglobal(L, "maplist");

	while(lua_next(L, -2))
		maplist[i] = (stringw)lua_tostring(L, -1);

		lua_pop(L, 1);
	lua_pop(L, 1);

Basically its just filling the array with random garbage.
If i change it to maplist[0] it works. (obviously overwrites it twice though)

Any tips? Maybe even a better way to do it?

Edit: Ok? Not initializing the array was apparently the problem. *shrug* Resolved now, I guess?

CG Shader with Textures problems.

02 April 2011 - 05:59 AM

So its come to this. Posting a help topic on GameDev!

I'm pretty new to CG, and my work is based on about 3 of my projects merged with mixed success.

So whats happening is the fragment shader is sortof working, I can see its doing something. However when I try to add the textures into the mix it decides there is an Invalid Program Handle.

The .cg file;
struct vertex
	float4 position : POSITION;
	float4 normal   : NORMAL;
	float4 color0   : COLOR0;
	float2 texCoord : TEXCOORD0;

struct fragment
	float4 position : POSITION;
	float4 color0   : COLOR0;

fragment main( vertex IN, 
       		uniform float4x4 modelViewProjection,
       		uniform float4x4 modelViewInverse,
		       uniform float4 eyePosition,
       		uniform float4 lightVector,
       		uniform sampler2D decal : TEX0)
	fragment OUT;

	OUT.position = mul( modelViewProjection, IN.position );

	// Transform normal from model-space to view-space
	float4 normal = normalize( mul( modelViewInverse, IN.normal ).xyzz );

	// Store normalized light vector
	float4 light = normalize( lightVector );

	// Calculate half angle vector
	float4 eye = eyePosition;
	float4 half = normalize( light + eye );
	// Calculate diffuse component
	float diffuse = dot( normal, light );

	// Calculate specular component
	float specular = dot( normal, half );
	specular = pow( specular, 32 );

	// A little ambient color
	float4 ambientColor = float4( 0.2, 0.2, 0.2, 0.2 );

	// White specular
	float4 specularMaterial = float4( 1.0, 1.0, 1.0, 1.0 );

	// Combine diffuse and specular contributions and output final vertex color
	OUT.color0 = diffuse * IN.color0 + specular * specularMaterial + ambientColor;
	//OUT.color0 = diffuse * tex2D(decal,IN.texCoord) + specular * specularMaterial + ambientColor;

	return OUT;

So see where I commented out "OUT.color0 = diffuse * tex2D(decal,IN.texCoord) + specular * specularMaterial + ambientColor;". If i leave it uncommented I get the model rendered with what looks like some form of shading. If I uncomment, I get Invalid Program Handle. I dont know if this is the best way to be doing things, I've had very little theory on shaders and just reading others' code.

Heres the rest of the code.

Snippet from the Header file;
static CGparameter modelViewProjection;

static CGparameter myCgFragmentParam_decal;

static CGparameter modelViewInverse;
static CGparameter CGeyePosition;
static CGparameter CGlightVector;

static CGprofile g_CGprofile;
static CGcontext g_CGcontext;
static CGprogram g_CGprogram;

Snippet from the Initializer;
	g_CGprofile = CG_PROFILE_ARBVP1;

	g_CGcontext = cgCreateContext();
	checkForCgError("creating context");

	g_CGprogram = cgCreateProgramFromFile( g_CGcontext,
									       NULL );
	checkForCgError("creating program");

	cgGLLoadProgram( g_CGprogram );
	checkForCgError("loading program");

	modelViewProjection = cgGetNamedParameter( g_CGprogram, "modelViewProjection" );
	modelViewInverse = cgGetNamedParameter( g_CGprogram, "modelViewInverse" );
	CGeyePosition = cgGetNamedParameter( g_CGprogram, "eyePosition" );
	CGlightVector = cgGetNamedParameter( g_CGprogram, "lightVector");
	checkForCgError("naming params");

	myCgFragmentParam_decal =cgGetNamedParameter(g_CGprogram, "decal"); //texture
	checkForCgError("getting decal parameter");//texture

	cgGLSetTextureParameter(myCgFragmentParam_decal, 1);//texture
	checkForCgError("setting decal 2D texture");//texture

The error CG throws is "creating program" Invalid Program Handle.

Snippet from the Rendering loop;

	glMatrixMode( GL_MODELVIEW );
	glTranslatef( 0.0f, 0.0f, -200.0f );

						     	CG_GL_MATRIX_IDENTITY );

	cgGLSetStateMatrixParameter( modelViewInverse,
                         		CG_GL_MATRIX_INVERSE_TRANSPOSE );

	float fEyePosition[] = { 0.0f, 0.0f, 0.0f, 0.0f };
	float fLightVector[] = { 0.0f, 0.0f, 1.0f, 0.0f };

	// Normalize light vector
	float fLength = sqrtf( fLightVector[0]*fLightVector[0] +
                   		fLightVector[1]*fLightVector[1] +
                   		fLightVector[2]*fLightVector[2] );
	fLightVector[0] /= fLength;
	fLightVector[1] /= fLength;
	fLightVector[2] /= fLength;

	cgGLSetParameter4fv( CGeyePosition, fEyePosition );
	cgGLSetParameter4fv( CGlightVector, fLightVector );

	cgGLBindProgram( g_CGprogram );
	cgGLEnableProfile( g_CGprofile );

	checkForCgError("enable decal texture");

	//now draw all the stuff

	cgGLDisableProfile( g_CGprofile );
	checkForCgError("disabling decal texture");

	checkForCgError("disabling decal texture");


Any help here would be greatly appreciated. At least a point in the right direction.
Originally I had a separate vertex and fragment shader but I was having some problems and ended up rewriting it like this. It was working all well and good until I decided to implement textures. I'm thinking this could be the problem, because at the creating program part there is no entry function declared - does there need to be one for it to work with textures? I can't do it the way I have it now?