Browse Source

Sort layers before rendering.

legacy
Sam Hocevar sam 14 years ago
parent
commit
a066bec3bb
2 changed files with 12 additions and 1 deletions
  1. +1
    -1
      src/test-map.cpp
  2. +11
    -0
      src/tiler.cpp

+ 1
- 1
src/test-map.cpp View File

@@ -54,7 +54,7 @@ void DrawScene()
/* Test stuff */
int playerx, playery;
SDL_GetMouseState(&playerx, &playery);
tiler->AddTile(50, playerx, playery, nlayers);
tiler->AddTile(50, playerx, playery, 1);

tiler->Render();
video->Refresh(33.33333f);


+ 11
- 0
src/tiler.cpp View File

@@ -27,6 +27,14 @@ class TilerData
friend class Tiler;

private:
static int Compare(void const *p1, void const *p2)
{
int const *n1 = (int const *)p1;
int const *n2 = (int const *)p2;

return n1[2] + 32 * n1[3] - (n2[2] + 32 * n2[3]);
}

int *tiles;
int ntiles;

@@ -90,6 +98,9 @@ void Tiler::AddTile(int n, int x, int y, int z)

void Tiler::Render()
{
/* Sort tiles */
qsort(data->tiles, data->ntiles, 4 * sizeof(int), TilerData::Compare);

/* Texture coord buffer */
float uvs[8 * data->ntiles];
for (int n = 0; n < data->ntiles; n++)


Loading…
Cancel
Save