Ahl

Members
  • Content count

    144
  • Joined

  • Last visited

Community Reputation

170 Neutral

About Ahl

  • Rank
    Member
  1. 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?
  2. 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.
  3. 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.
  4. Alright, then I need to figure out what I'm doing wrong. I have the following: [CODE] void RenderScene() { std::sort (RenderList.begin(), RenderList.end(), SortRenderList); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0f, 1.0f, 1.0f); glLoadIdentity(); glTranslatef(MyCamera->GetPosX(), MyCamera->GetPosY(), MyCamera->GetPosZ()); uintptr_t LastKey = (uintptr_t)-1; uintptr_t LastMeshKey = (uintptr_t)-1; uintptr_t LastTexKey = (uintptr_t)-1; uintptr_t LastMatKey = (uintptr_t)-1; for (RenderListIT = RenderList.begin(); RenderListIT != RenderList.end(); RenderListIT++) { glPushMatrix(); glLoadIdentity(); glTranslatef((*RenderListIT)->Position->x, (*RenderListIT)->Position->y, (*RenderListIT)->Position->z); glScalef ((*RenderListIT)->Scale->x, (*RenderListIT)->Scale->y, (*RenderListIT)->Scale->z); glRotatef ((*RenderListIT)->Rotation->x, 1.0f, 0.0f, 0.0f); glRotatef ((*RenderListIT)->Rotation->y, 0.0f, 1.0f, 0.0f); glRotatef ((*RenderListIT)->Rotation->z, 0.0f, 0.0f, 1.0f); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnable(GL_LIGHTING); if ((*RenderListIT)->Key != LastKey) { LastKey = (*RenderListIT)->Key; DrawCalls++; if ((*RenderListIT)->RenderMesh->Materials->Key != LastMatKey) { LastMatKey = (*RenderListIT)->RenderMesh->Materials->Key; if ((*RenderListIT)->RenderMesh->HasMaterials == true) { glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (*RenderListIT)->RenderMesh->Materials->Diffuse ); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (*RenderListIT)->RenderMesh->Materials->Specular ); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (*RenderListIT)->RenderMesh->Materials->Ambient ); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (*RenderListIT)->RenderMesh->Materials->Emission ); } } if ((*RenderListIT)->RenderMesh->Key != LastMeshKey) { LastMeshKey = (*RenderListIT)->RenderMesh->Key; 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 ); } } if ((*RenderListIT)->RenderMesh->Active->Key != LastTexKey) { LastTexKey = (*RenderListIT)->RenderMesh->Active->Key; if ((*RenderListIT)->RenderMesh->HasTexture == true) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, (*RenderListIT)->RenderMesh->Active->TextureHandle); } else { glDisable(GL_TEXTURE_2D); } } } glDrawArrays(GL_TRIANGLES, 0, (*RenderListIT)->RenderMesh->NumVerticies); glPopMatrix(); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisable(GL_LIGHTING); } [/CODE] And it's not moving the screen. HELP!
  5. I understand the camera class. My question is what OpenGL commands to use.
  6. 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.
  7. I haven't been able to find one. I tried writing one myself which proved to be an exercise in futility. Assimp isn't incredibly difficult for simply loading models and once you get the wrapper done you can use any model type Assimp supports.
  8. VBO help...

    [quote name='BitMaster' timestamp='1348039369' post='4981577'] [quote name='Ahl' timestamp='1348017039' post='4981497'] [CODE] 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]; }; [/CODE] Keep in mind that this is my data structure. An array of this is what is being loaded into the buffer, so the offset will be the same for all of the vertexs/normals/texcoords/etc per model. [/quote] No. If vertex data starts at offset 0 (the most common case in that scenario), then normal data starts at offset 0 + sizeof(float) * 3 and so on. Otherwise your normals are always your positions of the same vertex, your texture coordinates are just your (x, y) coordinates of the same vertex and your colors are the (x, y, z, nx) coordinates of the same vertex. Setting the stride to sizeof(MyVertex) was correct but only half the problem. [/quote] Boom! That did it. Thank you very much!
  9. VBO help...

    [CODE] 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]; }; [/CODE] Keep in mind that this is my data structure. An array of this is what is being loaded into the buffer, so the offset will be the same for all of the vertexs/normals/texcoords/etc per model. I figured out another problem. I had the stride set to 0. I set it to sizeof(MyVertex) and now my model is coming up properly. The textures are still wonky though. It's doing now what it was doing before when we figured out I had to do the whole &(*RenderListIT)->RenderMesh->VertexData->x bit.
  10. VBO help...

    Yeah, still getting garbled models, even when just loading one. I have this sneaky suspician that it has to do with not being able (or not know how) to specift what part of my struct each pointer needs to be using...
  11. VBO help...

    Ooh, good catch. Didn't even see that. I converted it over from where I needed it for the VAs and forgot about that. Thank you. Stuff is showing up now but it's all scrambled...
  12. 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: [CODE] 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]; }; [/CODE] This is how I load the VBO: [CODE] 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); } [/CODE] Rendering: [CODE] 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 ); [/CODE] That's the point that's giving me pause. When just rendering with VAs I need to do the following: [CODE] 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 ); [/CODE] 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?
  13. But would it be fast? Sorting by a single number is really fast.
  14. So hashing is probably not the right word to use. I'll try to explain this in regards to my needs: I'm writing the graphics handling code for my project. I have a vector of RenderObjects. Each RenderObject has pointer to a Model, Texture, Material and Shader object which are all stored in another container. It also has a key that the vector is sorted by. The Key is made up of some form of unique identifier from each of those 4 objects with the Model identifier in the most significant bits followed by Material, Texture then Shader. The example I was following (which I cannot find now, should have book marked it) used various bit manipulations of the pointer to generate this key. The result, when the vector is sorted using this key, has all like models/textures/materials/shaders lumped together to minimize OpenGL calls. No need to load a model or bind a texture that's already loaded/bound, right?
  15. I'm trying to generate a unique key from the pointers of various objects for the sake of sorting by catagory, sub catagory, etc. They key itself will be 32bit. For the sake of this question let's say I have a Car object made up of various Make, Model, Color, Package objects. That Car object is put into a Vector and sorted so that all the given catagories are lumped together appropriately. If I only have a total of 8 Makes, and the Make is our most important catagory to sort by, then I use the 4 most significant bits of our key. If I have 100 models per make thats the next 7 bits. 20 colors per model is the next 5 bits. So on. Where my question comes in is this. If I'm using a 32 pointer for my Make, Model, Color, Package objects, I need to somehow reduce that size down to the size of associated bits in the key. So for my Make bits I need to reduce the size of my Make pointer down to 4 bits and still maintain some level of integrity in regards to it's uniqueness. For obvious reseaons I can't have my Ford and Chevy come out the same at 4 bits. The method I've been playing with so far has looked something like this: I take bottom 16 bits of my pointer and AND them together with my top 16 bits. So: TempID = MakeID & 0x000fff TempID <<= 16 MakeId &= TempID At this point it seems to me (and please correct me if I'm wrong) that there is only one other pointer that would give me the same result and the statistical probability of getting that pointer would be incredible minute. But I need it to be 4 bits and not 16. So I can do that two more times. What I'm worried about is the ability to maintain the unique-ness and how important that unique-ness is in terms of the statistical possibility of getting identicle results from another pointer. I hope this all makes sense. It's giving me a headache just thinking about it. lol.