mirror of
https://github.com/dpethes/rerogue.git
synced 2025-06-07 18:58:32 +02:00
terrain viewer: fix uv coords
This commit is contained in:
parent
ef525fc0ff
commit
ab91e14a2f
@ -45,6 +45,7 @@ implementation
|
|||||||
procedure TTerrainMesh.TransformTiles;
|
procedure TTerrainMesh.TransformTiles;
|
||||||
|
|
||||||
//basex/y - offset in vertices
|
//basex/y - offset in vertices
|
||||||
|
//TODO solve flipped coords
|
||||||
procedure TileToBlock(var blk: TTerrainBlock; var tile: TTile; basex, basey: integer);
|
procedure TileToBlock(var blk: TTerrainBlock; var tile: TTile; basex, basey: integer);
|
||||||
const
|
const
|
||||||
h_scale = 0.5;
|
h_scale = 0.5;
|
||||||
@ -61,9 +62,9 @@ procedure TTerrainMesh.TransformTiles;
|
|||||||
for x := 0 to 4 do begin
|
for x := 0 to 4 do begin
|
||||||
v.x := (-width_half + basex + x) * h_scale;
|
v.x := (-width_half + basex + x) * h_scale;
|
||||||
v.z := (-height_half + basey + y) * h_scale;
|
v.z := (-height_half + basey + y) * h_scale;
|
||||||
v.u := -x * 1/4;
|
v.v := (1 - x/4);
|
||||||
v.v := -y * 1/4;
|
v.u := y/4;
|
||||||
v.y := shortint(tile.heights[y+x*5]) * v_scale; //hmm... all transforms are flipped?
|
v.y := shortint(tile.heights[y+x*5]) * v_scale;
|
||||||
v.y := -v.y;
|
v.y := -v.y;
|
||||||
|
|
||||||
blk.vertices[y * 5 + x] := v;
|
blk.vertices[y * 5 + x] := v;
|
||||||
@ -138,78 +139,51 @@ end;
|
|||||||
//draw vertices from each block
|
//draw vertices from each block
|
||||||
procedure TTerrainMesh.DrawGL(opts: TRenderOpts);
|
procedure TTerrainMesh.DrawGL(opts: TRenderOpts);
|
||||||
|
|
||||||
procedure RenderBlock(var blk: TTerrainBlock);
|
procedure RenderBlock(var blk: TTerrainBlock);
|
||||||
var
|
procedure RenderTri(i0, i1, i2:integer);
|
||||||
i, x, y, stride: integer;
|
var
|
||||||
v: TVertex3f;
|
v: TVertex3f;
|
||||||
begin
|
begin
|
||||||
|
v := blk.vertices[i0];
|
||||||
|
glTexCoord2f(v.u, v.v);
|
||||||
|
glVertex3fv(@v);
|
||||||
|
v := blk.vertices[i1];
|
||||||
|
glTexCoord2f(v.u, v.v);
|
||||||
|
glVertex3fv(@v);
|
||||||
|
v := blk.vertices[i2];
|
||||||
|
glTexCoord2f(v.u, v.v);
|
||||||
|
glVertex3fv(@v);
|
||||||
|
end;
|
||||||
|
var
|
||||||
|
i, x, y, stride: integer;
|
||||||
|
begin
|
||||||
stride := 5;
|
stride := 5;
|
||||||
glBindTexture(GL_TEXTURE_2D, textures_glidx[blk.texture_index]);
|
glBindTexture(GL_TEXTURE_2D, textures_glidx[blk.texture_index]);
|
||||||
{
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
//glColor3f(0, 1, 0);
|
//glColor3f(0, 1, 0);
|
||||||
for y := 0 to 3 do
|
for y := 0 to 3 do
|
||||||
for x := 0 to 3 do begin
|
for x := 0 to 3 do begin
|
||||||
//do two triangles
|
//do two triangles
|
||||||
i := y * stride + x;
|
i := y * stride + x;
|
||||||
|
RenderTri(i+1, i, i+stride);
|
||||||
v := blk.vertices[i + 1];
|
RenderTri(i+1, i+stride, i+stride+1);
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[i];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[i + stride];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
|
|
||||||
v := blk.vertices[i + 1];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[i + stride];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[i + stride + 1];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
end;
|
end;
|
||||||
glEnd;
|
glEnd;
|
||||||
|
{ //only 2 tris per block
|
||||||
}
|
glBegin(GL_TRIANGLES);
|
||||||
//quad from block corners
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
i := y * stride + x;
|
i := y * stride + x;
|
||||||
|
RenderTri(0, 4, 24);
|
||||||
v := blk.vertices[4];
|
RenderTri(24, 20, 0);
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[0];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[20];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
v := blk.vertices[24];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
glTexCoord2f(v.u, v.v);
|
|
||||||
glEnd;
|
glEnd;
|
||||||
|
}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
i, x, y, stride: integer;
|
i, x, y, stride: integer;
|
||||||
blk: TTerrainBlock;
|
blk: TTerrainBlock;
|
||||||
v: TVertex3f;
|
v: TVertex3f;
|
||||||
begin
|
begin
|
||||||
if opts.points then begin
|
|
||||||
glBegin(GL_POINTS);
|
|
||||||
glColor3f(0, 1, 0);
|
|
||||||
for i := 0 to terrain.vertex_count - 1 do begin
|
|
||||||
v := terrain.vertex_array[i];
|
|
||||||
glVertex3fv(@v);
|
|
||||||
end;
|
|
||||||
glEnd;
|
|
||||||
end else begin
|
|
||||||
if opts.wireframe then
|
if opts.wireframe then
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||||
else
|
else
|
||||||
@ -220,7 +194,6 @@ begin
|
|||||||
blk := blocks[y, x];
|
blk := blocks[y, x];
|
||||||
RenderBlock(blk);
|
RenderBlock(blk);
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user