Hi,
I have a serious (yeah, Serious Sam is my favorite game) design question:
I''m trying to make it possible to use multiple different apis for the graphics. I basically do this by defining a purely virtual base class GfxSystem and deriving classes like SdlGLGfxSystem from it, which implements a GfxSystem using OpenGL through SDL.
Now, how should I draw stuff, like models? I want to make it possible using multiple APIs, so I can''t make a drawing function a part of the Model class which calls the OpenGL drawing functions. I could make a drawModel function part of the GfxSystem, but it doesn''t have access to the vertex, face and texturing data of the Model because they''re private (do you think that''s reasonable?). So a copying function would need to be part of Model, but that would be really slow, wouldn''t it.
I could also make a function in GfxSystem which draws a single face, but since it''s a virtual function, it might be slow - for every single face...
So, how should I solve it? How have you solved this problem earlier? I''m thankful for advice!
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
Design question - drawing something
BUMP
Help, I need advice! Please - just tell me how you have solved this problem in earlier projects!
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
Help, I need advice! Please - just tell me how you have solved this problem in earlier projects!
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
newbie opinion:
I think that if you define you var has protected you can access it whit a virtual function in the derived class! That function will be diferent for each derived class and could solve your problem...
that should be it...
----------
[ladrilho]
I think that if you define you var has protected you can access it whit a virtual function in the derived class! That function will be diferent for each derived class and could solve your problem...
that should be it...
----------
[ladrilho]
I''m doing this for the first time too, so this just my way of doing it, but I guess you might get some idea at least.
I also use a virtual base class ( CGraphicsDevice ), and I''ve currently done a basic DirectX9 implementation. The way I handle models ( or any 3d objects ) is in a vertex array, I have a CreateVertexArray function that returns a handle to a vertex buffer, so the client doesn''t need to know anything about how the data is stored in the graphics object. So a model is basicly whatever values you need and a handle to a vertex array, and when rendering you call graphicsDevice->RenderVertexArray. I''m also working on getting index arrays in, but that doesn''t work yet. Oh, and the data ( vertices, triangles, materials, .. ) I feed into CreateVertexArray is in a common format of course, so the client needn''t bother at all about the implementation.
Hope this helped some
I also use a virtual base class ( CGraphicsDevice ), and I''ve currently done a basic DirectX9 implementation. The way I handle models ( or any 3d objects ) is in a vertex array, I have a CreateVertexArray function that returns a handle to a vertex buffer, so the client doesn''t need to know anything about how the data is stored in the graphics object. So a model is basicly whatever values you need and a handle to a vertex array, and when rendering you call graphicsDevice->RenderVertexArray. I''m also working on getting index arrays in, but that doesn''t work yet. Oh, and the data ( vertices, triangles, materials, .. ) I feed into CreateVertexArray is in a common format of course, so the client needn''t bother at all about the implementation.
Hope this helped some
Hmm, an idea has just occured to me: Why don''t I just give the Model class a vertexData() function that returns a const reference to the vertex data, etc.? It''s everything I need- the graphics system can read the data, and there''s no time wasted on copying lots of memory.
Thanks both of you.
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
Thanks both of you.
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
Hmm, I''m having some problems implementing my above idea:
I get the following compiler error:
"passing `const Model'' as `this'' argument of `const class vector > & Model::getVertices()'' discards qualifiers"
and the same error a second time for Model::getFaces()
If I get the error message right, the problem is that the Model I have is const. But what is wrong with that?
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
I get the following compiler error:
"passing `const Model'' as `this'' argument of `const class vector > & Model::getVertices()'' discards qualifiers"
and the same error a second time for Model::getFaces()
class Model{ private: vector<Vertex> vertices; vector<Face> faces; public: const vector<Vertex>& getVertices(void) { return vertices; } const vector<Face>& getFaces(void) { return faces; }};void SdlGLGfxSystem::drawModel(const Model& model){ // This causes the error: const vector<Vertex>& vertices = model.getVertices(); const vector<Face>& faces = model.getFaces();}
If I get the error message right, the problem is that the Model I have is const. But what is wrong with that?
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
quote:Original post by randomZ
Hmm, I''m having some problems implementing my above idea:
I get the following compiler error:
"passing `const Model'' as `this'' argument of `const class vector > & Model::getVertices()'' discards qualifiers"
...
If I get the error message right, the problem is that the Model I have is const. But what is wrong with that?
Thought I''d resurrect this, since you never got an answer.
The functions in question are not marked const, which means they are saying "this function may modify the object it''s called on". Which, in turn, means you cannot call those functions for a const object of that type. Hence the errors.
The solution in your case is to mark the functions as const, since they do not modify the object.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Thanks, although I already got an answer in another thread. I''m still not much further than this, but that''s more because I haven''t had much time to program lately...
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement