Skip to main content
GameDev.net gamedev.net
🔒 Locked

render to texture error

Started by Altourus Sep 10, 2010 at 11:35 PM 0 replies 500+ views
Original Post
Altourus
Altourus
I'm having an interesting problem, I'm pretty sure its with the way I declare my textures. I have two textures I declare of the same type, one is attached to the Frame buffer object, one isn't attached to anything. When I render to the frame buffer, it writes its colour information to both textures.

Frame buffer and texture declaration
// Create A Texture for the Occlusion Map	glGenTextures(1, &OcclusionMap);	glBindTexture(GL_TEXTURE_2D, OcclusionMap);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);	// Create A Texture for the Depth Map;	glGenTextures(1, &DepthMap);	glBindTexture(GL_TEXTURE_2D, DepthMap);	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);	// Create A Texture for the Scene Render	glGenTextures(1, &SceneRender);	glBindTexture(GL_TEXTURE_2D, SceneRender);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);	// Create a FrameBuffer and attach the render buffer and texture	glGenFramebuffersEXT(1, &ShadowFrameBuffer);	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFrameBuffer);	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, DepthMap, NULL);	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, OcclusionMap, NULL);


Occlusion map is ID 1
Depth map is ID 2
SceneRender is ID 3

Writing to the occlusion and depth map
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFrameBuffer);	GLenum buffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_DEPTH_ATTACHMENT_EXT};	glDrawBuffers(2, buffers);	glReadBuffer(NULL);glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(45, (float)Width/(float)Height, 1, 1000);	gluLookAt(lightPos[0],lightPos[1],lightPos[2], 0.0,0.0,0.0, 0.0,1.0,0.0);	glMatrixMode(GL_MODELVIEW);	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	Rotation -= 0.25f;	glUseProgram(0);	glPushMatrix();	glRotatef(Rotation, 1,0.5,0.25);	glScalef(1,0.25,1);	glGetFloatv(GL_PROJECTION_MATRIX, mplight);	glGetFloatv(GL_MODELVIEW_MATRIX, mvlight);	rim.draw(NULL, NULL);	glPopMatrix();	glGenerateMipmapEXT(GL_TEXTURE_2D);



Rendering the empty texture to the screen
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glUseProgram(NULL);	glEnable(GL_TEXTURE_2D);	glActiveTexture(GL_TEXTURE0);	glBindTexture(GL_TEXTURE_2D, SceneRender);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(0,1,0,1,0.1,2);	glMatrixMode(GL_MODELVIEW);	glBegin(GL_QUADS);		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f,0.0f,1.0f);		glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f,0.0f,1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f,1.0f,1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f,1.0f,1.0f);	glEnd();	glDisable(GL_TEXTURE_2D);


This will display a quad with the contents of OcclusionMap, it should be rendering a blank texture. Is there something wrong with my declaration of the textures that is causing two unique Id's to reference the same space in memory?

EDIT: Lol I'm an idiot
	glBindTexture(GL_TEXTURE_2D, SceneRender);

should have been

	glBindTexture(GL_TEXTURE0, SceneRender);



[Edited by - Altourus on September 11, 2010 5:22:01 AM]

Topic Locked

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

Sign in to reply to this topic.