Jump to content
  • Advertisement
Sign in to follow this  
diginerd

Dynamic Cube Mapping - Each of the 6 renders is from camera lookat

This topic is 3677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I've recently gotten into dynamic cube mapping, and I'm having trouble. Every time I render the cubemap, all 6 textures are rendered from the camera's perspective and not the object reflecting the scene. Here is the rundown of my render loop:
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

UpdateCamera();
UpdateObjects();
UpdateLights();

BuildDynamicCubeMap();

RenderScenery();
DrawTestReflection();

glFlush();
glutSwapBuffers();
}

UpdateCamera just updates the camera's eye, lookat, up vectors by calling gluLookAt. BuildDynamicCubeMap() is as follows:
void BuildDynamicCubeMap()
{
       // Must set fov to 90
	SetProjection(800, 600, 1.0, 90);
	glMatrixMode(GL_MODELVIEW);

	// Bind the FBO so the scene is rendered to it
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_fboID);

	// Render Left (-X) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_LEFT], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(90, 0.0f, 1.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	// Render Right (+X) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_RIGHT], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(-90, 0.0f, 1.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	// Render Top (+Y) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_TOP], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(-90, 1.0f, 0.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	// Render Bottom (-Y) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_BOTTOM], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(90, 1.0f, 0.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	// Render Near (+Z) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_NEAR], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(180, 0.0f, 1.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	// Render Far (-Z) Face
	glClear(GL_DEPTH_BUFFER_BIT);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_sceneTexs[SF_FAR], 0);
	glPushMatrix();
	glLoadIdentity();
	glRotatef(0, 0.0f, 1.0f, 0.0f);
	RenderScenery();
	glPopMatrix();

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

	// Reset projection
	Resize(800,600);
	glMatrixMode(GL_MODELVIEW);
}


I'm just trying to draw the reflection of the scene onto a cube from the perspective of the origin for now. But all 6 textures look exactly the same(the view from the camera). Can anyone please help me figure out what's going on? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!