Archived

This topic is now archived and is closed to further replies.

Xiachunyi

Scene after scene clearification

Recommended Posts

Hi, (Don''t laugh) I was wondering how do you change scenes within your game. I''ve been wondering about this for quite sometime and always did it like so.
int DrawGLScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glColor3f(1.0,1.0,1.0);
        if(scene != 2)
        {
          //Draw stuff that will be present for scene 1 and 2
        }
        if(scene == 1)
        {
          //Draw stuff for this scene
        }
        else if(scene == 2)
        {
          //Draw stuff for this scene
        }
        else if(scene == 3)
        {
          //Draw more stuff for this scene
        }
}
 
Yea, it looks very wierd and sort of has the paucity of being "good code". Can anyone suggest what to do or point to an article containg information on how to draw seperate scenes, like introduction scene, control panel scene, battle scene, etc? Thanks.

Share this post


Link to post
Share on other sites
It's okay to do it like that, you can also use a switch to make things look nicer.

[edit] Oh forgot to mention you need to call glLoadIdentity();

[edited by - FtMonkey on July 2, 2003 11:13:16 PM]

[edited by - FtMonkey on July 2, 2003 11:14:19 PM]

[edited by - FtMonkey on July 2, 2003 11:21:45 PM]

[edited by - FtMonkey on July 2, 2003 11:34:35 PM]

Share this post


Link to post
Share on other sites
I assume by change scene you mean switch between screens. Like from your running game to your main menu? In that case I like to use enum.


enum GameState
{
Intro,
MainMenu,
Options,
Running,
//Other game states you might have here

};


GameState DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

switch (GameState)
{
case Intro:
//Draw Intro stuff

break;
case MainMenu:
//Draw Menu stuff

break;
case Options:
//Draw Options stuff

break;
case Running:
//Draw Game stuff

break;
}
}



And you could use the same game state enum to determine what to do with your input functions.

This method is pretty much the same as your but easier to read which might be nice if you need to make some changes in the future. Anywho just my 2 cents.



     Hope is the first step on the road to disappointment

Share this post


Link to post
Share on other sites
Okay, thanks a lot. I was wondering if there was a better way to do that since it looked a little too "basic". Yea,

if(scene != 2)
{
//Draw stuff that will be present for scene 1 and 2
}

Needs to be changed to present for 1 and 3.

Share this post


Link to post
Share on other sites
When I came across this problem, I decided that I would makea screen class which had basic virtual functions like Tick(), which were called every gameloop. This way the code looked like this:



class BaseScreen
{
virtual void Tick();
};

class MainMenuScreen
{
virtual void Tick(){RenderMenu();}
void RenderMenu();
};

class MainGameScreen
{
virtual void Tick(){RenderGUI(); MainGameLoop();}
void RenderGUI();
void MainGameLoop();
};

class App
{
MainMenuScreen mms;
MainGameScreen mgs;

BaseScreen *currentScreen;

void MainLoop()
{
currentScreen->Tick();
}
};

// somewhere else where the screen changes


app.currentScreen = &mms;


I preffer this method over the large switch block for many reasons. It is much more OO. Screens can inherit methods/dat members from other similar screens. Less work for the coder. Easier to read(no need to search inside a massive witch case block)... there are other benifits that I am too lazy to mention...

please let me know what you think of this method, as it seems to be non-standard

Dwiel

Share this post


Link to post
Share on other sites
Thanks a lot for the answers. The virtual function idea and the enum idea looks very neat. The enum looks like a table of contents and the virtual function idea does look like it could cut my work down. I''ll try these, thanks again.

Share this post


Link to post
Share on other sites