Jump to content
  • Advertisement
Sign in to follow this  
DocKode

designing an extremely simple graphics engine?

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello folks, Up until now all of my c++/OpenGL applications have been limited to a structure like the following: main.cpp (using GLUT) TextureLoader.cpp ModelLoader.cpp TextureLoader.h Texture.h (storage for textures) ModelLoader.h (storage for models, etc) I also had any additional classes that may have been of some use. What I want to do is divide my main.cpp up into a type of graphics core that I can use in all my projects. main.cpp is usually structured like this: include headers define variables loadTextures(){} loadModels(){} // this code just loops through the triangles of any mesh I pass it and helps remove the code from my render function drawMesh(){} RenderScene() { //opengl stuff drawMesh(); //opengl stuff } SetupRC(){} ChangeSize(){} main(){} ---------- Moving on... I want to use Win32 code instead of GLUT to handle my window creation from now on as well. With all that out of the way... how should I structure my project so that it is closer to the model that graphics engines use... ie. programLogic.cpp or main.cpp etc... whatever. graphicsCore.cpp LoadTexture.cpp LoadModel.cpp graphicsCore.h LoadTexture.h LoadModel.h ---------------- Please let me know if I'm not being clear. I don't need actual code here, just a way to structure my files and to know how those files might be structured so that things are a little easier to manage and so that I can pass my graphicsCore and loaders onto other projects in the future. like a very very simple graphics engine. :) no audio, no input, just rendering. Thanks for any and all the help you may offer.

Share this post


Link to post
Share on other sites
Advertisement
You could place all Win32 window initialization code in your main.cpp file, I don't see a problem there -- or did I miss what you were trying to ask?

Share this post


Link to post
Share on other sites
right... but where would i put my program logic, and what about my rendering code?

that's kind of what i'm after. :)

I mean think of the simplest graphics/rendering engine you can think of and how would you structure it. I'm fairly new to the concept of using engines.

Share this post


Link to post
Share on other sites
Ok, upon a second reading I think you're asking how to structure your overall engine code into separate .cpp files. It all depends on how you want to do it. If you want to go the object-oriented way you can create individual classes for each sub-system and create the objects in main.cpp, calling the functions when you need them. If you don't wish to go OOP you can create LoadTexture() and RenderObjects() (or whatever) functions and place them in the appropriate files, calling the functions when needed in the main loop (in main.cpp). I personally prefer the OOP approach and would be more than happy to write you up some sample structure code.

Hope that helps.

Share this post


Link to post
Share on other sites
yes!! I am all about OOP, I came from a Java background. :)

I would love to see samples on how to structure things.

Share this post


Link to post
Share on other sites
Is there a business reason for using Win32?

SDL does a perfectly good job of handling the window creation and updating stuff (ie. hiding the win32 specific calls and WndProc for example)..

Anyways, for projects like what it looks like you're doing, I have a central stdafx.h header file with the function declarations. Then every other .cpp file just includes that one.

main.cpp - game logic
graphics.cpp - rendering logic
sound.cpp - audio logic

etc..

hth,

Share this post


Link to post
Share on other sites
Ok, I cooked up some rough code for you to follow. I don't suggest copy and pasting it directly as I just wrote it in notepad and don't know if it's truly syntactically correct ;) It should however give you a basic idea of what to do, hope it helps.

main.cpp:
#include "graphicsCore.h"

bool MakeWindow();
bool MainLoop();
bool CleanUp();

bool GameRunning;

CGraphicsCore* gc;

int main()
{
//Create a new instance of the graphics core
gc = new CGraphicsCore();

//Put all your window initialization here
MakeWindow();

//Initialize the render scene
gc->InitializeScene();

GameRunning = true;

//Enter the main loop
MainLoop();

//Once MainLoop() returns we can CleanUp();
CleanUp();
};


bool MainLoop()
{
//Note: Your windowing code may play a part in how you
//do your main loop.

while(GameRunning == true)
{
gc->RenderScene();
}

return true;
};

bool CleanUp()
{
delete gc;
gc = 0;
return true;
};




graphicsCore.cpp:
#include "graphicsCore.h"

bool CGraphicsCore::InitializeScene()
{
//initialize the scene, whatever that may mean to you
return true;
};

bool CGraphicsCore::RenderScene()
{
//render the scene
return true;
};

bool CGraphicsCore::DestroyScene()
{
//clean up the mess you made ;)
return true;
};




graphicsCore.h:
class CGraphicsCore
{
public:
CGraphicsCore(){};
~CGraphicsCore(){};

bool InitializeScene();
bool RenderScene();
bool DestroyScene();
};

Share this post


Link to post
Share on other sites
You know, this is just the sort of thing I've been looking for as well. Hope you don't mind if I use a similar style,cvg_james...?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!