Drawing only what you can see (terrain)
Well, ive been cracking out my game (RTS genre, OpenGL) and I have a fully functional terrain engine that randomly generates terrain maps and transition textures. I can fly (player is a helocopter) around the world with the player object. The problem I have is drawing the terrain.
I have tried to setup a rectangle area that is drawn, and that area floats with the player. I have been less than successful in getting acceptable results.
My terrain has no LOD system, It is based off a procedural heightmap and is basically just an 2d array of display lists. What sort of system do you think I can implement for drawing terrain? I have considered maybe some kind of frustrum culling, but I am concerned about the cpu expense of the math involved.
While writing this I have the idea of using my current rectangle area, oversizing it and adding a check so that it only draws below a specific height. To tired to mess with it tonight, will update tomorrow.
Code:
void cTerrain::DrawTerrain(sDrawArea* drawArea) {
int a,b;
if(drawArea->type == DRAW_RECTANGLE) {
RenderEngine->Translate(drawArea->x*TER_SCALE,drawArea->y*TER_SCALE,0);
for(a = drawArea->x; a < drawArea->w+drawArea->x; a++) {
for(b = drawArea->y; b < drawArea->h+drawArea->y; b++) {
RenderEngine->DrawModel(displayMap->GetData(a,b));
propMap->GetData(a,b)->Draw();
RenderEngine->ShiftUp(TER_SCALE);
}
RenderEngine->ShiftLeft(TER_SCALE);
RenderEngine->ShiftUp(-(drawArea->h)*TER_SCALE);
}
}
else if(drawArea->type == DRAW_ALL) {
for(a = 0; a < displayMap->size; a++) {
for(b = 0; b < displayMap->size; b++) {
RenderEngine->DrawModel(displayMap->GetData(a,b));
RenderEngine->ShiftUp(TER_SCALE);
}
RenderEngine->ShiftLeft(TER_SCALE);
RenderEngine->ShiftUp(-displayMap->size*TER_SCALE);
}
}
}