Jump to content
  • Advertisement
Sign in to follow this  
Jengu

OpenGL Tiled rendering math hurts my brain

This topic is 3991 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

I'm trying to do tiled rendering so that I can do high resolution screenshots. I found this page that describes how to do it: http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node30.html But I can't wrap my head around the math, esp. for calculating xoffset and yoffset (the equations look totally arbitrary to me). Can anyone explain or point to a more detailed explanation? Thanks :)

Share this post


Link to post
Share on other sites
Advertisement
Oh, forgot to include the code I'm using so far. The problem I'm getting is gaps between the tiles. I'm not sure how to debug it because I'm just copying the math from the link.


double multiplier = double(dpi) / 72.0; // DPI chosen by user

int sceneWidth = m_primarySelection->GetWidth() * multiplier;
int sceneHeight = m_primarySelection->GetHeight() * multiplier;

// We're using glReadPixels so we can't have tiles bigger than the
// the framebuffer. Pick biggest size that works.
int canvasWidth, canvasHeight;
GetClientSize(&canvasWidth, &canvasHeight);
int tileWidth, tileHeight;
for(int i = 1; i < 1000; ++i) {
tileWidth = std::ceil(double(sceneWidth) / double(i));
tileHeight = std::ceil(double(sceneHeight) / double(i));
if( tileWidth < canvasWidth &&
tileHeight < canvasHeight)
break;
}

float xscale = sceneWidth / tileWidth;
float yscale = sceneHeight / tileHeight;

wxBitmap composite_shot(sceneWidth, sceneHeight);
wxMemoryDC compositor;
compositor.SelectObject(composite_shot);

int nTilesX = std::ceil(double(sceneWidth) / double(tileWidth));
int nTilesY = std::ceil(double(sceneHeight) / double(tileHeight));

for(int y = 0; y < nTilesY; ++y) {
for(int x = 0; x < nTilesX; ++x) {
float xOffset = (-2.0f * float(x) * float(tileWidth) / float(sceneWidth)) + (1.0f - 1.0f / float(nTilesX));
float yOffset = (-2.0f * float(y) * float(tileHeight) / float(sceneHeight)) + (1.0f - 1.0f / float(nTilesY));

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// The scale and offset values are applied to the projection matrix before glOrtho is called
m_primarySelection->ContentsRender(xscale, yscale, xOffset, yOffset);

compositor.DrawBitmap(*Screenshot(0, 0, tileWidth, tileHeight), x * tileWidth, sceneHeight - (y+1) * tileHeight);
}
}

composite_shot.SaveFile(fileDlg.GetFilename(), wxBITMAP_TYPE_PNG);


(the wxwidgets stuff is just for dumping the data from glReadPixels, which is called by Screenshot(), to disk)

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!