glCopyTexImage2D strange result

Started by
1 comment, last by DMINATOR 18 years, 11 months ago
Hi I am using glCopyTexImage2D to render current game screen to texture and then use it as still background for menu. Everything works fine except that texture is somehow not filled fully, some black parts are shown instead. Here is image to show it better: Image Hosted by imagehosting.us Here is the code i use to render it:


//save viewport and set up new one
int viewport[4];

//first let's draw the mainscene to the texture
//and then use that texture 


RenderToTextureStart();

//clear any rendering made
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
glMatrixMode( GL_MODELVIEW );

//draw the scene
mainScene.GameDraw();

//and render to texture
RenderToTextureEnd();

	//draws current scene to the texture and use it after
	void RenderToTextureStart()
	{	
		glGetIntegerv(GL_VIEWPORT,(int*)viewport);
		glViewport(0,0,512,512);
		
	}

	void RenderToTextureEnd()
	{

		
		//save data to texture using glCopyTexImage2D
            //backimage.texID - is the texture we save to
		glBindTexture(GL_TEXTURE_2D,backimage.TextId(0 ));
		
		glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
			0,0, 512, 512, 0);
		
		//restore viewport
		glViewport( viewport[0],viewport[1],viewport[2],viewport[3]);
	}

	//draws background scene
	void DrawBack()
	{

		  glTranslatef(0.0f,0.0f,-1.0f); 

		      glColor3f(1.0f,1.0f,1.0f);          

			  glBindTexture( GL_TEXTURE_2D , backimage.TextId(0 ) );
			
		      glBegin(GL_QUADS);// Drawing Using Triangles
		
		
		
		
		          glTexCoord2f(0.0f, 0.0f);          // Top
		          glVertex3f(-0.77f,  -0.578f , 0);      		
		
		
	
	              glTexCoord2f(1.0f, 0.0f);
		          glVertex3f( 0.77f , -0.578f, 0);              // Bottom Left
		
		
		          glTexCoord2f(1.0f, 1.0f);
		          glVertex3f( 0.77f,   0.578f, 0);              // Bottom Right
		

		          glTexCoord2f(0.0f, 1.0f);
		          glVertex3f(-0.77f , 0.578f, 0);              // Bottom Right
		
		
		
		      glEnd();
		 
		    glTranslatef(0.0f,0.0f,1.0f); 
	}





Overall I am using SDL , OpenGL and DevIL One more thing is that this only occurs at 640x480 resolution. Higher resolutions work correctly ( 800x600 1024x768 ...) Here is what I get at 320x240. Strange :) Image Hosted by imagehosting.us I hope some one can help me out. [Edited by - DMINATOR on May 26, 2005 6:10:25 PM]
Advertisement
The buffer you render to is only as large as your window, so when you try to copy to a texture that is larger than this, only part of the texture will be filled.
(In other words, the top part of the texture is black because the window has height 480 and the texture is 512 pixels high.)

You have several options:
* Use a smaller texture
* Use only part of a texture (glCopyTexSubImage2D)
* Use pbuffers
* Render a small part of the texture every time and copy into the same texture (again glCopyTexSubImage2D.)
* and probably a bunch more...

I'd say the simplest would be to either use a texture that is small enough (512x256 for 640x480 window) or use only part of a larger texture (512x512 for 640x480, and render with texture coordinates 0 to 480/512 in y-direction.)
Thanks I am going to get it done now :)

This topic is closed to new replies.

Advertisement