# glViewport Makes no sense

## Recommended Posts

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);

// 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();
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();
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 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.

##### Share on other sites

OPh dude thanks a bunch, you are a smart guy. I'm so dumb thatnks a tonne!

Edited by Jossos

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627734
• Total Posts
2978846

• 10
• 10
• 21
• 14
• 12