Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Ahl

Member Since 02 Jul 2007
Offline Last Active Jun 21 2015 04:47 PM

Topics I've Started

Creating/Using a console buffer?

19 June 2015 - 09:10 PM

I've been searching around, looking for a way to generate, write too and flip between console buffers.  The best I've found consists of simply building a giant string and Console.Write()ing it all in one go or generating an array of class objects that contain the character, X and Y position and a single Color attribute and pushing it to a console buffer handle.  Asside from the fact that that single color attribute only covers text color and not background color, it seems like there should be an easier way to do this.

 

Thoughts?


Mediator Pattern Help!

27 May 2014 - 09:47 PM

Hey all,

 

I'm writing a Mediator class in C++ and am having trouble with a part of it.  I've done this before in C# (which was really easy) and trying to do the same thing in C++ is kicking my butt.  I have a std::map that contains a std::string for the key and a std::vector<> for the value.  The idea being any number of functions/methods can be registered under any number of keys and all said functions/methods can be invoked with one call.

 

I'm having two primary problems:  1, I can't figure out how to get both functions AND class methods into the std::map.  Currently I'm using:

typedef std::function<void(void* Object)> FunctionDef;

I have a Register method in my Mediator class that takes a std::string for the key and a FunctionDef for the value.  So far this works fine for functions but I can't get it to work with class methods.

 

And 2;  I have an Unregister method in my Mediator class that takes the same inputs and removes the appropriate function from the appropriate key.  Or, at least, it's supposed too. 

template<class T>
static void Unregister(std::string Key, T Function)
{
		if (MediatorMap.count(Key) != 0)
		 {
			FunctionDef Func = Function;
			for (std::vector<FunctionDef>::iterator It = MediatorMap[Key].begin();
				It != MediatorMap[Key].end();
				++It)
			 {
				 if ((*It).target_type().name() == Func.target_type().name())
				{
					std::cout << "1" << std::endl;

					std::cout << (*It).target<T>() << " == " << Func.target<T>() << " ?? \n";
					if ((*It).target<T>() == Func.target<T>())
					{
						std::cout << "2" << std::endl;
					}
				}
			}

			if (MediatorMap[Key].size() == 0)
			{
				MediatorMap.erase(MediatorMap.find(Key));
			}
		}
	}

This is basicaly just testing code ATM.  The problem seems to be, and mind you I can only test this with functions, that whatever info is provided by .target<T>() (I'm guessing the pointer) never matches, even when sending the same function.

 

I admit to not really being sure of what I'm doing.  This is new territory for me and my C++ is a little rusty.  Any help would be appreciated.


A few questions on binding VBOs...

24 December 2012 - 10:11 PM

Hey all,

 

The question isn't so much how to do it, I've figured that out, it's how you unbind a VBO and why having a bound VBO seems to block the usage of Vertex Arrays?

 

I have the following code in my rendering function:

 

if (VBO_Support)
				{
					glVertexPointer(	3,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*) (*RenderListIT)->RenderMesh->VBO_Offset					);
					glNormalPointer(		GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*3)	);
					glTexCoordPointer(	2,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*6)	);
					glColorPointer(		3,	GL_FLOAT,	sizeof(MyVertex),	(GLvoid*)((*RenderListIT)->RenderMesh->VBO_Offset+sizeof(float)*8)	);
				}
				else
				{
					glVertexPointer(	3,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->x		);
					glNormalPointer(		GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->nx	);
					glTexCoordPointer(	2,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->u		);
					glColorPointer(		3,	GL_FLOAT,	sizeof(MyVertex),	&(*RenderListIT)->RenderMesh->VertexData->a		);
				}

And I have a toggle that changes VBO_Support back and forth.  When I have a VBO bound (glBindBufferARB()) and VBO_Support = true everything runs fine but none of my objects display.  Why is that?

 

Thanks in advance.


Best method for a top down, side scrolling camera.

18 October 2012 - 09:15 PM

Ive seen examples using gluLookAt(), glOrtho(), gluOrtho2d(), etc. One example I saw said all you need is to just use glTranslate(). So what is presently the best, easiest method to achieve this effect?

Thanks in advance.

VBO help...

18 September 2012 - 11:43 AM

Having trouble getting my VBOs to work. No compiler errors. No run time errors. Just nothing showing up on the screen. VA's work though. I'm wondering if my implementation is the issue. I'll try to explain as best I can...

All the model information gets stored in the following:

struct MyVertex
{
float x, y, z;  // Vertex
float nx, ny, nz; // Normal
float u, v;   // Texcoords
float a, r, g, b; // Color
float padding[4];
};

This is how I load the VBO:

for (Itter = Mesh_Multimap.begin(); Itter != Mesh_Multimap.end(); ++Itter)
{
  VBO_Size += (*Itter).second->NumVerticies*sizeof(MyVertex);
}
glGenBuffersARB( 1, &VBO_ID );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBO_ID );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, VBO_Size, NULL, GL_STATIC_DRAW_ARB );
for (VBO_Vector_IT = VBO_Vector.begin(); VBO_Vector_IT != VBO_Vector.end(); ++VBO_Vector_IT)
{
   glBufferSubDataARB( GL_ARRAY_BUFFER_ARB, VBO_Offset, (*VBO_Vector_IT)->NumVerticies*sizeof(MyVertex), (*VBO_Vector_IT)->VertexData );
   (*VBO_Vector_IT)->VBO_Offset = VBO_Offset;
   VBO_Offset += (*VBO_Vector_IT)->NumVerticies*sizeof(MyVertex);
}

Rendering:

glVertexPointer( 3, GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );
glNormalPointer(  GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );
glTexCoordPointer( 2, GL_FLOAT, 0, &(*RenderListIT)->RenderMesh->VBO_Offset );

That's the point that's giving me pause. When just rendering with VAs I need to do the following:

glVertexPointer( 3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->x  );
glNormalPointer(  GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->nx  );
glTexCoordPointer( 2, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->u  );
glColorPointer(  3, GL_FLOAT, sizeof(MyVertex), &(*RenderListIT)->RenderMesh->VertexData->a  );

I had to specify what part of the struct to pull the appropriate data from. Am I supposed to be doing this with the VBOs somehow? What am I missing?

PARTNERS