Advertisement

reflections

Started by November 22, 2002 10:08 AM
83 comments, last by Crispy 22 years, 2 months ago


radeon 9000 pro... my cpu is a peice of trash though, which I''m expecting would explain the frame rate...

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
btw. and this is a personal hate I have please make your code not put the window at 0,0... as you might notice in the pic I have a verticle start bar... More than half the demos i download do this... so more than half are obscured by the task bar!

hehe.

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
Advertisement
That's exactly the kind of screenshot I could have taken : reflections are a little bit offset but the texture mapping part works fine.

I have a GeForce4Ti4400 (driver 40.72 from NVIDIA) on a Celeron1.1GHz and it runs ~10-15fps which I'd say would be correct for a TNT2 but is pretty slow for a GF4. That means I don't think that the GPU is the one being overloaded otherwise there would be a much significant difference between "your" TNT2 and "my" GF4, you should start with optimizing CPU.

I'll try with an Radeon 8500 later...

[edited by - vincoof on November 29, 2002 3:51:07 AM]
r you translating down the y axis before you render your reflected scene?
That''s exactly what I''m thinking of : Crispy may be flipping the vertical axis, but this works only if the water surface is at altitude 0. If the water surface is not at altitude 0, a little vertical translation has to be done for rendering the reflected scene.
I''ve checked the code and yes the water surface is not at altitude 0. It is at altitude 20 because you call :

  glBegin(GL_POLYGON);glVertex3f(1024, 20, 1024);glVertex3f(1024, 20, 0);glVertex3f(0, 20, 0);glVertex3f(0, 20, 1024);glEnd();  


In order to satisfy the 20 units difference, you can''t *just* scale by -1. You also have to "project the origin to the other side of the mirror". The origin being at (0,0,0) and the mirror being at altitude 20, where should be projected the origin by the mirror ? Answer : at (0,40,0). Elémentatire, mon cher Lock Holmes...
That means you have to replace the following reflecting code :

  	glViewport(0, 0, 512, 512);		glPushMatrix();			glScalef(1.0f, -1.0f, 1.0f);  

with this one :

  	glViewport(0, 0, 512, 512);		glPushMatrix();			glTranslatef(0, 40.0f, 0);			glScalef(1.0f, -1.0f, 1.0f);  



Also, I haven''t seen any clip planes in your texture reflections. You may already know it, but you will have to setup at least one clip plane "sooner or later".
Advertisement
I''ve tried your program on an ATI Radeon 8500 and it runs exactly at 8fps (no more no less everytime).
I also tried with an ATI Radeon 9700 and the program doesn''t run (start showing the window borders but no 3D view inside : the program freezes and has to be killed)
Could disable vsync
Ive been trying to superimpose vincoof's code onto my island demo, with rough luck. Heres what i got, which should essentially be a cut and paste job with a few mods:


  //Water constructor:WATER(GLsizei dimention = 128)	{		vertices = NULL;		Dimen = dimention;		//A bit of texture initialization		glBindTexture( GL_TEXTURE_2D, reflexture);		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, Dimen, Dimen, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);			}//------------------------------------------------------------------////- void WATER::Render(void) ------------------------------////------------------------------------------------------------------////- Renders the water plane ----------------------------------------////------------------------------------------------------------------//void WATER::Render(void (*Reflect)(void)){	//Setup texture coordinate equations	static GLfloat lsPlaneS[] = {1.0f, 0, 0, 0};	static GLfloat lsPlaneT[] = {0, 1.0f, 0, 0};	static GLfloat lsPlaneR[] = {0, 0, 1.0f, 0};	static GLfloat lsPlaneQ[] = {0, 0, 0, 1.0f};	//Do a bit of reflection	//If there is a render funcition	if(Reflect)	{		//Get the old viewport		GLint viewport[4];		glGetIntegerv (GL_VIEWPORT, viewport);		//Generate a new viewport		//For the reflected texture		glFrontFace(GL_CW);		glViewport(0,0,Dimen,Dimen);		//Draw the reflection		glPushMatrix();		glLoadIdentity();		Reflect();		//Set up scene		glPopMatrix();		glFlush();		//Grab the texture		glBindTexture( GL_TEXTURE_2D, reflexture);		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0 , 0, 0, 0, Dimen, Dimen);		//Get ready to draw the scene		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );		glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);		//And back to counter clockwise normals		glFrontFace(GL_CCW);		//Set up the texture generation		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);		glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);		glTexGenfv(GL_S, GL_EYE_PLANE, lsPlaneS);		glTexGenfv(GL_T, GL_EYE_PLANE, lsPlaneT);		glTexGenfv(GL_R, GL_EYE_PLANE, lsPlaneR);		glTexGenfv(GL_Q, GL_EYE_PLANE, lsPlaneQ);		glEnable(GL_TEXTURE_GEN_S);		glEnable(GL_TEXTURE_GEN_T);		glEnable(GL_TEXTURE_GEN_R);		glEnable(GL_TEXTURE_GEN_Q);				glMatrixMode(GL_TEXTURE);		glPushMatrix();		glLoadIdentity();		glTranslatef(0.5f, 0.5f, 0.0f);		glScalef(0.5f, 0.5f, 1.0f);		gluPerspective(45.0f, 			(GLfloat)((viewport[2] - viewport[0])/(viewport[1] - viewport[3])),			0.1f, 100.0f );			}	float x;	float y;		for(y=1; y<heightMapHeight-1; y++)	{		glBegin(GL_TRIANGLE_STRIP);		//Render the row as a triangle strip		for(x=0; x<heightMapWidth-1; x++)		{			//glTexCoord2f(0.0f , 0.0f );			glNormal3fv(vertices[(int)((y*heightMapHeight)+x)].v);			glVertex3fv(vertices[(int)((y*heightMapHeight)+x)].v);			//glTexCoord2f(1.0f , 0.0f );			glNormal3fv(vertices[(int)((y*heightMapHeight)+(x+1))].v);			glVertex3fv(vertices[(int)((y*heightMapHeight)+(x+1))].v);			//glTexCoord2f(0.0f , 1.0f );			glNormal3fv(vertices[(int)(((y+1)*heightMapHeight)+x)].v);			glVertex3fv(vertices[(int)(((y+1)*heightMapHeight)+x)].v);			//glTexCoord2f(1.0f , 1.0f );			glNormal3fv(vertices[(int)(((y+1)*heightMapHeight)+(x+1))].v);			glVertex3fv(vertices[(int)(((y+1)*heightMapHeight)+(x+1))].v);		}		glEnd();	}	//Restore defaults	if(Reflect)	{		glPopMatrix();		glLoadIdentity();		glMatrixMode(GL_MODELVIEW);		glDisable(GL_TEXTURE_GEN_S);		glDisable(GL_TEXTURE_GEN_T);		glDisable(GL_TEXTURE_GEN_R);		glDisable(GL_TEXTURE_GEN_Q);		}}  


When i run the program all i get is a white texture, regardless of what i draw in Reflect. Thanks for any help

[edited by - llvllatrix on November 30, 2002 9:23:21 AM]
Did you call something like glEnable(GL_TEXTURE_2D) ?

Apart from that, the piece of code looks fine except that I would set an identity matrix around this code :

  glTexGenfv(GL_S, GL_EYE_PLANE, lsPlaneS);glTexGenfv(GL_T, GL_EYE_PLANE, lsPlaneT);glTexGenfv(GL_R, GL_EYE_PLANE, lsPlaneR);glTexGenfv(GL_Q, GL_EYE_PLANE, lsPlaneQ);  

For instance this :

  glPushMatrix();glLoadIdentity();glTexGenfv(GL_S, GL_EYE_PLANE, lsPlaneS);glTexGenfv(GL_T, GL_EYE_PLANE, lsPlaneT);glTexGenfv(GL_R, GL_EYE_PLANE, lsPlaneR);glTexGenfv(GL_Q, GL_EYE_PLANE, lsPlaneQ);glPopMatrix();  

This topic is closed to new replies.

Advertisement