Sign in to follow this  
Jossos

glViewport Makes no sense

Recommended Posts

34yntrm.jpg

 

Ok So the two viewports refuse to go fullscreen, for reasons I cannot comprehend.

 

Code:

void GAME::DrawToFBO(bool half, float CameraOffset)
{
	// DRAW TO FBO
	glBindFramebuffer(GL_FRAMEBUFFER, FBO);	// Modify only 'FBO' screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_DEPTH_TEST);

	m_pipeline.LoadIdentity();

	// Init View
	m_pipeline.MatrixMode(VIEW_MATRIX);

	if (half)
		m_pipeline.Perspective(fov, ((float)g_graphicsManager->GetWidth()) / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
	else
		m_pipeline.Perspective(fov, (float)g_graphicsManager->GetWidth() / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
	m_pipeline.RotateX(-m_camera->GetRotX());
	m_pipeline.RotateY(m_camera->GetRotY());
	m_pipeline.Translate(-m_camera->GetPos().x, -m_camera->GetPos().y, -m_camera->GetPos().z);
	

	// Right
	m_pipeline.PushMatrix();
	glLoadIdentity();
	glViewport(0, 0, g_graphicsManager->GetWidth() / 2, g_graphicsManager->GetHeight());
	
	m_pipeline.Translate(-CameraOffset, 0.0f, 0.0f);
	RenderModels();
	m_pipeline.PopMatrix();

	// Left
	m_pipeline.PushMatrix();
	glLoadIdentity();
	glViewport(g_graphicsManager->GetWidth() / 2, 0, g_graphicsManager->GetWidth() / 2, g_graphicsManager->GetHeight());
	
	m_pipeline.Translate(CameraOffset, 0.0f, 0.0f);
	RenderModels();
	m_pipeline.PopMatrix();
}

I'm not even sure how glViewport works, and google refuses to give anything useful. I thought specifying the pixels would work, but apparently not? And I've fiddled with the values for ages. It makes absolutely no sense. It seems calling glViewport twice seems to scale them both down for some reason.

 

Any help is appreciated.

 

 

 

By the way I'm trying to make a little thing for the oculus rift. If anyone has useful resources, feel free to share, although I'm obviously not that far just yet, until I can fix this stupidity.

 

Thanks!

Share this post


Link to post
Share on other sites

What's happening is you are setting your glViewport the 2nd time, rendering to an FBO, and then doing whatever with the FBO to actually get it to the screen while your glViewport is still the right half of the screen. So the FBO gets dumped to just that area.

 

EDIT: add another glViewport for the entire screen before you draw the stereo FBO to the screen.

Edited by radioteeth

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this