140
void TerrainRenderer::GenerateVertices(const GameWorldViewer * gwv)
140
void TerrainRenderer::GenerateVertices(const GameWorldViewer* gwv)
143
vertices = new Vertex[width * height];
144
memset(vertices, 0, sizeof(Vertex) * width * height);
146
// Terrain generieren
147
for(unsigned short y = 0; y < height; ++y)
149
for(unsigned short x = 0; x < width; ++x)
151
UpdateVertexPos(x,y,gwv);
152
UpdateVertexColor(x,y,gwv);
153
UpdateVertexTerrain(x,y,gwv);
158
for(unsigned short y = 0; y < height; ++y)
160
for(unsigned short x = 0; x < width; ++x)
162
UpdateBorderVertex(x,y,gwv);
143
vertices = new Vertex[width * height];
144
memset(vertices, 0, sizeof(Vertex) * width * height);
146
// Terrain generieren
147
for(unsigned short y = 0; y < height; ++y)
149
for(unsigned short x = 0; x < width; ++x)
151
UpdateVertexPos(x, y, gwv);
152
UpdateVertexColor(x, y, gwv);
153
UpdateVertexTerrain(x, y, gwv);
158
for(unsigned short y = 0; y < height; ++y)
160
for(unsigned short x = 0; x < width; ++x)
162
UpdateBorderVertex(x, y, gwv);
167
167
/// erzeugt Vertex
168
void TerrainRenderer::UpdateVertexPos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
170
GetVertex(x,y).pos.pos.x = float(x * TR_W + ( (y&1) ? TR_W/2 : 0) );
171
GetVertex(x,y).pos.pos.y = float(y * TR_H - HEIGHT_FACTOR * gwv->GetNode(x,y).altitude + HEIGHT_FACTOR * 0x0A );
175
void TerrainRenderer::UpdateVertexColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
177
switch(gwv->GetVisibility(x,y))
179
// Unsichtbar -> schwarz
180
case VIS_INVISIBLE: GetVertex(x,y).pos.color = 0.0f; break;
181
// Fog of War -> abgedunkelt
182
case VIS_FOW: GetVertex(x,y).pos.color = float(gwv->GetNode(x,y).shadow + 0x40) / float(0xFF) / 2; break;
184
case VIS_VISIBLE: GetVertex(x,y).pos.color = float(gwv->GetNode(x,y).shadow + 0x40) / float(0xFF); break;
188
void TerrainRenderer::UpdateVertexTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
190
if(gwv->GetNode(x,y).t1 < 20)
191
GetVertex(x,y).terrain[0] = gwv->GetNode(x,y).t1;
193
if(gwv->GetNode(x,y).t2 < 20)
194
GetVertex(x,y).terrain[1] = gwv->GetNode(x,y).t2;
168
void TerrainRenderer::UpdateVertexPos(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
170
GetVertex(x, y).pos.pos.x = float(x * TR_W + ( (y & 1) ? TR_W / 2 : 0) );
171
GetVertex(x, y).pos.pos.y = float(y * TR_H - HEIGHT_FACTOR * gwv->GetNode(x, y).altitude + HEIGHT_FACTOR * 0x0A );
175
void TerrainRenderer::UpdateVertexColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
177
switch(gwv->GetVisibility(x, y))
179
// Unsichtbar -> schwarz
180
case VIS_INVISIBLE: GetVertex(x, y).pos.color = 0.0f; break;
181
// Fog of War -> abgedunkelt
182
case VIS_FOW: GetVertex(x, y).pos.color = float(gwv->GetNode(x, y).shadow + 0x40) / float(0xFF) / 2; break;
184
case VIS_VISIBLE: GetVertex(x, y).pos.color = float(gwv->GetNode(x, y).shadow + 0x40) / float(0xFF); break;
188
void TerrainRenderer::UpdateVertexTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
190
if(gwv->GetNode(x, y).t1 < 20)
191
GetVertex(x, y).terrain[0] = gwv->GetNode(x, y).t1;
193
if(gwv->GetNode(x, y).t2 < 20)
194
GetVertex(x, y).terrain[1] = gwv->GetNode(x, y).t2;
197
197
/// erzeugt Rand-Vertex
198
void TerrainRenderer::UpdateBorderVertex(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
198
void TerrainRenderer::UpdateBorderVertex(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
200
/// @todo GetTerrainX und Co durch GetTerrainXA ausdr�cken
201
GetVertex(x,y).border[0].pos.x = ( GetTerrainXAround(x,y,5) + GetTerrainX(x, y) + GetTerrainXAround(x,y,4) ) / 3.0f;
202
GetVertex(x,y).border[0].pos.y = ( GetTerrainYAround(x,y,5) + GetTerrainY(x, y) + GetTerrainYAround(x,y,4) ) / 3.0f;
203
GetVertex(x,y).border[0].color = ( GetColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5)) + GetColor(x, y) + GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4)) ) / 3.0f;
200
/// @todo GetTerrainX und Co durch GetTerrainXA ausdr�cken
201
GetVertex(x, y).border[0].pos.x = ( GetTerrainXAround(x, y, 5) + GetTerrainX(x, y) + GetTerrainXAround(x, y, 4) ) / 3.0f;
202
GetVertex(x, y).border[0].pos.y = ( GetTerrainYAround(x, y, 5) + GetTerrainY(x, y) + GetTerrainYAround(x, y, 4) ) / 3.0f;
203
GetVertex(x, y).border[0].color = ( GetColor(gwv->GetXA(x, y, 5), gwv->GetYA(x, y, 5)) + GetColor(x, y) + GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4)) ) / 3.0f;
205
GetVertex(x,y).border[1].pos.x = ( GetTerrainXAround(x,y,3) + GetTerrainX(x, y) + GetTerrainXAround(x,y,4) ) / 3.0f;
206
GetVertex(x,y).border[1].pos.y = ( GetTerrainYAround(x,y,3) + GetTerrainY(x, y) + GetTerrainYAround(x,y,4) ) / 3.0f;
207
GetVertex(x,y).border[1].color = ( GetColor(gwv->GetXA(x,y,3), gwv->GetYA(x,y,3)) + GetColor(x, y) + GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4)) ) / 3.0f;
205
GetVertex(x, y).border[1].pos.x = ( GetTerrainXAround(x, y, 3) + GetTerrainX(x, y) + GetTerrainXAround(x, y, 4) ) / 3.0f;
206
GetVertex(x, y).border[1].pos.y = ( GetTerrainYAround(x, y, 3) + GetTerrainY(x, y) + GetTerrainYAround(x, y, 4) ) / 3.0f;
207
GetVertex(x, y).border[1].color = ( GetColor(gwv->GetXA(x, y, 3), gwv->GetYA(x, y, 3)) + GetColor(x, y) + GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4)) ) / 3.0f;
216
216
* @author FloSoft
218
void TerrainRenderer::GenerateOpenGL(const GameWorldViewer * gwv)
218
void TerrainRenderer::GenerateOpenGL(const GameWorldViewer* gwv)
220
width = gwv->GetWidth();
221
height = gwv->GetHeight();
222
LandscapeType lt = gwv->GetLandscapeType();
224
GenerateVertices(gwv);
226
unsigned int offset = width * height * 2;
229
borders = new Borders[width * height];
230
for(unsigned short y = 0; y < height; ++y)
232
for(unsigned short x = 0; x < width; ++x)
234
unsigned char t1 = gwv->GetNode(x, y).t1;
235
unsigned char t2 = gwv->GetNode(x, y).t2;
236
unsigned int pos = y * width + x;
238
if( (borders[pos].left_right[0] = BORDER_TABLES[lt][t1][t2][1]) )
240
borders[pos].left_right_offset[0] = offset + border_count;
243
if( (borders[pos].left_right[1] = BORDER_TABLES[lt][t1][t2][0]) )
245
borders[pos].left_right_offset[1] = offset + border_count;
249
t1 = gwv->GetNodeAround(x, y,3).t1;
250
if( (borders[pos].right_left[0] = BORDER_TABLES[lt][t2][t1][1]) )
252
borders[pos].right_left_offset[0] = offset + border_count;
255
if( (borders[pos].right_left[1] = BORDER_TABLES[lt][t2][t1][0]) )
257
borders[pos].right_left_offset[1] = offset + border_count;
261
t1 = gwv->GetNode(x, y).t1;
262
t2 = gwv->GetNodeAround(x,y,5).t2;
263
if( (borders[pos].top_down[0] = BORDER_TABLES[lt][t1][t2][1]) )
265
borders[pos].top_down_offset[0] = offset + border_count;
268
if( (borders[pos].top_down[1] = BORDER_TABLES[lt][t1][t2][0]) )
270
borders[pos].top_down_offset[1] = offset + border_count;
276
gl_vertices = new Triangle[offset + border_count];
277
gl_texcoords = new Triangle[offset + border_count];
278
gl_colors = new ColorTriangle[offset + border_count];
280
// Normales Terrain erzeugen
281
for(unsigned short y = 0; y < height; ++y)
283
for(unsigned short x = 0; x < width; ++x)
285
UpdateTrianglePos(x,y,gwv,false);
286
UpdateTriangleColor(x,y,gwv,false);
287
UpdateTriangleTerrain(x,y,gwv,false);
292
for(unsigned short y = 0; y < height; ++y)
294
for(unsigned short x = 0; x < width; ++x)
296
UpdateBorderTrianglePos(x,y,gwv,false);
297
UpdateBorderTriangleColor(x,y,gwv,false);
298
UpdateBorderTriangleTerrain(x,y,gwv,false);
301
//unsigned buffer_size = (offset ) * 2 * 3 * sizeof(float);
303
if(SETTINGS.video.vbo)
305
// Generiere und Binde den Vertex Buffer
306
glGenBuffersARB(1, (GLuint*)&vbo_vertices);
307
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
308
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_vertices, GL_STATIC_DRAW_ARB);
309
glVertexPointer(2, GL_FLOAT, 0, NULL);
311
// Generiere und Binde den Textur Koordinaten Buffer
312
glGenBuffersARB(1, (GLuint*)&vbo_texcoords);
313
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_texcoords);
314
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_texcoords, GL_STATIC_DRAW_ARB );
315
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
317
// Generiere und Binde den Color Buffer
318
glGenBuffersARB(1, (GLuint*)&vbo_colors);
319
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_colors);
320
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 3 * sizeof(float), gl_colors, GL_STATIC_DRAW_ARB );
321
glColorPointer(3, GL_FLOAT, 0, NULL);
325
glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
326
glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
327
glColorPointer(3, GL_FLOAT, 0, gl_colors);
220
width = gwv->GetWidth();
221
height = gwv->GetHeight();
222
LandscapeType lt = gwv->GetLandscapeType();
224
GenerateVertices(gwv);
226
unsigned int offset = width * height * 2;
229
borders = new Borders[width * height];
230
for(unsigned short y = 0; y < height; ++y)
232
for(unsigned short x = 0; x < width; ++x)
234
unsigned char t1 = gwv->GetNode(x, y).t1;
235
unsigned char t2 = gwv->GetNode(x, y).t2;
236
unsigned int pos = y * width + x;
238
if( (borders[pos].left_right[0] = BORDER_TABLES[lt][t1][t2][1]) )
240
borders[pos].left_right_offset[0] = offset + border_count;
243
if( (borders[pos].left_right[1] = BORDER_TABLES[lt][t1][t2][0]) )
245
borders[pos].left_right_offset[1] = offset + border_count;
249
t1 = gwv->GetNodeAround(x, y, 3).t1;
250
if( (borders[pos].right_left[0] = BORDER_TABLES[lt][t2][t1][1]) )
252
borders[pos].right_left_offset[0] = offset + border_count;
255
if( (borders[pos].right_left[1] = BORDER_TABLES[lt][t2][t1][0]) )
257
borders[pos].right_left_offset[1] = offset + border_count;
261
t1 = gwv->GetNode(x, y).t1;
262
t2 = gwv->GetNodeAround(x, y, 5).t2;
263
if( (borders[pos].top_down[0] = BORDER_TABLES[lt][t1][t2][1]) )
265
borders[pos].top_down_offset[0] = offset + border_count;
268
if( (borders[pos].top_down[1] = BORDER_TABLES[lt][t1][t2][0]) )
270
borders[pos].top_down_offset[1] = offset + border_count;
276
gl_vertices = new Triangle[offset + border_count];
277
gl_texcoords = new Triangle[offset + border_count];
278
gl_colors = new ColorTriangle[offset + border_count];
280
// Normales Terrain erzeugen
281
for(unsigned short y = 0; y < height; ++y)
283
for(unsigned short x = 0; x < width; ++x)
285
UpdateTrianglePos(x, y, gwv, false);
286
UpdateTriangleColor(x, y, gwv, false);
287
UpdateTriangleTerrain(x, y, gwv, false);
292
for(unsigned short y = 0; y < height; ++y)
294
for(unsigned short x = 0; x < width; ++x)
296
UpdateBorderTrianglePos(x, y, gwv, false);
297
UpdateBorderTriangleColor(x, y, gwv, false);
298
UpdateBorderTriangleTerrain(x, y, gwv, false);
301
//unsigned buffer_size = (offset ) * 2 * 3 * sizeof(float);
303
if(SETTINGS.video.vbo)
305
// Generiere und Binde den Vertex Buffer
306
glGenBuffersARB(1, (GLuint*)&vbo_vertices);
307
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
308
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_vertices, GL_STATIC_DRAW_ARB);
309
glVertexPointer(2, GL_FLOAT, 0, NULL);
311
// Generiere und Binde den Textur Koordinaten Buffer
312
glGenBuffersARB(1, (GLuint*)&vbo_texcoords);
313
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
314
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_texcoords, GL_STATIC_DRAW_ARB );
315
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
317
// Generiere und Binde den Color Buffer
318
glGenBuffersARB(1, (GLuint*)&vbo_colors);
319
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
320
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 3 * sizeof(float), gl_colors, GL_STATIC_DRAW_ARB );
321
glColorPointer(3, GL_FLOAT, 0, NULL);
325
glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
326
glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
327
glColorPointer(3, GL_FLOAT, 0, gl_colors);
331
331
/// Erzeugt fertiges Dreieick f�r OpenGL
333
void TerrainRenderer::UpdateTrianglePos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
335
unsigned int pos = 2 * width * y + x*2;
337
gl_vertices[pos].pos[0].x = GetTerrainXAround(x,y,4);
338
gl_vertices[pos].pos[0].y = GetTerrainYAround(x,y,4);
339
gl_vertices[pos].pos[1].x = GetTerrainX(x, y);
340
gl_vertices[pos].pos[1].y = GetTerrainY(x, y);
341
gl_vertices[pos].pos[2].x = GetTerrainXAround(x,y,5);
342
gl_vertices[pos].pos[2].y = GetTerrainYAround(x,y,5);
346
gl_vertices[pos].pos[0].x = GetTerrainX(x, y);
347
gl_vertices[pos].pos[0].y = GetTerrainY(x, y);
348
gl_vertices[pos].pos[1].x = GetTerrainXAround(x,y,4);
349
gl_vertices[pos].pos[1].y = GetTerrainYAround(x,y,4);
350
gl_vertices[pos].pos[2].x = GetTerrainXAround(x,y,3);
351
gl_vertices[pos].pos[2].y = GetTerrainYAround(x,y,3);
353
if(update && SETTINGS.video.vbo)
355
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
356
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,(pos-1) * 3 * 2 * sizeof(float),
357
2 * 3 * 2 * sizeof(float), &gl_vertices[pos-1]);
361
void TerrainRenderer::UpdateTriangleColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
363
unsigned int pos = 2 * width * y + x*2;
365
gl_colors[pos].colors[0].r = gl_colors[pos].colors[0].g = gl_colors[pos].colors[0].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
366
gl_colors[pos].colors[1].r = gl_colors[pos].colors[1].g = gl_colors[pos].colors[1].b = GetColor(x, y);
367
gl_colors[pos].colors[2].r = gl_colors[pos].colors[2].g = gl_colors[pos].colors[2].b = GetColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5));
371
gl_colors[pos].colors[0].r = gl_colors[pos].colors[0].g = gl_colors[pos].colors[0].b = GetColor(x, y);
372
gl_colors[pos].colors[1].r = gl_colors[pos].colors[1].g = gl_colors[pos].colors[1].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
373
gl_colors[pos].colors[2].r = gl_colors[pos].colors[2].g = gl_colors[pos].colors[2].b = GetColor(gwv->GetXA(x,y,3), gwv->GetYA(x,y,3));
376
/// Bei Vertexbuffern das die Daten aktualisieren
377
if(update && SETTINGS.video.vbo)
379
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
380
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,(pos-1) * 3 * 3 * sizeof(float),
381
2 * 3 * 3 * sizeof(float), &gl_colors[pos-1]);
385
void TerrainRenderer::UpdateTriangleTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
387
unsigned int pos = 2 * width * y + x*2;
389
unsigned char t1 = gwv->GetNode(x, y).t1;
390
gl_texcoords[pos].pos[0].x = (t1 == 14 || t1 == 15) ? 0.4375f : 0.45f;
391
gl_texcoords[pos].pos[0].y = (t1 == 14 || t1 == 15) ? 0.0f : 0.45f;
392
gl_texcoords[pos].pos[1].y = (t1 == 14 || t1 == 15) ? 0.445312f : 0.0f;
393
gl_texcoords[pos].pos[1].x = (t1 == 14 || t1 == 15) ? 0.0f : 0.225f;
394
gl_texcoords[pos].pos[2].x = (t1 == 14 || t1 == 15) ? 0.84375f : 0.0f;
395
gl_texcoords[pos].pos[2].y = (t1 == 14 || t1 == 15) ? 0.445312f : 0.45f;
399
unsigned char t2 = gwv->GetNode(x, y).t2;
400
gl_texcoords[pos].pos[0].x = (t2 == 14 || t2 == 15) ? 0.4375f : 0.0f;
401
gl_texcoords[pos].pos[0].y = (t2 == 14 || t2 == 15) ? 0.859375f : 0.0f;
402
gl_texcoords[pos].pos[1].x = (t2 == 14 || t2 == 15) ? 0.84375f : 0.235f;
403
gl_texcoords[pos].pos[1].y = (t2 == 14 || t2 == 15) ? 0.445312f : 0.45f;
404
gl_texcoords[pos].pos[2].x = (t2 == 14 || t2 == 15) ? 0.0f : 0.47f;
405
gl_texcoords[pos].pos[2].y = (t2 == 14 || t2 == 15) ? 0.445312f : 0.0f;
408
/// Bei Vertexbuffern das die Daten aktualisieren
409
if(update && SETTINGS.video.vbo)
411
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
412
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,(pos-1) * 3 * 2 * sizeof(float),
413
2 * 3 * 2 * sizeof(float), &gl_texcoords[pos-1]);
333
void TerrainRenderer::UpdateTrianglePos(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
335
unsigned int pos = 2 * width * y + x * 2;
337
gl_vertices[pos].pos[0].x = GetTerrainXAround(x, y, 4);
338
gl_vertices[pos].pos[0].y = GetTerrainYAround(x, y, 4);
339
gl_vertices[pos].pos[1].x = GetTerrainX(x, y);
340
gl_vertices[pos].pos[1].y = GetTerrainY(x, y);
341
gl_vertices[pos].pos[2].x = GetTerrainXAround(x, y, 5);
342
gl_vertices[pos].pos[2].y = GetTerrainYAround(x, y, 5);
346
gl_vertices[pos].pos[0].x = GetTerrainX(x, y);
347
gl_vertices[pos].pos[0].y = GetTerrainY(x, y);
348
gl_vertices[pos].pos[1].x = GetTerrainXAround(x, y, 4);
349
gl_vertices[pos].pos[1].y = GetTerrainYAround(x, y, 4);
350
gl_vertices[pos].pos[2].x = GetTerrainXAround(x, y, 3);
351
gl_vertices[pos].pos[2].y = GetTerrainYAround(x, y, 3);
353
if(update && SETTINGS.video.vbo)
355
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
356
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, (pos - 1) * 3 * 2 * sizeof(float),
357
2 * 3 * 2 * sizeof(float), &gl_vertices[pos - 1]);
361
void TerrainRenderer::UpdateTriangleColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
363
unsigned int pos = 2 * width * y + x * 2;
365
gl_colors[pos].colors[0].r = gl_colors[pos].colors[0].g = gl_colors[pos].colors[0].b = GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4));
366
gl_colors[pos].colors[1].r = gl_colors[pos].colors[1].g = gl_colors[pos].colors[1].b = GetColor(x, y);
367
gl_colors[pos].colors[2].r = gl_colors[pos].colors[2].g = gl_colors[pos].colors[2].b = GetColor(gwv->GetXA(x, y, 5), gwv->GetYA(x, y, 5));
371
gl_colors[pos].colors[0].r = gl_colors[pos].colors[0].g = gl_colors[pos].colors[0].b = GetColor(x, y);
372
gl_colors[pos].colors[1].r = gl_colors[pos].colors[1].g = gl_colors[pos].colors[1].b = GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4));
373
gl_colors[pos].colors[2].r = gl_colors[pos].colors[2].g = gl_colors[pos].colors[2].b = GetColor(gwv->GetXA(x, y, 3), gwv->GetYA(x, y, 3));
376
/// Bei Vertexbuffern das die Daten aktualisieren
377
if(update && SETTINGS.video.vbo)
379
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
380
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, (pos - 1) * 3 * 3 * sizeof(float),
381
2 * 3 * 3 * sizeof(float), &gl_colors[pos - 1]);
385
void TerrainRenderer::UpdateTriangleTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
387
unsigned int pos = 2 * width * y + x * 2;
389
unsigned char t1 = gwv->GetNode(x, y).t1;
390
gl_texcoords[pos].pos[0].x = (t1 == 14 || t1 == 15) ? 0.4375f : 0.45f;
391
gl_texcoords[pos].pos[0].y = (t1 == 14 || t1 == 15) ? 0.0f : 0.45f;
392
gl_texcoords[pos].pos[1].y = (t1 == 14 || t1 == 15) ? 0.445312f : 0.0f;
393
gl_texcoords[pos].pos[1].x = (t1 == 14 || t1 == 15) ? 0.0f : 0.225f;
394
gl_texcoords[pos].pos[2].x = (t1 == 14 || t1 == 15) ? 0.84375f : 0.0f;
395
gl_texcoords[pos].pos[2].y = (t1 == 14 || t1 == 15) ? 0.445312f : 0.45f;
399
unsigned char t2 = gwv->GetNode(x, y).t2;
400
gl_texcoords[pos].pos[0].x = (t2 == 14 || t2 == 15) ? 0.4375f : 0.0f;
401
gl_texcoords[pos].pos[0].y = (t2 == 14 || t2 == 15) ? 0.859375f : 0.0f;
402
gl_texcoords[pos].pos[1].x = (t2 == 14 || t2 == 15) ? 0.84375f : 0.235f;
403
gl_texcoords[pos].pos[1].y = (t2 == 14 || t2 == 15) ? 0.445312f : 0.45f;
404
gl_texcoords[pos].pos[2].x = (t2 == 14 || t2 == 15) ? 0.0f : 0.47f;
405
gl_texcoords[pos].pos[2].y = (t2 == 14 || t2 == 15) ? 0.445312f : 0.0f;
408
/// Bei Vertexbuffern das die Daten aktualisieren
409
if(update && SETTINGS.video.vbo)
411
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
412
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, (pos - 1) * 3 * 2 * sizeof(float),
413
2 * 3 * 2 * sizeof(float), &gl_texcoords[pos - 1]);
417
417
/// Erzeugt die Dreiecke f�r die R�nder
418
void TerrainRenderer::UpdateBorderTrianglePos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
420
unsigned int pos = y * width + x;
422
// F�r VBO-Aktualisierung:
423
// Erzeugte R�nder z�hlen
424
unsigned count_borders = 0;
425
// Erstes Offset merken
426
unsigned first_offset = 0;
429
// Rand links - rechts
430
for(unsigned char i = 0; i < 2; ++i)
432
if(borders[pos].left_right[i])
434
unsigned int offset = borders[pos].left_right_offset[i];
437
first_offset = offset;
439
gl_vertices[offset].pos[i ? 0 : 2].x = GetTerrainX(x, y);
440
gl_vertices[offset].pos[i ? 0 : 2].y = GetTerrainY(x, y);
441
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,4);
442
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,4);
443
gl_vertices[offset].pos[i ? 2 : 0].x = GetBX(x, y, i);
444
gl_vertices[offset].pos[i ? 2 : 0].y = GetBY(x, y, i);
450
// Rand rechts - links
451
for(unsigned char i = 0; i < 2; ++i)
453
if(borders[pos].right_left[i])
455
unsigned int offset = borders[pos].right_left_offset[i];
458
first_offset = offset;
460
gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x,y,4);
461
gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x,y,4);
462
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,3);
463
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,3);
467
gl_vertices[offset].pos[2].x = GetBX(x, y, 1);
468
gl_vertices[offset].pos[2].y = GetBY(x, y, 1);
472
gl_vertices[offset].pos[0].x = GetBXAround(x, y, 0, 3);
473
gl_vertices[offset].pos[0].y = GetBYAround(x, y, 0, 3);
481
for(unsigned char i = 0; i < 2; ++i)
483
if(borders[pos].top_down[i])
485
unsigned int offset = borders[pos].top_down_offset[i];
488
first_offset = offset;
490
gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x,y,5);
491
gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x,y,5);
492
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x,y,4);
493
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x,y,4);
497
gl_vertices[offset].pos[2].x = GetBX(x,y,i);
498
gl_vertices[offset].pos[2].y = GetBY(x,y,i);
502
//x - i + i * rt, y + i, i
503
gl_vertices[offset].pos[0].x = GetBXAround(x, y, i, 5);
504
gl_vertices[offset].pos[0].y = GetBYAround(x, y, i, 5);
511
/// Bei Vertexbuffern das die Daten aktualisieren
512
if(update && SETTINGS.video.vbo)
514
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
515
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,first_offset * 3 * 2 * sizeof(float),
516
count_borders * 3 * 2 * sizeof(float), &gl_vertices[first_offset]);
520
void TerrainRenderer::UpdateBorderTriangleColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
522
unsigned int pos = y * width + x;
524
// F�r VBO-Aktualisierung:
525
// Erzeugte R�nder z�hlen
526
unsigned count_borders = 0;
527
// Erstes Offset merken
528
unsigned first_offset = 0;
531
// Rand links - rechts
532
for(unsigned char i = 0; i < 2; ++i)
534
if(borders[pos].left_right[i])
536
unsigned int offset = borders[pos].left_right_offset[i];
539
first_offset = offset;
541
gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetColor(x, y);
542
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
543
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetBColor(x, y, i);
549
// Rand rechts - links
550
for(unsigned char i = 0; i < 2; ++i)
552
if(borders[pos].right_left[i])
554
unsigned int offset = borders[pos].right_left_offset[i];
557
first_offset = offset;
559
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
560
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x,y,3), gwv->GetYA(x,y,3));
561
gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetBColor(x + i, y, i ? 0 : 1);
568
for(unsigned char i = 0; i < 2; ++i)
570
if(borders[pos].top_down[i])
572
unsigned int offset = borders[pos].top_down_offset[i];
575
first_offset = offset;
577
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5));
578
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x,y,4), gwv->GetYA(x,y,4));
581
gl_colors[offset].colors[2].r = gl_colors[offset].colors[2].g = gl_colors[offset].colors[2].b = GetBColor(x, y, i);
583
gl_colors[offset].colors[0].r = gl_colors[offset].colors[0].g = gl_colors[offset].colors[0].b = GetBColor(gwv->GetXA(x,y,5), gwv->GetYA(x,y,5),i);
589
/// Bei Vertexbuffern das die Daten aktualisieren
590
if(update && SETTINGS.video.vbo)
592
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
593
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,first_offset * 3 * 3 * sizeof(float),
594
count_borders * 3 * 3 * sizeof(float), &gl_colors[first_offset]);
598
void TerrainRenderer::UpdateBorderTriangleTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
600
unsigned int pos = y * width + x;
602
// F�r VBO-Aktualisierung:
603
// Erzeugte R�nder z�hlen
604
unsigned count_borders = 0;
605
// Erstes Offset merken
606
unsigned first_offset = 0;
609
// Rand links - rechts
610
for(unsigned char i = 0; i < 2; ++i)
612
if(borders[pos].left_right[i])
614
unsigned int offset = borders[pos].left_right_offset[i];
617
first_offset = offset;
619
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.0f;
620
gl_texcoords[offset].pos[i ? 0 : 2].y = 0.0f;
621
gl_texcoords[offset].pos[1 ].x = 1.0f;
622
gl_texcoords[offset].pos[1 ].y = 0.0f;
623
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.5f;
624
gl_texcoords[offset].pos[i ? 2 : 0].y = 1.0f;
630
// Rand rechts - links
631
for(unsigned char i = 0; i < 2; ++i)
633
if(borders[pos].right_left[i])
635
unsigned int offset = borders[pos].right_left_offset[i];
638
first_offset = offset;
640
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.0f;
641
gl_texcoords[offset].pos[i ? 2 : 0].y = 0.0f;
642
gl_texcoords[offset].pos[1 ].x = 1.0f;
643
gl_texcoords[offset].pos[1 ].y = 0.0f;
644
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.5f;
645
gl_texcoords[offset].pos[i ? 0 : 2].y = 1.0f;
652
for(unsigned char i = 0; i < 2; ++i)
654
if(borders[pos].top_down[i])
656
unsigned int offset = borders[pos].top_down_offset[i];
659
first_offset = offset;
661
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.0f;
662
gl_texcoords[offset].pos[i ? 2 : 0].y = 0.0f;
663
gl_texcoords[offset].pos[1 ].x = 1.0f;
664
gl_texcoords[offset].pos[1 ].y = 0.0f;
665
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.5f;
666
gl_texcoords[offset].pos[i ? 0 : 2].y = 1.0f;
672
/// Bei Vertexbuffern das die Daten aktualisieren
673
if(update && SETTINGS.video.vbo)
675
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
676
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,first_offset * 3 * 2 * sizeof(float),
677
count_borders * 3 * 2 * sizeof(float), &gl_texcoords[first_offset]);
418
void TerrainRenderer::UpdateBorderTrianglePos(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
420
unsigned int pos = y * width + x;
422
// F�r VBO-Aktualisierung:
423
// Erzeugte R�nder z�hlen
424
unsigned count_borders = 0;
425
// Erstes Offset merken
426
unsigned first_offset = 0;
429
// Rand links - rechts
430
for(unsigned char i = 0; i < 2; ++i)
432
if(borders[pos].left_right[i])
434
unsigned int offset = borders[pos].left_right_offset[i];
437
first_offset = offset;
439
gl_vertices[offset].pos[i ? 0 : 2].x = GetTerrainX(x, y);
440
gl_vertices[offset].pos[i ? 0 : 2].y = GetTerrainY(x, y);
441
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x, y, 4);
442
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x, y, 4);
443
gl_vertices[offset].pos[i ? 2 : 0].x = GetBX(x, y, i);
444
gl_vertices[offset].pos[i ? 2 : 0].y = GetBY(x, y, i);
450
// Rand rechts - links
451
for(unsigned char i = 0; i < 2; ++i)
453
if(borders[pos].right_left[i])
455
unsigned int offset = borders[pos].right_left_offset[i];
458
first_offset = offset;
460
gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x, y, 4);
461
gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x, y, 4);
462
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x, y, 3);
463
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x, y, 3);
467
gl_vertices[offset].pos[2].x = GetBX(x, y, 1);
468
gl_vertices[offset].pos[2].y = GetBY(x, y, 1);
472
gl_vertices[offset].pos[0].x = GetBXAround(x, y, 0, 3);
473
gl_vertices[offset].pos[0].y = GetBYAround(x, y, 0, 3);
481
for(unsigned char i = 0; i < 2; ++i)
483
if(borders[pos].top_down[i])
485
unsigned int offset = borders[pos].top_down_offset[i];
488
first_offset = offset;
490
gl_vertices[offset].pos[i ? 2 : 0].x = GetTerrainXAround(x, y, 5);
491
gl_vertices[offset].pos[i ? 2 : 0].y = GetTerrainYAround(x, y, 5);
492
gl_vertices[offset].pos[1 ].x = GetTerrainXAround(x, y, 4);
493
gl_vertices[offset].pos[1 ].y = GetTerrainYAround(x, y, 4);
497
gl_vertices[offset].pos[2].x = GetBX(x, y, i);
498
gl_vertices[offset].pos[2].y = GetBY(x, y, i);
502
//x - i + i * rt, y + i, i
503
gl_vertices[offset].pos[0].x = GetBXAround(x, y, i, 5);
504
gl_vertices[offset].pos[0].y = GetBYAround(x, y, i, 5);
511
/// Bei Vertexbuffern das die Daten aktualisieren
512
if(update && SETTINGS.video.vbo)
514
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
515
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, first_offset * 3 * 2 * sizeof(float),
516
count_borders * 3 * 2 * sizeof(float), &gl_vertices[first_offset]);
520
void TerrainRenderer::UpdateBorderTriangleColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
522
unsigned int pos = y * width + x;
524
// F�r VBO-Aktualisierung:
525
// Erzeugte R�nder z�hlen
526
unsigned count_borders = 0;
527
// Erstes Offset merken
528
unsigned first_offset = 0;
531
// Rand links - rechts
532
for(unsigned char i = 0; i < 2; ++i)
534
if(borders[pos].left_right[i])
536
unsigned int offset = borders[pos].left_right_offset[i];
539
first_offset = offset;
541
gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetColor(x, y);
542
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4));
543
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetBColor(x, y, i);
549
// Rand rechts - links
550
for(unsigned char i = 0; i < 2; ++i)
552
if(borders[pos].right_left[i])
554
unsigned int offset = borders[pos].right_left_offset[i];
557
first_offset = offset;
559
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4));
560
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x, y, 3), gwv->GetYA(x, y, 3));
561
gl_colors[offset].colors[i ? 0 : 2].r = gl_colors[offset].colors[i ? 0 : 2].g = gl_colors[offset].colors[i ? 0 : 2].b = GetBColor(x + i, y, i ? 0 : 1);
568
for(unsigned char i = 0; i < 2; ++i)
570
if(borders[pos].top_down[i])
572
unsigned int offset = borders[pos].top_down_offset[i];
575
first_offset = offset;
577
gl_colors[offset].colors[i ? 2 : 0].r = gl_colors[offset].colors[i ? 2 : 0].g = gl_colors[offset].colors[i ? 2 : 0].b = GetColor(gwv->GetXA(x, y, 5), gwv->GetYA(x, y, 5));
578
gl_colors[offset].colors[1 ].r = gl_colors[offset].colors[1 ].g = gl_colors[offset].colors[1 ].b = GetColor(gwv->GetXA(x, y, 4), gwv->GetYA(x, y, 4));
581
gl_colors[offset].colors[2].r = gl_colors[offset].colors[2].g = gl_colors[offset].colors[2].b = GetBColor(x, y, i);
583
gl_colors[offset].colors[0].r = gl_colors[offset].colors[0].g = gl_colors[offset].colors[0].b = GetBColor(gwv->GetXA(x, y, 5), gwv->GetYA(x, y, 5), i);
589
/// Bei Vertexbuffern das die Daten aktualisieren
590
if(update && SETTINGS.video.vbo)
592
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
593
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, first_offset * 3 * 3 * sizeof(float),
594
count_borders * 3 * 3 * sizeof(float), &gl_colors[first_offset]);
598
void TerrainRenderer::UpdateBorderTriangleTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
600
unsigned int pos = y * width + x;
602
// F�r VBO-Aktualisierung:
603
// Erzeugte R�nder z�hlen
604
unsigned count_borders = 0;
605
// Erstes Offset merken
606
unsigned first_offset = 0;
609
// Rand links - rechts
610
for(unsigned char i = 0; i < 2; ++i)
612
if(borders[pos].left_right[i])
614
unsigned int offset = borders[pos].left_right_offset[i];
617
first_offset = offset;
619
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.0f;
620
gl_texcoords[offset].pos[i ? 0 : 2].y = 0.0f;
621
gl_texcoords[offset].pos[1 ].x = 1.0f;
622
gl_texcoords[offset].pos[1 ].y = 0.0f;
623
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.5f;
624
gl_texcoords[offset].pos[i ? 2 : 0].y = 1.0f;
630
// Rand rechts - links
631
for(unsigned char i = 0; i < 2; ++i)
633
if(borders[pos].right_left[i])
635
unsigned int offset = borders[pos].right_left_offset[i];
638
first_offset = offset;
640
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.0f;
641
gl_texcoords[offset].pos[i ? 2 : 0].y = 0.0f;
642
gl_texcoords[offset].pos[1 ].x = 1.0f;
643
gl_texcoords[offset].pos[1 ].y = 0.0f;
644
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.5f;
645
gl_texcoords[offset].pos[i ? 0 : 2].y = 1.0f;
652
for(unsigned char i = 0; i < 2; ++i)
654
if(borders[pos].top_down[i])
656
unsigned int offset = borders[pos].top_down_offset[i];
659
first_offset = offset;
661
gl_texcoords[offset].pos[i ? 2 : 0].x = 0.0f;
662
gl_texcoords[offset].pos[i ? 2 : 0].y = 0.0f;
663
gl_texcoords[offset].pos[1 ].x = 1.0f;
664
gl_texcoords[offset].pos[1 ].y = 0.0f;
665
gl_texcoords[offset].pos[i ? 0 : 2].x = 0.5f;
666
gl_texcoords[offset].pos[i ? 0 : 2].y = 1.0f;
672
/// Bei Vertexbuffern das die Daten aktualisieren
673
if(update && SETTINGS.video.vbo)
675
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
676
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, first_offset * 3 * 2 * sizeof(float),
677
count_borders * 3 * 2 * sizeof(float), &gl_texcoords[first_offset]);
681
681
///////////////////////////////////////////////////////////////////////////////
686
686
* @author FloSoft
688
void TerrainRenderer::Draw(GameWorldView * gwv, unsigned int *water)
688
void TerrainRenderer::Draw(GameWorldView* gwv, unsigned int* water)
693
/* if ((gwv->GetXOffset() == gwv->terrain_last_xoffset) && (gwv->GetYOffset() == gwv->terrain_last_yoffset) && (gwv->terrain_list != 0) && (GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0) == gwv->terrain_last_global_animation))
695
glCallList(gwv->terrain_list);
696
*water = gwv->terrain_last_water;
700
gwv->terrain_last_xoffset = gwv->GetXOffset();
701
gwv->terrain_last_yoffset = gwv->GetYOffset();
702
gwv->terrain_last_global_animation = GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0);
704
if (gwv->terrain_list == 0)
705
gwv->terrain_list = glGenLists(1);
707
glNewList(gwv->terrain_list, GL_COMPILE_AND_EXECUTE);*/
711
// nach Texture in Listen sortieren
712
std::list<MapTile> sorted_textures[16];
713
std::list<BorderTile> sorted_borders[5];
715
int lastxo = 0, lastyo = 0;
717
unsigned short tx,ty;
718
unsigned int offset = width * height * 2;
720
// Beim zeichnen immer nur beginnen, wo man auch was sieht
721
for(int y = gwv->GetFirstY(); y < gwv->GetLastY(); ++y)
723
unsigned char last = 255;
724
unsigned char last_border = 255;
726
for(int x = gwv->GetFirstX(); x < gwv->GetLastX(); ++x)
728
ConvertCoords(x, y, tx, ty, &xo, &yo);
730
unsigned char t = gwv->GetGameWorldViewer()->GetNode(tx,ty).t1;
731
if(xo != lastxo || yo != lastyo)
735
++sorted_textures[t].back().count;
738
MapTile tmp = {tx * 2, ty, 1, xo, yo};
739
sorted_textures[t].push_back(tmp);
744
t = gwv->GetGameWorldViewer()->GetNode(tx,ty).t2;
747
++sorted_textures[t].back().count;
750
MapTile tmp = {tx * 2 + 1, ty, 1, xo, yo};
751
sorted_textures[t].push_back(tmp);
756
unsigned char tiles[6] =
758
borders[ty * width + tx].left_right[0],
759
borders[ty * width + tx].left_right[1],
760
borders[ty * width + tx].right_left[0],
761
borders[ty * width + tx].right_left[1],
762
borders[ty * width + tx].top_down[0],
763
borders[ty * width + tx].top_down[1],
766
unsigned int offsets[6] =
768
borders[ty * width + tx].left_right_offset[0],
769
borders[ty * width + tx].left_right_offset[1],
770
borders[ty * width + tx].right_left_offset[0],
771
borders[ty * width + tx].right_left_offset[1],
772
borders[ty * width + tx].top_down_offset[0],
773
borders[ty * width + tx].top_down_offset[1],
776
for(unsigned char i = 0; i < 6; ++i)
780
if(tiles[i] == last_border)
781
++sorted_borders[last_border-1].back().count;
784
last_border = tiles[i];
785
BorderTile tmp = { (int)offsets[ i ], 1, xo, yo};
786
sorted_borders[last_border-1].push_back(tmp);
792
PrepareWaysPoint(gwv, tx, ty, xo, yo);
801
unsigned water_count = 0;
803
for(std::list<MapTile>::iterator it = sorted_textures[TT_WATER].begin(); it != sorted_textures[TT_WATER].end(); ++it)
805
water_count += it->count;
808
if( (gwv->GetLastX() - gwv->GetFirstX()) && (gwv->GetLastY() - gwv->GetFirstY()) )
809
*water = 50 * water_count / ( (gwv->GetLastX() - gwv->GetFirstX()) * (gwv->GetLastY() - gwv->GetFirstY()) );
817
if(SETTINGS.video.vbo)
819
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
820
glVertexPointer(2, GL_FLOAT, 0, NULL);
822
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_texcoords);
823
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
825
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_colors);
826
glColorPointer(3, GL_FLOAT, 0, NULL);
829
glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
830
glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
831
glColorPointer(3, GL_FLOAT, 0, gl_colors);
835
glEnableClientState(GL_VERTEX_ARRAY);
836
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
837
glEnableClientState(GL_COLOR_ARRAY);
840
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
841
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
843
// Verschieben gem�� x und y offset
844
glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
849
for(unsigned char i = 0; i < 16; ++i)
851
if(sorted_textures[i].size())
856
VideoDriverWrapper::inst().BindTexture(GetImage(water, GAMECLIENT.GetGlobalAnimation(8, 5, 2, 0))->GetTexture());
859
VideoDriverWrapper::inst().BindTexture(GetImage(lava, GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0))->GetTexture());
862
VideoDriverWrapper::inst().BindTexture(GetImage(textures, i)->GetTexture());
865
for(std::list<MapTile>::iterator it = sorted_textures[i].begin(); it != sorted_textures[i].end(); ++it)
867
if(it->xo != lastxo || it->yo != lastyo)
869
glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
874
glDrawArrays(GL_TRIANGLES, it->y * width * 3 * 2 + it->x * 3, it->count * 3);
882
glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
886
for(unsigned short i = 0;i<5;++i)
888
if(sorted_borders[i].size())
890
VideoDriverWrapper::inst().BindTexture(GetImage(borders, i)->GetTexture());
892
for(std::list<BorderTile>::iterator it = sorted_borders[i].begin(); it != sorted_borders[i].end(); ++it)
894
if(it->xo != lastxo || it->yo != lastyo)
896
glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
900
glDrawArrays(GL_TRIANGLES, it->offset * 3, it->count * 3);
909
// Wieder zur�ck ins normale modulate
910
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
914
gwv->terrain_last_water = *water;*/
693
/* if ((gwv->GetXOffset() == gwv->terrain_last_xoffset) && (gwv->GetYOffset() == gwv->terrain_last_yoffset) && (gwv->terrain_list != 0) && (GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0) == gwv->terrain_last_global_animation))
695
glCallList(gwv->terrain_list);
696
*water = gwv->terrain_last_water;
700
gwv->terrain_last_xoffset = gwv->GetXOffset();
701
gwv->terrain_last_yoffset = gwv->GetYOffset();
702
gwv->terrain_last_global_animation = GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0);
704
if (gwv->terrain_list == 0)
705
gwv->terrain_list = glGenLists(1);
707
glNewList(gwv->terrain_list, GL_COMPILE_AND_EXECUTE);*/
711
// nach Texture in Listen sortieren
712
std::list<MapTile> sorted_textures[16];
713
std::list<BorderTile> sorted_borders[5];
715
int lastxo = 0, lastyo = 0;
717
unsigned short tx, ty;
718
unsigned int offset = width * height * 2;
720
// Beim zeichnen immer nur beginnen, wo man auch was sieht
721
for(int y = gwv->GetFirstY(); y < gwv->GetLastY(); ++y)
723
unsigned char last = 255;
724
unsigned char last_border = 255;
726
for(int x = gwv->GetFirstX(); x < gwv->GetLastX(); ++x)
728
ConvertCoords(x, y, tx, ty, &xo, &yo);
730
unsigned char t = gwv->GetGameWorldViewer()->GetNode(tx, ty).t1;
731
if(xo != lastxo || yo != lastyo)
735
++sorted_textures[t].back().count;
738
MapTile tmp = {tx * 2, ty, 1, xo, yo};
739
sorted_textures[t].push_back(tmp);
744
t = gwv->GetGameWorldViewer()->GetNode(tx, ty).t2;
747
++sorted_textures[t].back().count;
750
MapTile tmp = {tx * 2 + 1, ty, 1, xo, yo};
751
sorted_textures[t].push_back(tmp);
756
unsigned char tiles[6] =
758
borders[ty* width + tx].left_right[0],
759
borders[ty* width + tx].left_right[1],
760
borders[ty* width + tx].right_left[0],
761
borders[ty* width + tx].right_left[1],
762
borders[ty* width + tx].top_down[0],
763
borders[ty* width + tx].top_down[1],
766
unsigned int offsets[6] =
768
borders[ty* width + tx].left_right_offset[0],
769
borders[ty* width + tx].left_right_offset[1],
770
borders[ty* width + tx].right_left_offset[0],
771
borders[ty* width + tx].right_left_offset[1],
772
borders[ty* width + tx].top_down_offset[0],
773
borders[ty* width + tx].top_down_offset[1],
776
for(unsigned char i = 0; i < 6; ++i)
780
if(tiles[i] == last_border)
781
++sorted_borders[last_border - 1].back().count;
784
last_border = tiles[i];
785
BorderTile tmp = { (int)offsets[ i ], 1, xo, yo};
786
sorted_borders[last_border - 1].push_back(tmp);
792
PrepareWaysPoint(gwv, tx, ty, xo, yo);
801
unsigned water_count = 0;
803
for(std::list<MapTile>::iterator it = sorted_textures[TT_WATER].begin(); it != sorted_textures[TT_WATER].end(); ++it)
805
water_count += it->count;
808
if( (gwv->GetLastX() - gwv->GetFirstX()) && (gwv->GetLastY() - gwv->GetFirstY()) )
809
*water = 50 * water_count / ( (gwv->GetLastX() - gwv->GetFirstX()) * (gwv->GetLastY() - gwv->GetFirstY()) );
817
if(SETTINGS.video.vbo)
819
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
820
glVertexPointer(2, GL_FLOAT, 0, NULL);
822
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
823
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
825
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
826
glColorPointer(3, GL_FLOAT, 0, NULL);
830
glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
831
glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
832
glColorPointer(3, GL_FLOAT, 0, gl_colors);
836
glEnableClientState(GL_VERTEX_ARRAY);
837
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
838
glEnableClientState(GL_COLOR_ARRAY);
841
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
842
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
844
// Verschieben gem�� x und y offset
845
glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
850
for(unsigned char i = 0; i < 16; ++i)
852
if(sorted_textures[i].size())
857
VideoDriverWrapper::inst().BindTexture(GetImage(water, GAMECLIENT.GetGlobalAnimation(8, 5, 2, 0))->GetTexture());
860
VideoDriverWrapper::inst().BindTexture(GetImage(lava, GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0))->GetTexture());
863
VideoDriverWrapper::inst().BindTexture(GetImage(textures, i)->GetTexture());
866
for(std::list<MapTile>::iterator it = sorted_textures[i].begin(); it != sorted_textures[i].end(); ++it)
868
if(it->xo != lastxo || it->yo != lastyo)
870
glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
875
glDrawArrays(GL_TRIANGLES, it->y * width * 3 * 2 + it->x * 3, it->count * 3);
883
glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
887
for(unsigned short i = 0; i < 5; ++i)
889
if(sorted_borders[i].size())
891
VideoDriverWrapper::inst().BindTexture(GetImage(borders, i)->GetTexture());
893
for(std::list<BorderTile>::iterator it = sorted_borders[i].begin(); it != sorted_borders[i].end(); ++it)
895
if(it->xo != lastxo || it->yo != lastyo)
897
glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
901
glDrawArrays(GL_TRIANGLES, it->offset * 3, it->count * 3);
910
// Wieder zur�ck ins normale modulate
911
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
915
gwv->terrain_last_water = *water;*/
929
void TerrainRenderer::ConvertCoords(int x,int y,unsigned short& x_out, unsigned short& y_out, int *xo, int *yo) const
930
void TerrainRenderer::ConvertCoords(int x, int y, unsigned short& x_out, unsigned short& y_out, int* xo, int* yo) const
931
bool mx = false, my = false;
946
*xo = (mx ? (x / width) * TR_W - width * TR_W : (x / width) * TR_W * width );
948
*yo = (my ? (y / height) * TR_H - height * TR_H : (y / height) * TR_H * height);
953
x_out = static_cast<unsigned short>(x);
954
y_out = static_cast<unsigned short>(y);
932
bool mx = false, my = false;
947
*xo = (mx ? (x / width) * TR_W - width * TR_W : (x / width) * TR_W * width );
949
*yo = (my ? (y / height) * TR_H - height * TR_H : (y / height) * TR_H * height);
954
x_out = static_cast<unsigned short>(x);
955
y_out = static_cast<unsigned short>(y);
957
958
struct GL_T2F_C3F_V3F_Struct
964
void TerrainRenderer::PrepareWays(GameWorldView *gwv)
966
for (unsigned char type = 0; type < 4; type++)
968
gwv->sorted_roads[type].clear();
972
void TerrainRenderer::PrepareWaysPoint(GameWorldView *gwv, unsigned short tx, unsigned short ty, int xo, int yo)
974
float xpos = GetTerrainX(tx,ty)-gwv->GetXOffset()+xo;
975
float ypos = GetTerrainY(tx,ty)-gwv->GetYOffset()+yo;
977
// Wegtypen f�r die drei Richtungen
980
Visibility visibility = gwv->GetGameWorldViewer()->GetVisibility(tx,ty);
982
for(unsigned dir = 0; dir < 3; ++dir)
984
if ((type = gwv->GetGameWorldViewer()->GetVisibleRoad(tx,ty, dir, visibility)))
986
MapCoord xa = gwv->GetGameWorldViewer()->GetXA(tx, ty, 3 + dir);
987
MapCoord ya = gwv->GetGameWorldViewer()->GetYA(tx, ty, 3 + dir);
989
float xpos2 = GetTerrainX(xa, ya) - gwv->GetXOffset() + xo;
990
float ypos2 = GetTerrainY(xa, ya) - gwv->GetYOffset() + yo;
992
// Gehen wir �ber einen Kartenrand (horizontale Richung?)
993
if(abs(xpos-xpos2) >= gwv->GetGameWorldViewer()->GetWidth() * TR_W / 2)
995
if(abs(xpos2-int(gwv->GetGameWorldViewer()->GetWidth())*TR_W-xpos) < abs(xpos-xpos2))
996
xpos2 -= gwv->GetGameWorldViewer()->GetWidth()*TR_W;
998
xpos2 += gwv->GetGameWorldViewer()->GetWidth()*TR_W;
1000
// Und dasselbe f�r vertikale Richtung
1001
if(abs(ypos-ypos2) >= gwv->GetGameWorldViewer()->GetHeight() * TR_H / 2)
1003
if(abs(ypos2-int(gwv->GetGameWorldViewer()->GetHeight())*TR_H-ypos) < abs(ypos-ypos2))
1004
ypos2 -= gwv->GetGameWorldViewer()->GetHeight()*TR_H;
1006
ypos2 += gwv->GetGameWorldViewer()->GetHeight()*TR_H;
1011
// Wegtypen "konvertieren"
1014
case RoadSegment::RT_DONKEY:
1015
case RoadSegment::RT_NORMAL:
1017
unsigned t1 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 2);
1018
unsigned t2 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 3);
1020
// Pr�fen, ob Bergwerge gezeichnet werden m�ssen, indem man guckt, ob der Weg einen
1021
// Berg "streift" oder auch eine Bergwiese
1022
if(( (t1 >= TT_MOUNTAIN1 && t1 <= TT_MOUNTAIN4) || t1 == TT_MOUNTAINMEADOW)
1023
|| ( (t2 >= TT_MOUNTAIN1 && t2 <= TT_MOUNTAIN4) || t2 == TT_MOUNTAINMEADOW))
1027
case RoadSegment::RT_BOAT:
1033
gwv->sorted_roads[type].push_back(
1035
xpos, ypos, xpos2, ypos2,
1036
GetColor(tx, ty), GetColor(xa, ya),
1044
void TerrainRenderer::DrawWays(GameWorldView *gwv)
1046
const float begin_end_coords[24] =
1064
if (SETTINGS.video.vbo)
1067
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1070
for (unsigned char type = 0; type < 4; type++)
1073
GL_T2F_C3F_V3F_Struct *tmp = new GL_T2F_C3F_V3F_Struct[gwv->sorted_roads[type].size() * 4];
1075
for (std::list<PreparedRoad>::iterator it = gwv->sorted_roads[type].begin(); it != gwv->sorted_roads[type].end(); ++it)
1080
tmp[i].r = (*it).color1;
1081
tmp[i].g = (*it).color1;
1082
tmp[i].b = (*it).color1;
1084
tmp[i].x = (*it).xpos+begin_end_coords[(*it).dir*8];
1085
tmp[i].y = (*it).ypos+begin_end_coords[(*it).dir*8+1];
1093
tmp[i].r = (*it).color1;
1094
tmp[i].g = (*it).color1;
1095
tmp[i].b = (*it).color1;
1097
tmp[i].x = (*it).xpos+begin_end_coords[(*it).dir*8+2];
1098
tmp[i].y = (*it).ypos+begin_end_coords[(*it).dir*8+3];
1106
tmp[i].r = (*it).color2;
1107
tmp[i].g = (*it).color2;
1108
tmp[i].b = (*it).color2;
1110
tmp[i].x = (*it).xpos2+begin_end_coords[(*it).dir*8+4];
1111
tmp[i].y = (*it).ypos2+begin_end_coords[(*it).dir*8+5];
1119
tmp[i].r = (*it).color2;
1120
tmp[i].g = (*it).color2;
1121
tmp[i].b = (*it).color2;
1123
tmp[i].x = (*it).xpos2+begin_end_coords[(*it).dir*8+6];
1124
tmp[i].y = (*it).ypos2+begin_end_coords[(*it).dir*8+7];
1130
glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp);
1131
VideoDriverWrapper::inst().BindTexture(GetImage(roads, type)->GetTexture());
1132
glDrawArrays(GL_QUADS, 0, i);
1138
void TerrainRenderer::AltitudeChanged(const MapCoord x, const MapCoord y, const GameWorldViewer * gwv)
1140
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1141
UpdateVertexPos(x,y,gwv);
1142
UpdateVertexColor(x,y,gwv);
1144
for(unsigned i = 0;i<6;++i)
1145
UpdateVertexColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1148
// und f�r die R�nder
1149
UpdateBorderVertex(x,y,gwv);
1151
for(unsigned i = 0;i<6;++i)
1152
UpdateBorderVertex(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1154
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1155
UpdateTrianglePos(x,y,gwv,true);
1156
UpdateTriangleColor(x,y,gwv,true);
1158
for(unsigned i = 0;i<6;++i)
1160
UpdateTrianglePos(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1161
UpdateTriangleColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1165
// Auch im zweiten Kreis drumherum die Dreiecke neu berechnen, da die durch die Schatten�nderung der umliegenden
1166
// Punkte auch ge�ndert werden k�nnten
1167
for(unsigned i = 0;i<12;++i)
1168
UpdateTriangleColor(gwv->GetXA2(x,y,i),gwv->GetYA2(x,y,i),gwv,true);
1171
// und f�r die R�nder
1172
UpdateBorderTrianglePos(x,y,gwv,true);
1173
UpdateBorderTriangleColor(x,y,gwv,true);
1175
for(unsigned i = 0;i<6;++i)
1177
UpdateBorderTrianglePos(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1178
UpdateBorderTriangleColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1181
for(unsigned i = 0;i<12;++i)
1182
UpdateBorderTriangleColor(gwv->GetXA2(x,y,i),gwv->GetYA2(x,y,i),gwv,true);
1185
void TerrainRenderer::VisibilityChanged(const MapCoord x, const MapCoord y, const GameWorldViewer * gwv)
1187
/// Noch kein Terrain gebaut? abbrechen
1191
UpdateVertexColor(x,y,gwv);
1192
for(unsigned i = 0;i<6;++i)
1193
UpdateVertexColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1195
// und f�r die R�nder
1196
UpdateBorderVertex(x,y,gwv);
1197
for(unsigned i = 0;i<6;++i)
1198
UpdateBorderVertex(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1200
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1201
UpdateTriangleColor(x,y,gwv,true);
1202
for(unsigned i = 0;i<6;++i)
1203
UpdateTriangleColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1205
// und f�r die R�nder
1206
UpdateBorderTriangleColor(x,y,gwv,true);
1207
for(unsigned i = 0;i<6;++i)
1208
UpdateBorderTriangleColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv,true);
1212
void TerrainRenderer::UpdateAllColors(const GameWorldViewer * gwv)
1214
for(MapCoord y = 0;y<height;++y)
1216
for(MapCoord x = 0;x<width;++x)
1218
UpdateVertexColor(x,y,gwv);
1222
for(MapCoord y = 0;y<height;++y)
1224
for(MapCoord x = 0;x<width;++x)
1226
UpdateBorderVertex(x,y,gwv);
1230
for(MapCoord y = 0;y<height;++y)
1232
for(MapCoord x = 0;x<width;++x)
1234
UpdateTriangleColor(x,y,gwv,false);
1238
for(MapCoord y = 0;y<height;++y)
1240
for(MapCoord x = 0;x<width;++x)
1242
UpdateBorderTriangleColor(x,y,gwv,false);
1247
if(SETTINGS.video.vbo)
1249
// Generiere und Binde den Color Buffer
1250
glGenBuffersARB(1, (GLuint*)&vbo_colors);
1251
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_colors);
1252
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (width * height * 2 + border_count) * 3 * 3 * sizeof(float), gl_colors, GL_STATIC_DRAW_ARB );
1253
glColorPointer(3, GL_FLOAT, 0, NULL);
1256
glColorPointer(3, GL_FLOAT, 0, gl_colors);
965
void TerrainRenderer::PrepareWays(GameWorldView* gwv)
967
for (unsigned char type = 0; type < 4; type++)
969
gwv->sorted_roads[type].clear();
973
void TerrainRenderer::PrepareWaysPoint(GameWorldView* gwv, unsigned short tx, unsigned short ty, int xo, int yo)
975
float xpos = GetTerrainX(tx, ty) - gwv->GetXOffset() + xo;
976
float ypos = GetTerrainY(tx, ty) - gwv->GetYOffset() + yo;
978
// Wegtypen f�r die drei Richtungen
981
Visibility visibility = gwv->GetGameWorldViewer()->GetVisibility(tx, ty);
983
for(unsigned dir = 0; dir < 3; ++dir)
985
if ((type = gwv->GetGameWorldViewer()->GetVisibleRoad(tx, ty, dir, visibility)))
987
MapCoord xa = gwv->GetGameWorldViewer()->GetXA(tx, ty, 3 + dir);
988
MapCoord ya = gwv->GetGameWorldViewer()->GetYA(tx, ty, 3 + dir);
990
float xpos2 = GetTerrainX(xa, ya) - gwv->GetXOffset() + xo;
991
float ypos2 = GetTerrainY(xa, ya) - gwv->GetYOffset() + yo;
993
// Gehen wir �ber einen Kartenrand (horizontale Richung?)
994
if(abs(xpos - xpos2) >= gwv->GetGameWorldViewer()->GetWidth() * TR_W / 2)
996
if(abs(xpos2 - int(gwv->GetGameWorldViewer()->GetWidth())*TR_W - xpos) < abs(xpos - xpos2))
997
xpos2 -= gwv->GetGameWorldViewer()->GetWidth() * TR_W;
999
xpos2 += gwv->GetGameWorldViewer()->GetWidth() * TR_W;
1001
// Und dasselbe f�r vertikale Richtung
1002
if(abs(ypos - ypos2) >= gwv->GetGameWorldViewer()->GetHeight() * TR_H / 2)
1004
if(abs(ypos2 - int(gwv->GetGameWorldViewer()->GetHeight())*TR_H - ypos) < abs(ypos - ypos2))
1005
ypos2 -= gwv->GetGameWorldViewer()->GetHeight() * TR_H;
1007
ypos2 += gwv->GetGameWorldViewer()->GetHeight() * TR_H;
1012
// Wegtypen "konvertieren"
1015
case RoadSegment::RT_DONKEY:
1016
case RoadSegment::RT_NORMAL:
1018
unsigned t1 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 2);
1019
unsigned t2 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 3);
1021
// Pr�fen, ob Bergwerge gezeichnet werden m�ssen, indem man guckt, ob der Weg einen
1022
// Berg "streift" oder auch eine Bergwiese
1023
if(( (t1 >= TT_MOUNTAIN1 && t1 <= TT_MOUNTAIN4) || t1 == TT_MOUNTAINMEADOW)
1024
|| ( (t2 >= TT_MOUNTAIN1 && t2 <= TT_MOUNTAIN4) || t2 == TT_MOUNTAINMEADOW))
1028
case RoadSegment::RT_BOAT:
1034
gwv->sorted_roads[type].push_back(
1036
xpos, ypos, xpos2, ypos2,
1037
GetColor(tx, ty), GetColor(xa, ya),
1045
void TerrainRenderer::DrawWays(GameWorldView* gwv)
1047
const float begin_end_coords[24] =
1065
if (SETTINGS.video.vbo)
1068
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1071
for (unsigned char type = 0; type < 4; type++)
1074
GL_T2F_C3F_V3F_Struct* tmp = new GL_T2F_C3F_V3F_Struct[gwv->sorted_roads[type].size() * 4];
1076
for (std::list<PreparedRoad>::iterator it = gwv->sorted_roads[type].begin(); it != gwv->sorted_roads[type].end(); ++it)
1081
tmp[i].r = (*it).color1;
1082
tmp[i].g = (*it).color1;
1083
tmp[i].b = (*it).color1;
1085
tmp[i].x = (*it).xpos + begin_end_coords[(*it).dir * 8];
1086
tmp[i].y = (*it).ypos + begin_end_coords[(*it).dir * 8 + 1];
1094
tmp[i].r = (*it).color1;
1095
tmp[i].g = (*it).color1;
1096
tmp[i].b = (*it).color1;
1098
tmp[i].x = (*it).xpos + begin_end_coords[(*it).dir * 8 + 2];
1099
tmp[i].y = (*it).ypos + begin_end_coords[(*it).dir * 8 + 3];
1107
tmp[i].r = (*it).color2;
1108
tmp[i].g = (*it).color2;
1109
tmp[i].b = (*it).color2;
1111
tmp[i].x = (*it).xpos2 + begin_end_coords[(*it).dir * 8 + 4];
1112
tmp[i].y = (*it).ypos2 + begin_end_coords[(*it).dir * 8 + 5];
1120
tmp[i].r = (*it).color2;
1121
tmp[i].g = (*it).color2;
1122
tmp[i].b = (*it).color2;
1124
tmp[i].x = (*it).xpos2 + begin_end_coords[(*it).dir * 8 + 6];
1125
tmp[i].y = (*it).ypos2 + begin_end_coords[(*it).dir * 8 + 7];
1131
glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp);
1132
VideoDriverWrapper::inst().BindTexture(GetImage(roads, type)->GetTexture());
1133
glDrawArrays(GL_QUADS, 0, i);
1139
void TerrainRenderer::AltitudeChanged(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
1141
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1142
UpdateVertexPos(x, y, gwv);
1143
UpdateVertexColor(x, y, gwv);
1145
for(unsigned i = 0; i < 6; ++i)
1146
UpdateVertexColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
1149
// und f�r die R�nder
1150
UpdateBorderVertex(x, y, gwv);
1152
for(unsigned i = 0; i < 6; ++i)
1153
UpdateBorderVertex(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
1155
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1156
UpdateTrianglePos(x, y, gwv, true);
1157
UpdateTriangleColor(x, y, gwv, true);
1159
for(unsigned i = 0; i < 6; ++i)
1161
UpdateTrianglePos(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1162
UpdateTriangleColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1166
// Auch im zweiten Kreis drumherum die Dreiecke neu berechnen, da die durch die Schatten�nderung der umliegenden
1167
// Punkte auch ge�ndert werden k�nnten
1168
for(unsigned i = 0; i < 12; ++i)
1169
UpdateTriangleColor(gwv->GetXA2(x, y, i), gwv->GetYA2(x, y, i), gwv, true);
1172
// und f�r die R�nder
1173
UpdateBorderTrianglePos(x, y, gwv, true);
1174
UpdateBorderTriangleColor(x, y, gwv, true);
1176
for(unsigned i = 0; i < 6; ++i)
1178
UpdateBorderTrianglePos(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1179
UpdateBorderTriangleColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1182
for(unsigned i = 0; i < 12; ++i)
1183
UpdateBorderTriangleColor(gwv->GetXA2(x, y, i), gwv->GetYA2(x, y, i), gwv, true);
1186
void TerrainRenderer::VisibilityChanged(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
1188
/// Noch kein Terrain gebaut? abbrechen
1192
UpdateVertexColor(x, y, gwv);
1193
for(unsigned i = 0; i < 6; ++i)
1194
UpdateVertexColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
1196
// und f�r die R�nder
1197
UpdateBorderVertex(x, y, gwv);
1198
for(unsigned i = 0; i < 6; ++i)
1199
UpdateBorderVertex(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
1201
// den selbst sowieso die Punkte darum updaten, da sich bei letzteren die Schattierung ge�ndert haben k�nnte
1202
UpdateTriangleColor(x, y, gwv, true);
1203
for(unsigned i = 0; i < 6; ++i)
1204
UpdateTriangleColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1206
// und f�r die R�nder
1207
UpdateBorderTriangleColor(x, y, gwv, true);
1208
for(unsigned i = 0; i < 6; ++i)
1209
UpdateBorderTriangleColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv, true);
1213
void TerrainRenderer::UpdateAllColors(const GameWorldViewer* gwv)
1215
for(MapCoord y = 0; y < height; ++y)
1217
for(MapCoord x = 0; x < width; ++x)
1219
UpdateVertexColor(x, y, gwv);
1223
for(MapCoord y = 0; y < height; ++y)
1225
for(MapCoord x = 0; x < width; ++x)
1227
UpdateBorderVertex(x, y, gwv);
1231
for(MapCoord y = 0; y < height; ++y)
1233
for(MapCoord x = 0; x < width; ++x)
1235
UpdateTriangleColor(x, y, gwv, false);
1239
for(MapCoord y = 0; y < height; ++y)
1241
for(MapCoord x = 0; x < width; ++x)
1243
UpdateBorderTriangleColor(x, y, gwv, false);
1248
if(SETTINGS.video.vbo)
1250
// Generiere und Binde den Color Buffer
1251
glGenBuffersARB(1, (GLuint*)&vbo_colors);
1252
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
1253
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (width * height * 2 + border_count) * 3 * 3 * sizeof(float), gl_colors, GL_STATIC_DRAW_ARB );
1254
glColorPointer(3, GL_FLOAT, 0, NULL);
1257
glColorPointer(3, GL_FLOAT, 0, gl_colors);