   My graphics engine (complete source code)
  Hello everyone!  I have been working on a graphics engine from scratch (that I call AliquiX.  I'm bad at names...).  See details below.AliquiX Engine (Visual Studio 2003)Sample AliquiX App (Visual Studio 2003)The point of this post:I am asking experienced developers to look at my source code and help me code better.  I am looking for constructive criticism.  "Never do this...", "That's awful!", etc.  I have been programming for several years but only recently have I been serious about C++ and graphical development.  There is quite a bit of code here and you can look through it as deep as you like.I would also like comments on general design.  How I manage entities, the scene, system components, vertex data and uploading buffers, lights, etc.I hope that people new to this area of development can use my source code to learn how to solve certain problems and see how something might work.  Feel free to PM me or message here to ask any questions about it.I've never developed anything big or serious, so keep in mind that this is my first attempt at something like this.  I've thought hard about many aspects of its design, and I've been influenced by DirectX, Ogre, stuff you guys have said, and other articles on Gamedev.  This is something I'm going to use to create some things, and I'm really not striving for full portability or making it easy for everyone to use.Now to describe AliquiX.  It is an engine written in C++ that is far from being finished.  What it can do:Manage core components like the renderer, input, clock, scene, etc.A scene manager handles scene nodes that define hierarchal relationships as well as hierarchal transformations for objects.Entities define that objects that have some action to be taken each frame.  Entities are added to the scene by attaching them to a scene node.  Example entities:  Mesh, Light, Camera.Shaders are written separately and meshes can be assigned any shader at any time.  I will extend this to more an "effect" system where effects may run through multiple shaders for one object.Meshes are divided into chunks, and these chunks automatically manage their vertex data and give functions to deal with the data easily.  When a shader is run, it requests that the chunk upload the streams it needs to run (if not already uploaded).  The meshes can also interleave the data if it's not interleaved, or generate a new chunk to render its normals, etc.A resource manager deals with resources and re-uploading when needed.  Vertex and index buffers are dealt with abstractly by pre-allocating space on the video card and managing the space with the resource manager.The whole engine is written abstractly.  As of now there is only a DirectX renderer, but an OpenGL renderer is possible (though would be kind of difficult because the engine is similar to DX).  I wanted to write it abstractly to make things clear and easy, but I'm not really going for full cross-platform/cross-API support.There are still many things I need to implement, like model loading and better support for large static geometry.  I also need to improve the vertex buffer management scheme.  And then on to collision detection, spatial structures, etc.  But before I move on I'd like input on what's there.I've been asking questions on these forums for years, so I also want to say thanks for everyone who has helped me!  I love doing this stuff.  I hope others can benefit from my work.I've included a sample app at the top that would use this engine.  Here is an example of how I set up a scene:AXScene *Scene = AXBaseSystem::GetSceneMgr();Scene->AddSceneListener(new InputListener);AXSceneNode *Root = Scene->GetRoot();Root->CreateChildWithEntity(Scene->CreateEntity("Mesh", "Axes", "Axes"));AXEntity *Box = Scene->CreateEntity("Mesh", "RootBox", "Box");AXSceneNode *BoxNode = Root->CreateChildWithEntity(Box);AXLightEntity *Light1 = Scene->CreateLight("Light1");Light1->Type = AX_LIGHT_POINT;Light1->Dynamic = 1;AXSceneNode *LightNode = BoxNode->CreateChildWithEntity(Light1);LightNode->Translate(0.0f, 5.0f, 0.0f);AXSceneNode *LastBox = BoxNode;LastBox->Translate(0.0f, 0.0f, 5.0f);for(unsigned int i=0; i<50; i++) {std::string Name = "Box" + AXStringConvertFromInt(i);AXEntity *Box = Scene->CreateEntity("Mesh", Name, "Box");AXSceneNode *RotatingBox;RotatingBox = LastBox->CreateChildWithEntity(Box);RotatingBox->Rotate(AX_PI/15.0f, AXVector3(1.0f, 0.0f, 0.0f));RotatingBox->Translate(5.0f, 0.0f, 0.0f);LastBox = RotatingBox;}AXEntity *Camera = Scene->CreateCamera("Player", 50.0f);AXSceneNode *CameraNode = Root->CreateChildWithEntity(Camera);CameraNode->Translate(0.0f, 0.0f, -5.0f);Scene->ActivateCamera("Player");That scene creates a line of twisting boxes with a light rotating around the first one (the light is rotating because of code in a listener not listed here).Screenshot (not too exciting, but just an example):Thanks for everything.Edit:  Fixed a lot of things with lighting, it's pretty much implemented now (besides optimizing and such) Yay, fun![Edited by - okonomiyaki on June 2, 2006 3:28:01 AM]
  Looks like a great resource! I may browse through it for some ideas for my own engine.   ;  looks like extremly clean code(compared to my engine,which is also my first cpp project and looks like a spawn of hell regarding cleanliness). This is actually the first engine's source that i downloaded.regards,m4gnus   ;  Looks nice and clean from what I've looked at so far. I'm not very experienced with engine programming so I can't really comment on or criticize it but I'll keep on going through it in search of good (and bad) stuff :)   ;  Thanks guys!  I have a ton of stuff still to do with it, but I think I'm off to a right start.  My projects used to look like a spawn from hell, and I've been trying to code more clearly and cleanly.   ;  Hey, this is great stuff. I'm very impressed with your design and code cleansliness. It reminds me of Ogre! Great work! =)   ;  Looks like a tone of work done. And it's just ~6k LOC!A few random thoughts:1. Is it based on Enginuity?2. You put message pumping into your input class, not a window class. Interesting.3. Did you already put it to use in some project? I mean, did you find in practice what parts of the engine are very useful and handy, and which seem like a bargain (if any)?What, IMO, it lacks in terms of C++:1. const correctness - I guess you completely left it for now[grin], or, with all the internal caches possibly updating in anytime, it is plain impossible (think: mutable keyword).2. exception safety - this is much harded, possibly would require a major engine redesign.What is a must in terms of graphic engine:1. textures - y'know.2. render to texture - swapping buffers with the device.3. matrix stacks - make the app code much cleaner. If you ever used GL, you know what I mean.4. programmable shader support - y'know.Can't find anything more right now...Good luck!~def   ;  Looks like an excellent start!Just a suggestion: Instead of adding 'AX' to every class name, consider using an 'ax' namespace.   ;  Yes the AX is a finger breaker on the long run ^^One thing I have realized is, you use a lot of pointers.In my projects I make a lot use of stl containers and references, I am just sick of checking for null pointers everywhere, although they aren t required since references do the job pretty wellOther than that, its good that people release their sources from time to time, its always interesting how other solve problems  thx   ;  Looks very nice and clean.What did I miss language-wise:Use namespace instead of AX prefix.Use references instead of pointers if possible.Do not use so many macros. Eg. you have 4 LOG_SYSx, 4 LOG_APPx etc. macros.Add some comments [smile]. When I wrote my engine and got back to it after almost year it was pretty hard to remember what I did and why without comments. Later I spent few weeks adding comments to almost 12 KLOC of code, which was not too pleasant. So add them while it is not so much work and write new comments as you add new features. This will be especially important if you plan to publish source somewhere on the web.What features did I miss:Textures. You definitely need them.Statistics about engine (how many polys were submitted during frame, fps, memory usage etc.).File import, that is, you engine should be able to import some simple scene files (you can for example use ASE files from 3ds max because they are very easy to parse).Programmable shaders. Then you can remove FFP completely.Also, your test application is linked with debug version of DirectX dll. I don't have DX SDK installed so I was unable to run it.   