Jump to content

  • Log In with Google      Sign In   
  • Create Account


MrSimon

Member Since 16 Mar 2012
Offline Last Active Aug 28 2012 12:52 PM
-----

Posts I've Made

In Topic: Nested Classes ~ I think

11 May 2012 - 06:13 AM

It all works now.

I needed the correct order of assignments, in the correct place in regards to the object calls.

It works now. Yay!

I've only been using c++ for a few weeks, but I'm getting really really good at diagnosing errors!!!!

It's a start!

In Topic: Nested Classes ~ I think

11 May 2012 - 05:04 AM

Hi there. Sorry for the late reply.

I managed to get it working on my own, though essentially I have done what you describe in the second method.

I am having another problem though.

I have my gameengine class create pointers to the renderengine, the gamestates and now the eventengine.

The gameengine constructor creates new instances of the renderengine, the gamestate and the event engine.

The gameengine destructor deletes these instances.

The gamestate class creates a pointer to renderengine, and is now able to access it to do rendering. The gamestate class also creates a pointer to the eventengine class and is able to access that.

However, even though i create pointers in the event engine class (even copying and pasting the same declarations) the event engine is unable to access the functions of the other objects. It compiles, but I am getting bad access errors, which so far have usually been caused by empty pointers.

In pseudo code, if it helps.

class cGameEngine
{
	cGameEngine();
	void Function();
	cEventEngine* EventEngine;
	cRenderEngine* RenderEngine;
	cGameState* GameState;
};
cGameEngine::cGameEngine()
{
	EventEngine = new cEventEngine;
	RenderEngine = new cRenderEngine;
	GameState = new cGameState;
};
cGameEngine::~cGameEngine()
{
	delete EventEngine;
	delete RenderEngine;
	delete GameState;
};
void cRenderEngine()
{
	//Do Something...
};
class cRenderEngine
{
	void Function();
};
void cRenderEngine::Function()
{
	//Render Something...
};
class cGameState
{
	void GetEvents();
	void GetRendering();
	cRenderEngine* RenderEngine;
	cEventEngine* EventEngine;
};
void cGameState::GetEvents()
{
	EventEngine->Function();
};
void cGameState::GetRendering()
{
	RenderEngine->Function();
};
cGameEngine* Game = new GameEngine;
int main()
{
	while(running)
		{
			Game->GameState->GetRendering();
				// ^ This works!
			Game->GameState->GetEvent();
				// ^ This doesn't work!
		};
	delete Game;
};

If I change the event engine function to render (like the render engine function) it fails here too with the same error. I can follow the processes with the debugger, and it is following the references through the gameengine to the gamestate to the render engine, and it is following the process through the gameengine to the gamestate to the eventengine, but the pointers at the eventengine are coming up empty.

Game engine > game state > render engine > to render engine function

Game engine > game state > event engine > empty pointers.

Sorry that I have basically tried to explain the same problem over and over. I want to make it clear.

Thanks in advance for any help offered.

Simon

In Topic: VBO error

06 May 2012 - 03:27 AM

And that did it.

As promised, I will bugger off for a while.

Thanks guys. You really are brilliant.

In Topic: VBO error

05 May 2012 - 09:24 AM

OK. I have one more. After this, I promise, I'll leave you all alone.

VBO works, colours work, IBO works. Texture doesn't work?

Any ideas what's wrong?

struct float3
 
{
 
  float x, y, z;
 
};
 
struct float2
 
{
 
  float x, y;
  
};
struct sVertex
{
 
  float3 Position, colours, normals;
 
  float2 Texture;
};
 
struct sPolygons
 
{
 
  int x, y, z;

  //float Normal;
 
};
class cModel
{
 
  private:
 
   GLuint TextureID;
 
   GLuint VBOID;
  
   GLuint IBOID;
  
   int nVertices, nPolygons;
  
   unsigned char* TextureData;
  
  public:

   cModel(int nVertices, sVertex Vertices[], int nPolygons, sPolygons Polygons[], const char * TextureFile, int TextureWidth, int
TextureHeight);
 
   void Update();
  
   void Render();

};
cModel::cModel(int numVertices, sVertex Vertices[], int numPolygons, sPolygons Polygons[], const char * TextureFile, int TextureWidth, int
TextureHeight)
{
nVertices = numVertices;

glGenBuffers(1, &VBOID);

glGenBuffers(1, &IBOID);
	   
glBindBuffer(GL_ARRAY_BUFFER, VBOID);

glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(sVertex), Vertices, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);

nPolygons = numPolygons;

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOID);

glBufferData(GL_ELEMENT_ARRAY_BUFFER, numPolygons*sizeof(sPolygons), Polygons, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

FILE * file = NULL;
file = fopen(TextureFile, "rb");
TextureData = new unsigned char [TextureWidth * TextureHeight * 3];
   
fread(TextureData, TextureWidth * TextureHeight * 3, 1, file);

fclose(file);

glGenTextures(1, &TextureID);

glBindTexture(GL_TEXTURE_2D, TextureID);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureWidth, TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureData);

};
void cModel::Render()
{
glBindBuffer(GL_ARRAY_BUFFER, VBOID);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOID);

glBindTexture(GL_TEXTURE_2D, TextureID);

glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_COLOR_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	   
glVertexPointer(3, GL_FLOAT, 11*sizeof(float), (char*)NULL+0);

glColorPointer(3, GL_FLOAT, 11*sizeof(float), (char*)NULL+3*sizeof(float));

glTexCoordPointer(2, GL_FLOAT,11*sizeof(float), ((char*)NULL)+9*sizeof(float));
 
glDrawElements(GL_TRIANGLES, nPolygons*3, GL_UNSIGNED_INT, 0);
 
//glDrawArrays(GL_TRIANGLES, 0, nVertices);
			   
glDisableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
};
sVertex Vertices[3] =
{
{{0.0f, 5.0f, -1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},

{{5.0f, -5.0f, -1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, 0.0f}},

{{-5.0f, -5.0f, -1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}
};
sPolygons Array2[1] =
{
{0, 1, 2}
};

I really promise, this will be the last thing for a while (a little while anyway).

In Topic: VBO error

05 May 2012 - 08:00 AM

And now it works.

Thank you guys.

I should be quiet for a couple of days while I try to work out loading textures! :)

Thanks again guys. You make a difficult process (for me anyway - it's only been a week, so far) a whole lot easier.

PARTNERS