Skip to main content
gamedev.net
🔒 Locked

Untitled

Started by dgrat Dec 19, 2008 at 11:47 AM 0 replies 550+ views
Original Post
dgrat
dgrat
I have a nice Scene class, which consists of a skybox and a list of items.

class SceneGraphScene
{
private:
	SceneGraph *m_pParentGraph;

	/*
	 * list of items to draw
	 */
	std::vector<SceneGraphItem*> m_SceneGraphItems;

	/*
	 * list of light sources to draw
	 */
	std::vector<LightSource> m_LightSources;

	/*
	 * list of texture ids necessary to draw the sky box
	 */
	std::vector<GLuint> m_iSkyBoxT;
	void drawSkyBox();

public:
//**

	virtual void RenderScene();
};

my item class should do the render-jobs for parts of the scene. for example for models.

class SceneGraphItem
{
//..

public:
//..

	void RenderItem() const  {draw1();}
};
my problem occurs when i try to draw via RenderItem() function in my scene. All i do is to draw a cube. if i write the same code in the renderfunction of my scene i get more than 1000 fps. but if i try to draw like in the example (down) i only have 16 frames and render problems with my skybox. there is no additional code in the render function of my item. i only run the draw1() function. this is my function:

void SceneGraphScene::RenderScene()
{
	// Lichter setzen
	for(unsigned int i = 0; i < m_LightSources.size(); i++) {
		if(i < GL_MAX_LIGHTS) {
			//std::cout<<"set up new light source"<<std::endl;
			glLightfv(GL_LIGHT0 + i, GL_AMBIENT, m_LightSources.at(i).fLightAmbient);
			glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, m_LightSources.at(i).fLightDiffuse);
			glLightfv(GL_LIGHT0 + i, GL_POSITION, m_LightSources.at(i).fLightPosition);
			glEnable(GL_LIGHT0 + i);
		}
	}

	// Zeichne nun die Modelle
	for(unsigned int i = 0; i < m_SceneGraphItems.size(); i++) {
		m_SceneGraphItems.at(i)->RenderItem();
	}

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);// reset the color to white
}

inline void draw1()
{
    glPushMatrix();
    glBegin(GL_QUADS);
        // face v0-v1-v2-v3
        glNormal3f(0,0,1);
        glColor3f(1,1,1);
        glVertex3f(1,1,1);
        glColor3f(1,1,0);
        glVertex3f(-1,1,1);
        glColor3f(1,0,0);
        glVertex3f(-1,-1,1);
        glColor3f(1,0,1);
        glVertex3f(1,-1,1);

        // face v0-v3-v4-v6
        glNormal3f(1,0,0);
        glColor3f(1,1,1);
        glVertex3f(1,1,1);
        glColor3f(1,0,1);
        glVertex3f(1,-1,1);
        glColor3f(0,0,1);
        glVertex3f(1,-1,-1);
        glColor3f(0,1,1);
        glVertex3f(1,1,-1);

        // face v0-v5-v6-v1
        glNormal3f(0,1,0);
        glColor3f(1,1,1);
        glVertex3f(1,1,1);
        glColor3f(0,1,1);
        glVertex3f(1,1,-1);
        glColor3f(0,1,0);
        glVertex3f(-1,1,-1);
        glColor3f(1,1,0);
        glVertex3f(-1,1,1);

        // face  v1-v6-v7-v2
        glNormal3f(-1,0,0);
        glColor3f(1,1,0);
        glVertex3f(-1,1,1);
        glColor3f(0,1,0);
        glVertex3f(-1,1,-1);
        glColor3f(0,0,0);
        glVertex3f(-1,-1,-1);
        glColor3f(1,0,0);
        glVertex3f(-1,-1,1);

/..

    glPopMatrix();
}
How is this possible. The code is the same, why is the indirect call over the itemclass so slow ):
Pooya65
Pooya65
1. use vbo (vertex buffer object ) or displaylists for drawing quad (can help u t in performance)

2. dont set light data's in every frame

3. when u are using skybox u don't need to clear color buffer (this can help u to have better fps)

i think problem is in setting of light sources

do this jobs for have nice skybox:

1. disable lighting and fog when rendering skybox
2. disable depth write but not depth test
3. set size of cube
3. draw skybox
4. enable lights and fog and depth test

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.