How rendering a fixed part of scene in the background (which not change) and the second part in foregound (that change)?

  • Follow


For simplicity, the scene in the background is the Cone and the scene
in the foregorund is Torus.
I thought to render the cone in an auxiliary buffer (function init)
that is performed only once. In the display function, copy the cone
from the auxiliary buffer, after rendering the torus. I do not
understand what I am wrong, but that does not work. Thank you for your
help.
--------------------------------------------------------------------------------------------------------------------------------------------
#include <GL/glut.h>
#include <stdlib.h>

int g_w=0;
int g_h=0;

void init (void){
	GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
	glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
	glLightfv (GL_LIGHT0, GL_POSITION, light_position);
	glEnable (GL_LIGHTING);
	glEnable (GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);


	//This is the scene of the background that not change:
	//-----------------------------------------------------------------------------------------------
	glDrawBuffer(GL_AUX1);
	glClearColor (1.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
	glPushMatrix ();
		glTranslatef (-0.75, -0.5, 0.0);
		glRotatef (270.0, 1.0, 0.0, 0.0);
		glutSolidCone (1.0, 2.0, 15, 15);
	glPopMatrix ();
	glReadBuffer(GL_FRONT);
	//----------------------------------------------------------------------------------------------

}

void display (void){
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//---------------------------------------------------------------------------------------------
	glReadBuffer(GL_AUX1);
		glCopyPixels (0, 0, g_w, g_h, GL_COLOR | GL_DEPTH);
	glDrawBuffer(GL_FRONT);
	//--------------------------------------------------------------------------------------------

	glPushMatrix();
		glRotatef (20.0, 1.0, 0.0, 0.0);

		glPushMatrix();
			glTranslatef (-0.75, 0.5, 0.0);
			glRotatef (90.0, 1.0, 0.0, 0.0);
			glutSolidTorus (0.275, 0.85, 15, 15);
		glPopMatrix ();
		/*
		glPushMatrix ();
			glTranslatef (-0.75, -0.5, 0.0);
			glRotatef (270.0, 1.0, 0.0, 0.0);
			glutSolidCone (1.0, 2.0, 15, 15);
		glPopMatrix ();
		*/
	glPopMatrix ();
	glFlush ();
}

void reshape(int w, int h){

	g_w=w;
	g_h=h;
	glViewport (0,0,(GLsizei)w,(GLsizei)h);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	if (w <= h)
		glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w,2.5*(GLfloat)h/
(GLfloat)w, -10.0, 10.0);
	else
		glOrtho (-2.5*(GLfloat)w/(GLfloat)h,2.5*(GLfloat)w/(GLfloat)h, -2.5,
2.5, -10.0, 10.0);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
}

int main(int argc, char** argv){
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize (500, 500);
	glutCreateWindow (argv[0]);
	init ();
	glutReshapeFunc (reshape);
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------------
0
Reply bhodi78 3/6/2009 7:55:17 PM

On Mar 6, 2:55=A0pm, bhod...@gmail.com wrote:
> For simplicity, the scene in the background is the Cone and the scene
> in the foregorund is Torus.
> I thought to render the cone in an auxiliary buffer (function init)
> that is performed only once. In the display function, copy the cone
> from the auxiliary buffer, after rendering the torus. I do not
> understand what I am wrong, but that does not work. Thank you for your
> help.

1. Few implementations support AUX buffers. Use a texture instead.

2. You should also copy the depth buffer unless the variable portion
is 100% in front of the background.

3. It may not be necessary -- is there a performance problem that you
have actually measured?

--
Andy V
0
Reply Andy 3/6/2009 10:18:12 PM


Best way? Don't do it...

If you do it, it will be slower.



--
<\___/>
/ O O \
\_____/  FTB.

0
Reply fungus 3/7/2009 11:20:15 AM

> > For simplicity, the scene in the background is the Cone and the scene
> > in the foregorund is Torus.
> > I thought to render the cone in an auxiliary buffer (function init)
> > that is performed only once. In the display function, copy the cone
> > from the auxiliary buffer, after rendering the torus. I do not
> > understand what I am wrong, but that does not work. Thank you for your
> > help.


> 1. Few implementations support AUX buffers. Use a texture instead.

  - I checked the number with the following code and are four.
        GLint auxBuffers;
        glGetIntegerv(GL_AUX_BUFFERS, &auxBuffers);
        printf("Number of axiliary buffer is:%d",auxBuffers);

  - what it means: "Use a texture instead." ?


> 2. You should also copy the depth buffer unless the variable portion
> is 100% in front of the background.

The variable portion is ~2%, I thought that the command
"glCopyPixels (0, 0, g_w, g_h, GL_COLOR | GL_DEPTH);"
copy also the depth buffer.


> 3. It may not be necessary -- is there a performance problem that you
> have actually measured?
Yes, it's a problem of performance. The background's scene is very
complex and never changes, instead the foreground's scene is little
complex and it always changes. (it's like a spray).

Thank bye.
0
Reply bhodi78 3/7/2009 11:41:41 AM

On Mar 7, 6:41=A0am, bhod...@gmail.com wrote:

> > 1. Few implementations support AUX buffers. Use a texture instead.
>
> =A0 - I checked the number with the following code and are four.
> =A0 =A0 =A0 =A0 GLint auxBuffers;
> =A0 =A0 =A0 =A0 glGetIntegerv(GL_AUX_BUFFERS, &auxBuffers);
> =A0 =A0 =A0 =A0 printf("Number of axiliary buffer is:%d",auxBuffers);

What graphics board are you using?
>
> =A0 - what it means: "Use a texture instead." ?

Generate the background image and copy it to a texture (or use a
pbuffer). To display, render a textured quad to the entire screen.
>
> > 2. You should also copy the depth buffer unless the variable portion
> > is 100% in front of the background.
>
> The variable portion is ~2%, I thought that the command
> "glCopyPixels (0, 0, g_w, g_h, GL_COLOR | GL_DEPTH);"
> copy also the depth buffer.

I don't think that's a legal value for that parameter. From the spec:

void CopyPixels( int x, int y, sizei width, sizei height, enum type );
type is a symbolic constant that must be one of COLOR, STENCIL, or
DEPTH,

Besides, there is only one depth buffer for all color buffers, so that
wouldn't work anyway. Again, from the spec:

Corresponding bits from each pixel in the framebuff=0Ber are grouped to-
gether into a bitplane; each bitplane contains a single bit from each
pixel.
These bitplanes are grouped into several logical bu=0Bffers. These are
the color,
depth, stencil, and accumulation buff=0Bers. The color bu=0Bffer actually
consists
of a number of bu=0Bffers: the front left bu=0Bffer, the front right buff
er, the back
left buff=0Ber, the back right bu=0Bffer, and some number of auxiliary bu
ffers.

>
> > 3. It may not be necessary -- is there a performance problem that you
> > have actually measured?
>
> Yes, it's a problem of performance. The background's scene is very
> complex and never changes, instead the foreground's scene is little
> complex and it always changes. (it's like a spray).
>
> Thank bye.

I repeat -- have you measured this?

--
Andy V
0
Reply Andy 3/7/2009 9:24:06 PM

> > > 1. Few implementations support AUX buffers. Use a texture instead.
>
> > =A0 - I checked the number with the following code and are four.
> > =A0 =A0 =A0 =A0 GLint auxBuffers;
> > =A0 =A0 =A0 =A0 glGetIntegerv(GL_AUX_BUFFERS, &auxBuffers);
> > =A0 =A0 =A0 =A0 printf("Number of axiliary buffer is:%d",auxBuffers);
>
> What graphics board are you using?
I have an nvidia 9800 GT



> > =A0 - what it means: "Use a texture instead." ?
>
> Generate the background image and copy it to a texture (or use a
> pbuffer). To display, render a textured quad to the entire screen.
>
>
>
> > > 2. You should also copy the depth buffer unless the variable portion
> > > is 100% in front of the background.
>
> > The variable portion is ~2%, I thought that the command
> > "glCopyPixels (0, 0, g_w, g_h, GL_COLOR | GL_DEPTH);"
> > copy also the depth buffer.
>
> I don't think that's a legal value for that parameter. From the spec:
>
> void CopyPixels( int x, int y, sizei width, sizei height, enum type );
> type is a symbolic constant that must be one of COLOR, STENCIL, or
> DEPTH,
>
> Besides, there is only one depth buffer for all color buffers, so that
> wouldn't work anyway. Again, from the spec:
>
> Corresponding bits from each pixel in the framebuff er are grouped to-
> gether into a bitplane; each bitplane contains a single bit from each
> pixel.
> These bitplanes are grouped into several logical bu ffers. These are
> the color,
> depth, stencil, and accumulation buff ers. The color bu ffer actually
> consists
> of a number of bu ffers: the front left bu ffer, the front right buff
> er, the back
> left buff er, the back right bu ffer, and some number of auxiliary bu
> ffers.
>
>
>
> > > 3. It may not be necessary -- is there a performance problem that you
> > > have actually measured?
>
> > Yes, it's a problem of performance. The background's scene is very
> > complex and never changes, instead the foreground's scene is little
> > complex and it always changes. (it's like a spray).
>
> > Thank bye.
>
> I repeat -- have you measured this?
No i don't.

Maybe i should use the frame buffer object!

0
Reply bhodi78 3/9/2009 8:41:40 PM

bhodi78@gmail.com wrote:

>> I repeat -- have you measured this?
> No i don't.

Then measure it first.

> Maybe i should use the frame buffer object!

You should do a measurement. The GT9800 can munch through
literally millions of triangles within a 1/30 second. Probably
you can just redraw the whole scene each frame.

Wolfgang

0
Reply Wolfgang 3/9/2009 10:07:25 PM

6 Replies
141 Views

(page loaded in 0.068 seconds)


Reply: