~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/TerrainRenderer.cpp

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: TerrainRenderer.cpp 9164 2014-02-17 11:45:14Z marcus $
 
1
// $Id: TerrainRenderer.cpp 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
31
31
///////////////////////////////////////////////////////////////////////////////
32
32
// Makros / Defines
33
33
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
34
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
35
 
        #undef THIS_FILE
36
 
        static char THIS_FILE[] = __FILE__;
 
34
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
35
#undef THIS_FILE
 
36
static char THIS_FILE[] = __FILE__;
37
37
#endif
38
38
 
39
39
TerrainRenderer::TerrainRenderer() :
40
 
        vertices(NULL),
41
 
        gl_vertices(NULL), gl_texcoords(NULL), gl_colors(NULL),
42
 
        vbo_vertices(0), vbo_texcoords(0), vbo_colors(0),
43
 
        borders(NULL), border_count(0)
44
 
        {}
 
40
    vertices(NULL),
 
41
    gl_vertices(NULL), gl_texcoords(NULL), gl_colors(NULL),
 
42
    vbo_vertices(0), vbo_texcoords(0), vbo_colors(0),
 
43
    borders(NULL), border_count(0)
 
44
{}
45
45
 
46
46
TerrainRenderer::~TerrainRenderer()
47
47
{
48
 
        if(SETTINGS.video.vbo)
49
 
        {
50
 
                glDeleteBuffersARB(1, (const GLuint*)&vbo_vertices);
51
 
                glDeleteBuffersARB(1, (const GLuint*)&vbo_texcoords);
52
 
                glDeleteBuffersARB(1, (const GLuint*)&vbo_colors);
53
 
        }
54
 
 
55
 
        delete[] vertices;
56
 
 
57
 
        delete[] gl_vertices;
58
 
        delete[] gl_texcoords;
59
 
        delete[] gl_colors;
60
 
 
61
 
        delete[] borders;
 
48
    if(SETTINGS.video.vbo)
 
49
    {
 
50
        glDeleteBuffersARB(1, (const GLuint*)&vbo_vertices);
 
51
        glDeleteBuffersARB(1, (const GLuint*)&vbo_texcoords);
 
52
        glDeleteBuffersARB(1, (const GLuint*)&vbo_colors);
 
53
    }
 
54
 
 
55
    delete[] vertices;
 
56
 
 
57
    delete[] gl_vertices;
 
58
    delete[] gl_texcoords;
 
59
    delete[] gl_colors;
 
60
 
 
61
    delete[] borders;
62
62
}
63
63
 
64
 
void GetPointAround(int& x, int& y,const unsigned dir)
 
64
void GetPointAround(int& x, int& y, const unsigned dir)
65
65
{
66
 
        switch(dir)
67
 
        {
68
 
        case 0: x = x - 1; break;
69
 
        case 1: x = x - !(y&1); break;
70
 
        case 2: x = x + (y&1); break;
71
 
        case 3: x = x + 1; break;
72
 
        case 4: x = x + (y&1); break;
73
 
        case 5: x = x - !(y&1); break;
74
 
        }
 
66
    switch(dir)
 
67
    {
 
68
        case 0: x = x - 1; break;
 
69
        case 1: x = x - !(y&1); break;
 
70
        case 2: x = x + (y&1); break;
 
71
        case 3: x = x + 1; break;
 
72
        case 4: x = x + (y&1); break;
 
73
        case 5: x = x - !(y&1); break;
 
74
    }
75
75
 
76
 
        switch(dir)
77
 
        {
78
 
        default: break;
79
 
        case 1:
80
 
        case 2: --y; break;
81
 
        case 4:
82
 
        case 5: ++y; break;
83
 
        }
 
76
    switch(dir)
 
77
    {
 
78
        default: break;
 
79
        case 1:
 
80
        case 2: --y; break;
 
81
        case 4:
 
82
        case 5: ++y; break;
 
83
    }
84
84
}
85
85
 
86
86
float TerrainRenderer::GetTerrainXAround(int x,  int y, const unsigned dir)
87
87
{
88
 
        unsigned short tx,ty;
89
 
 
90
 
        GetPointAround(x,y,dir);
91
 
 
92
 
        int xo,yo;
93
 
        ConvertCoords(x,y,tx,ty,&xo,&yo);
94
 
 
95
 
        return GetTerrainX(tx,ty)+xo;
 
88
    unsigned short tx, ty;
 
89
 
 
90
    GetPointAround(x, y, dir);
 
91
 
 
92
    int xo, yo;
 
93
    ConvertCoords(x, y, tx, ty, &xo, &yo);
 
94
 
 
95
    return GetTerrainX(tx, ty) + xo;
96
96
}
97
97
 
98
98
float TerrainRenderer::GetTerrainYAround(int x,  int y, const unsigned dir)
99
99
{
100
 
        unsigned short tx,ty;
101
 
 
102
 
        GetPointAround(x,y,dir);
103
 
 
104
 
        int xo,yo;
105
 
        ConvertCoords(x,y,tx,ty,&xo,&yo);
106
 
 
107
 
        return GetTerrainY(tx,ty)+yo;
 
100
    unsigned short tx, ty;
 
101
 
 
102
    GetPointAround(x, y, dir);
 
103
 
 
104
    int xo, yo;
 
105
    ConvertCoords(x, y, tx, ty, &xo, &yo);
 
106
 
 
107
    return GetTerrainY(tx, ty) + yo;
108
108
}
109
109
 
110
110
float TerrainRenderer::GetBXAround(int x, int y, const unsigned char triangle, const unsigned char dir)
111
111
{
112
 
        unsigned short tx,ty;
113
 
 
114
 
        GetPointAround(x,y,dir);
115
 
 
116
 
        int xo,yo;
117
 
        ConvertCoords(x,y,tx,ty,&xo,&yo);
118
 
 
119
 
        return GetBX(tx,ty,triangle)+xo;
 
112
    unsigned short tx, ty;
 
113
 
 
114
    GetPointAround(x, y, dir);
 
115
 
 
116
    int xo, yo;
 
117
    ConvertCoords(x, y, tx, ty, &xo, &yo);
 
118
 
 
119
    return GetBX(tx, ty, triangle) + xo;
120
120
}
121
121
 
122
122
float TerrainRenderer::GetBYAround(int x, int y, const unsigned char triangle, const unsigned char dir)
123
123
{
124
 
        unsigned short tx,ty;
125
 
 
126
 
        GetPointAround(x,y,dir);
127
 
 
128
 
        int xo,yo;
129
 
        ConvertCoords(x,y,tx,ty,&xo,&yo);
130
 
 
131
 
        return GetBY(tx,ty,triangle)+yo;
 
124
    unsigned short tx, ty;
 
125
 
 
126
    GetPointAround(x, y, dir);
 
127
 
 
128
    int xo, yo;
 
129
    ConvertCoords(x, y, tx, ty, &xo, &yo);
 
130
 
 
131
    return GetBY(tx, ty, triangle) + yo;
132
132
}
133
133
 
134
134
///////////////////////////////////////////////////////////////////////////////
137
137
 *
138
138
 *  @author OLiver
139
139
 */
140
 
void TerrainRenderer::GenerateVertices(const GameWorldViewer * gwv)
 
140
void TerrainRenderer::GenerateVertices(const GameWorldViewer* gwv)
141
141
{
142
 
        delete[] vertices;
143
 
        vertices = new Vertex[width * height];
144
 
        memset(vertices, 0, sizeof(Vertex) * width * height);
145
 
 
146
 
        // Terrain generieren
147
 
        for(unsigned short y = 0; y < height; ++y)
148
 
        {
149
 
                for(unsigned short x = 0; x < width; ++x)
150
 
                {
151
 
                        UpdateVertexPos(x,y,gwv);
152
 
                        UpdateVertexColor(x,y,gwv);
153
 
                        UpdateVertexTerrain(x,y,gwv);
154
 
                }
155
 
        }
156
 
 
157
 
        // R�nder generieren
158
 
        for(unsigned short y = 0; y < height; ++y)
159
 
        {
160
 
                for(unsigned short x = 0; x < width; ++x)
161
 
                {
162
 
                        UpdateBorderVertex(x,y,gwv);
163
 
                }
164
 
        }
 
142
    delete[] vertices;
 
143
    vertices = new Vertex[width * height];
 
144
    memset(vertices, 0, sizeof(Vertex) * width * height);
 
145
 
 
146
    // Terrain generieren
 
147
    for(unsigned short y = 0; y < height; ++y)
 
148
    {
 
149
        for(unsigned short x = 0; x < width; ++x)
 
150
        {
 
151
            UpdateVertexPos(x, y, gwv);
 
152
            UpdateVertexColor(x, y, gwv);
 
153
            UpdateVertexTerrain(x, y, gwv);
 
154
        }
 
155
    }
 
156
 
 
157
    // R�nder generieren
 
158
    for(unsigned short y = 0; y < height; ++y)
 
159
    {
 
160
        for(unsigned short x = 0; x < width; ++x)
 
161
        {
 
162
            UpdateBorderVertex(x, y, gwv);
 
163
        }
 
164
    }
165
165
}
166
166
 
167
167
/// erzeugt Vertex
168
 
void TerrainRenderer::UpdateVertexPos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
169
 
{
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 );
172
 
}
173
 
 
174
 
 
175
 
void TerrainRenderer::UpdateVertexColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
176
 
{
177
 
        switch(gwv->GetVisibility(x,y))
178
 
        {
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;
183
 
        // Normal sichtbar
184
 
        case VIS_VISIBLE: GetVertex(x,y).pos.color = float(gwv->GetNode(x,y).shadow  + 0x40) / float(0xFF); break;
185
 
        }
186
 
}
187
 
 
188
 
void TerrainRenderer::UpdateVertexTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv)
189
 
{
190
 
        if(gwv->GetNode(x,y).t1 < 20)
191
 
                GetVertex(x,y).terrain[0] = gwv->GetNode(x,y).t1;
192
 
 
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)
 
169
{
 
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 );
 
172
}
 
173
 
 
174
 
 
175
void TerrainRenderer::UpdateVertexColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
 
176
{
 
177
    switch(gwv->GetVisibility(x, y))
 
178
    {
 
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;
 
183
            // Normal sichtbar
 
184
        case VIS_VISIBLE: GetVertex(x, y).pos.color = float(gwv->GetNode(x, y).shadow  + 0x40) / float(0xFF); break;
 
185
    }
 
186
}
 
187
 
 
188
void TerrainRenderer::UpdateVertexTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
 
189
{
 
190
    if(gwv->GetNode(x, y).t1 < 20)
 
191
        GetVertex(x, y).terrain[0] = gwv->GetNode(x, y).t1;
 
192
 
 
193
    if(gwv->GetNode(x, y).t2 < 20)
 
194
        GetVertex(x, y).terrain[1] = gwv->GetNode(x, y).t2;
195
195
}
196
196
 
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)
199
199
{
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;
204
204
 
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;
208
208
 
209
209
}
210
210
 
215
215
 *  @author OLiver
216
216
 *  @author FloSoft
217
217
 */
218
 
void TerrainRenderer::GenerateOpenGL(const GameWorldViewer * gwv)
 
218
void TerrainRenderer::GenerateOpenGL(const GameWorldViewer* gwv)
219
219
{
220
 
        width = gwv->GetWidth();
221
 
        height = gwv->GetHeight();
222
 
        LandscapeType lt = gwv->GetLandscapeType();
223
 
 
224
 
        GenerateVertices(gwv);
225
 
 
226
 
        unsigned int offset = width * height * 2;
227
 
 
228
 
        // R�nder z�hlen
229
 
        borders = new Borders[width * height];
230
 
        for(unsigned short y = 0; y < height; ++y)
231
 
        {
232
 
                for(unsigned short x = 0; x < width; ++x)
233
 
                {
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;
237
 
 
238
 
                        if( (borders[pos].left_right[0] = BORDER_TABLES[lt][t1][t2][1]) )
239
 
                        {
240
 
                                borders[pos].left_right_offset[0] = offset + border_count;
241
 
                                ++border_count;
242
 
                        }
243
 
                        if( (borders[pos].left_right[1] = BORDER_TABLES[lt][t1][t2][0]) )
244
 
                        {
245
 
                                borders[pos].left_right_offset[1] = offset + border_count;
246
 
                                ++border_count;
247
 
                        }
248
 
 
249
 
                        t1 = gwv->GetNodeAround(x, y,3).t1;
250
 
                        if( (borders[pos].right_left[0] = BORDER_TABLES[lt][t2][t1][1]) )
251
 
                        {
252
 
                                borders[pos].right_left_offset[0] = offset + border_count;
253
 
                                ++border_count;
254
 
                        }
255
 
                        if( (borders[pos].right_left[1] = BORDER_TABLES[lt][t2][t1][0]) )
256
 
                        {
257
 
                                borders[pos].right_left_offset[1] = offset + border_count;
258
 
                                ++border_count;
259
 
                        }
260
 
 
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]) )
264
 
                        {
265
 
                                borders[pos].top_down_offset[0] = offset + border_count;
266
 
                                ++border_count;
267
 
                        }
268
 
                        if( (borders[pos].top_down[1] = BORDER_TABLES[lt][t1][t2][0]) )
269
 
                        {
270
 
                                borders[pos].top_down_offset[1] = offset + border_count;
271
 
                                ++border_count;
272
 
                        }
273
 
                }
274
 
        }
275
 
 
276
 
        gl_vertices = new Triangle[offset + border_count];
277
 
        gl_texcoords = new Triangle[offset + border_count];
278
 
        gl_colors = new ColorTriangle[offset + border_count];
279
 
 
280
 
        // Normales Terrain erzeugen
281
 
        for(unsigned short y = 0; y < height; ++y)
282
 
        {
283
 
                for(unsigned short x = 0; x < width; ++x)
284
 
                {
285
 
                        UpdateTrianglePos(x,y,gwv,false);
286
 
                        UpdateTriangleColor(x,y,gwv,false);
287
 
                        UpdateTriangleTerrain(x,y,gwv,false);
288
 
                }
289
 
        }
290
 
 
291
 
        // R�nder erzeugen
292
 
        for(unsigned short y = 0; y < height; ++y)
293
 
        {
294
 
                for(unsigned short x = 0; x < width; ++x)
295
 
                {
296
 
                        UpdateBorderTrianglePos(x,y,gwv,false);
297
 
                        UpdateBorderTriangleColor(x,y,gwv,false);
298
 
                        UpdateBorderTriangleTerrain(x,y,gwv,false);
299
 
                }
300
 
        }
301
 
        //unsigned buffer_size = (offset ) * 2 * 3 * sizeof(float);
302
 
 
303
 
        if(SETTINGS.video.vbo)
304
 
        {
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);
310
 
 
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);
316
 
 
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);
322
 
        }
323
 
        else
324
 
        {
325
 
                glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
326
 
                glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
327
 
                glColorPointer(3, GL_FLOAT, 0, gl_colors);
328
 
        }
 
220
    width = gwv->GetWidth();
 
221
    height = gwv->GetHeight();
 
222
    LandscapeType lt = gwv->GetLandscapeType();
 
223
 
 
224
    GenerateVertices(gwv);
 
225
 
 
226
    unsigned int offset = width * height * 2;
 
227
 
 
228
    // R�nder z�hlen
 
229
    borders = new Borders[width * height];
 
230
    for(unsigned short y = 0; y < height; ++y)
 
231
    {
 
232
        for(unsigned short x = 0; x < width; ++x)
 
233
        {
 
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;
 
237
 
 
238
            if( (borders[pos].left_right[0] = BORDER_TABLES[lt][t1][t2][1]) )
 
239
            {
 
240
                borders[pos].left_right_offset[0] = offset + border_count;
 
241
                ++border_count;
 
242
            }
 
243
            if( (borders[pos].left_right[1] = BORDER_TABLES[lt][t1][t2][0]) )
 
244
            {
 
245
                borders[pos].left_right_offset[1] = offset + border_count;
 
246
                ++border_count;
 
247
            }
 
248
 
 
249
            t1 = gwv->GetNodeAround(x, y, 3).t1;
 
250
            if( (borders[pos].right_left[0] = BORDER_TABLES[lt][t2][t1][1]) )
 
251
            {
 
252
                borders[pos].right_left_offset[0] = offset + border_count;
 
253
                ++border_count;
 
254
            }
 
255
            if( (borders[pos].right_left[1] = BORDER_TABLES[lt][t2][t1][0]) )
 
256
            {
 
257
                borders[pos].right_left_offset[1] = offset + border_count;
 
258
                ++border_count;
 
259
            }
 
260
 
 
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]) )
 
264
            {
 
265
                borders[pos].top_down_offset[0] = offset + border_count;
 
266
                ++border_count;
 
267
            }
 
268
            if( (borders[pos].top_down[1] = BORDER_TABLES[lt][t1][t2][0]) )
 
269
            {
 
270
                borders[pos].top_down_offset[1] = offset + border_count;
 
271
                ++border_count;
 
272
            }
 
273
        }
 
274
    }
 
275
 
 
276
    gl_vertices = new Triangle[offset + border_count];
 
277
    gl_texcoords = new Triangle[offset + border_count];
 
278
    gl_colors = new ColorTriangle[offset + border_count];
 
279
 
 
280
    // Normales Terrain erzeugen
 
281
    for(unsigned short y = 0; y < height; ++y)
 
282
    {
 
283
        for(unsigned short x = 0; x < width; ++x)
 
284
        {
 
285
            UpdateTrianglePos(x, y, gwv, false);
 
286
            UpdateTriangleColor(x, y, gwv, false);
 
287
            UpdateTriangleTerrain(x, y, gwv, false);
 
288
        }
 
289
    }
 
290
 
 
291
    // R�nder erzeugen
 
292
    for(unsigned short y = 0; y < height; ++y)
 
293
    {
 
294
        for(unsigned short x = 0; x < width; ++x)
 
295
        {
 
296
            UpdateBorderTrianglePos(x, y, gwv, false);
 
297
            UpdateBorderTriangleColor(x, y, gwv, false);
 
298
            UpdateBorderTriangleTerrain(x, y, gwv, false);
 
299
        }
 
300
    }
 
301
    //unsigned buffer_size = (offset ) * 2 * 3 * sizeof(float);
 
302
 
 
303
    if(SETTINGS.video.vbo)
 
304
    {
 
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);
 
310
 
 
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);
 
316
 
 
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);
 
322
    }
 
323
    else
 
324
    {
 
325
        glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
 
326
        glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
 
327
        glColorPointer(3, GL_FLOAT, 0, gl_colors);
 
328
    }
329
329
}
330
330
 
331
331
/// Erzeugt fertiges Dreieick f�r OpenGL
332
332
 
333
 
void TerrainRenderer::UpdateTrianglePos(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
334
 
{
335
 
        unsigned int pos = 2 * width * y + x*2;
336
 
 
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);
343
 
 
344
 
        ++pos;
345
 
 
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);
352
 
 
353
 
        if(update && SETTINGS.video.vbo)
354
 
        {
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]);
358
 
        }
359
 
}
360
 
 
361
 
void TerrainRenderer::UpdateTriangleColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
362
 
{
363
 
        unsigned int pos = 2 * width * y + x*2;
364
 
 
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));
368
 
 
369
 
        ++pos;
370
 
 
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));
374
 
 
375
 
 
376
 
        /// Bei Vertexbuffern das die Daten aktualisieren
377
 
        if(update && SETTINGS.video.vbo)
378
 
        {
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]);
382
 
        }
383
 
}
384
 
 
385
 
void TerrainRenderer::UpdateTriangleTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
386
 
{
387
 
        unsigned int pos = 2 * width * y + x*2;
388
 
 
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;
396
 
 
397
 
        ++pos;
398
 
 
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;
406
 
 
407
 
 
408
 
        /// Bei Vertexbuffern das die Daten aktualisieren
409
 
        if(update && SETTINGS.video.vbo)
410
 
        {
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]);
414
 
        }
 
333
void TerrainRenderer::UpdateTrianglePos(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
334
{
 
335
    unsigned int pos = 2 * width * y + x * 2;
 
336
 
 
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);
 
343
 
 
344
    ++pos;
 
345
 
 
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);
 
352
 
 
353
    if(update && SETTINGS.video.vbo)
 
354
    {
 
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]);
 
358
    }
 
359
}
 
360
 
 
361
void TerrainRenderer::UpdateTriangleColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
362
{
 
363
    unsigned int pos = 2 * width * y + x * 2;
 
364
 
 
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));
 
368
 
 
369
    ++pos;
 
370
 
 
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));
 
374
 
 
375
 
 
376
    /// Bei Vertexbuffern das die Daten aktualisieren
 
377
    if(update && SETTINGS.video.vbo)
 
378
    {
 
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]);
 
382
    }
 
383
}
 
384
 
 
385
void TerrainRenderer::UpdateTriangleTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
386
{
 
387
    unsigned int pos = 2 * width * y + x * 2;
 
388
 
 
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;
 
396
 
 
397
    ++pos;
 
398
 
 
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;
 
406
 
 
407
 
 
408
    /// Bei Vertexbuffern das die Daten aktualisieren
 
409
    if(update && SETTINGS.video.vbo)
 
410
    {
 
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]);
 
414
    }
415
415
}
416
416
 
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)
419
 
{
420
 
        unsigned int pos = y * width + x;
421
 
 
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;
427
 
 
428
 
 
429
 
        // Rand links - rechts
430
 
        for(unsigned char i = 0; i < 2; ++i)
431
 
        {
432
 
                if(borders[pos].left_right[i])
433
 
                {
434
 
                        unsigned int offset = borders[pos].left_right_offset[i];
435
 
 
436
 
                        if(!first_offset)
437
 
                                first_offset = offset;
438
 
 
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);
445
 
 
446
 
                        ++count_borders;
447
 
                }
448
 
        }
449
 
 
450
 
        // Rand rechts - links
451
 
        for(unsigned char i = 0; i < 2; ++i)
452
 
        {
453
 
                if(borders[pos].right_left[i])
454
 
                {
455
 
                        unsigned int offset = borders[pos].right_left_offset[i];
456
 
 
457
 
                        if(!first_offset)
458
 
                                first_offset = offset;
459
 
 
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);
464
 
 
465
 
                        if(i == 0)
466
 
                        {
467
 
                                gl_vertices[offset].pos[2].x = GetBX(x, y, 1);
468
 
                                gl_vertices[offset].pos[2].y = GetBY(x, y, 1);
469
 
                        }
470
 
                        else
471
 
                        {
472
 
                                gl_vertices[offset].pos[0].x = GetBXAround(x, y, 0, 3);
473
 
                                gl_vertices[offset].pos[0].y = GetBYAround(x, y, 0, 3);
474
 
                        }
475
 
 
476
 
                        ++count_borders;
477
 
                }
478
 
        }
479
 
 
480
 
        // Rand oben - unten
481
 
        for(unsigned char i = 0; i < 2; ++i)
482
 
        {
483
 
                if(borders[pos].top_down[i])
484
 
                {
485
 
                        unsigned int offset = borders[pos].top_down_offset[i];
486
 
 
487
 
                        if(!first_offset)
488
 
                                first_offset = offset;
489
 
 
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);
494
 
 
495
 
                        if(i == 0)
496
 
                        {
497
 
                                gl_vertices[offset].pos[2].x = GetBX(x,y,i);
498
 
                                gl_vertices[offset].pos[2].y = GetBY(x,y,i);
499
 
                        }
500
 
                        else
501
 
                        {
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);
505
 
                        }
506
 
 
507
 
                        ++count_borders;
508
 
                }
509
 
        }
510
 
 
511
 
        /// Bei Vertexbuffern das die Daten aktualisieren
512
 
        if(update && SETTINGS.video.vbo)
513
 
        {
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]);
517
 
        }
518
 
}
519
 
 
520
 
void TerrainRenderer::UpdateBorderTriangleColor(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
521
 
{
522
 
        unsigned int pos = y * width + x;
523
 
 
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;
529
 
 
530
 
 
531
 
        // Rand links - rechts
532
 
        for(unsigned char i = 0; i < 2; ++i)
533
 
        {
534
 
                if(borders[pos].left_right[i])
535
 
                {
536
 
                        unsigned int offset = borders[pos].left_right_offset[i];
537
 
 
538
 
                        if(!first_offset)
539
 
                                first_offset = offset;
540
 
 
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);
544
 
 
545
 
                        ++count_borders;
546
 
                }
547
 
        }
548
 
 
549
 
        // Rand rechts - links
550
 
        for(unsigned char i = 0; i < 2; ++i)
551
 
        {
552
 
                if(borders[pos].right_left[i])
553
 
                {
554
 
                        unsigned int offset = borders[pos].right_left_offset[i];
555
 
 
556
 
                        if(!first_offset)
557
 
                                first_offset = offset;
558
 
 
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);
562
 
 
563
 
                        ++count_borders;
564
 
                }
565
 
        }
566
 
 
567
 
        // Rand oben - unten
568
 
        for(unsigned char i = 0; i < 2; ++i)
569
 
        {
570
 
                if(borders[pos].top_down[i])
571
 
                {
572
 
                        unsigned int offset = borders[pos].top_down_offset[i];
573
 
 
574
 
                        if(!first_offset)
575
 
                                first_offset = offset;
576
 
 
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));
579
 
 
580
 
                        if(i == 0)
581
 
                                gl_colors[offset].colors[2].r = gl_colors[offset].colors[2].g = gl_colors[offset].colors[2].b = GetBColor(x, y, i);
582
 
                        else
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);
584
 
 
585
 
                        ++count_borders;
586
 
                }
587
 
        }
588
 
 
589
 
        /// Bei Vertexbuffern das die Daten aktualisieren
590
 
        if(update && SETTINGS.video.vbo)
591
 
        {
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]);
595
 
        }
596
 
}
597
 
 
598
 
void TerrainRenderer::UpdateBorderTriangleTerrain(const MapCoord x, const MapCoord y,const GameWorldViewer * gwv, const bool update)
599
 
{
600
 
        unsigned int pos = y * width + x;
601
 
 
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;
607
 
 
608
 
 
609
 
        // Rand links - rechts
610
 
        for(unsigned char i = 0; i < 2; ++i)
611
 
        {
612
 
                if(borders[pos].left_right[i])
613
 
                {
614
 
                        unsigned int offset = borders[pos].left_right_offset[i];
615
 
 
616
 
                        if(!first_offset)
617
 
                                first_offset = offset;
618
 
 
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;
625
 
 
626
 
                        ++count_borders;
627
 
                }
628
 
        }
629
 
 
630
 
        // Rand rechts - links
631
 
        for(unsigned char i = 0; i < 2; ++i)
632
 
        {
633
 
                if(borders[pos].right_left[i])
634
 
                {
635
 
                        unsigned int offset = borders[pos].right_left_offset[i];
636
 
 
637
 
                        if(!first_offset)
638
 
                                first_offset = offset;
639
 
 
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;
646
 
 
647
 
                        ++count_borders;
648
 
                }
649
 
        }
650
 
 
651
 
        // Rand oben - unten
652
 
        for(unsigned char i = 0; i < 2; ++i)
653
 
        {
654
 
                if(borders[pos].top_down[i])
655
 
                {
656
 
                        unsigned int offset = borders[pos].top_down_offset[i];
657
 
 
658
 
                        if(!first_offset)
659
 
                                first_offset = offset;
660
 
 
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;
667
 
 
668
 
                        ++count_borders;
669
 
                }
670
 
        }
671
 
 
672
 
        /// Bei Vertexbuffern das die Daten aktualisieren
673
 
        if(update && SETTINGS.video.vbo)
674
 
        {
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]);
678
 
        }
 
418
void TerrainRenderer::UpdateBorderTrianglePos(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
419
{
 
420
    unsigned int pos = y * width + x;
 
421
 
 
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;
 
427
 
 
428
 
 
429
    // Rand links - rechts
 
430
    for(unsigned char i = 0; i < 2; ++i)
 
431
    {
 
432
        if(borders[pos].left_right[i])
 
433
        {
 
434
            unsigned int offset = borders[pos].left_right_offset[i];
 
435
 
 
436
            if(!first_offset)
 
437
                first_offset = offset;
 
438
 
 
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);
 
445
 
 
446
            ++count_borders;
 
447
        }
 
448
    }
 
449
 
 
450
    // Rand rechts - links
 
451
    for(unsigned char i = 0; i < 2; ++i)
 
452
    {
 
453
        if(borders[pos].right_left[i])
 
454
        {
 
455
            unsigned int offset = borders[pos].right_left_offset[i];
 
456
 
 
457
            if(!first_offset)
 
458
                first_offset = offset;
 
459
 
 
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);
 
464
 
 
465
            if(i == 0)
 
466
            {
 
467
                gl_vertices[offset].pos[2].x = GetBX(x, y, 1);
 
468
                gl_vertices[offset].pos[2].y = GetBY(x, y, 1);
 
469
            }
 
470
            else
 
471
            {
 
472
                gl_vertices[offset].pos[0].x = GetBXAround(x, y, 0, 3);
 
473
                gl_vertices[offset].pos[0].y = GetBYAround(x, y, 0, 3);
 
474
            }
 
475
 
 
476
            ++count_borders;
 
477
        }
 
478
    }
 
479
 
 
480
    // Rand oben - unten
 
481
    for(unsigned char i = 0; i < 2; ++i)
 
482
    {
 
483
        if(borders[pos].top_down[i])
 
484
        {
 
485
            unsigned int offset = borders[pos].top_down_offset[i];
 
486
 
 
487
            if(!first_offset)
 
488
                first_offset = offset;
 
489
 
 
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);
 
494
 
 
495
            if(i == 0)
 
496
            {
 
497
                gl_vertices[offset].pos[2].x = GetBX(x, y, i);
 
498
                gl_vertices[offset].pos[2].y = GetBY(x, y, i);
 
499
            }
 
500
            else
 
501
            {
 
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);
 
505
            }
 
506
 
 
507
            ++count_borders;
 
508
        }
 
509
    }
 
510
 
 
511
    /// Bei Vertexbuffern das die Daten aktualisieren
 
512
    if(update && SETTINGS.video.vbo)
 
513
    {
 
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]);
 
517
    }
 
518
}
 
519
 
 
520
void TerrainRenderer::UpdateBorderTriangleColor(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
521
{
 
522
    unsigned int pos = y * width + x;
 
523
 
 
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;
 
529
 
 
530
 
 
531
    // Rand links - rechts
 
532
    for(unsigned char i = 0; i < 2; ++i)
 
533
    {
 
534
        if(borders[pos].left_right[i])
 
535
        {
 
536
            unsigned int offset = borders[pos].left_right_offset[i];
 
537
 
 
538
            if(!first_offset)
 
539
                first_offset = offset;
 
540
 
 
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);
 
544
 
 
545
            ++count_borders;
 
546
        }
 
547
    }
 
548
 
 
549
    // Rand rechts - links
 
550
    for(unsigned char i = 0; i < 2; ++i)
 
551
    {
 
552
        if(borders[pos].right_left[i])
 
553
        {
 
554
            unsigned int offset = borders[pos].right_left_offset[i];
 
555
 
 
556
            if(!first_offset)
 
557
                first_offset = offset;
 
558
 
 
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);
 
562
 
 
563
            ++count_borders;
 
564
        }
 
565
    }
 
566
 
 
567
    // Rand oben - unten
 
568
    for(unsigned char i = 0; i < 2; ++i)
 
569
    {
 
570
        if(borders[pos].top_down[i])
 
571
        {
 
572
            unsigned int offset = borders[pos].top_down_offset[i];
 
573
 
 
574
            if(!first_offset)
 
575
                first_offset = offset;
 
576
 
 
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));
 
579
 
 
580
            if(i == 0)
 
581
                gl_colors[offset].colors[2].r = gl_colors[offset].colors[2].g = gl_colors[offset].colors[2].b = GetBColor(x, y, i);
 
582
            else
 
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);
 
584
 
 
585
            ++count_borders;
 
586
        }
 
587
    }
 
588
 
 
589
    /// Bei Vertexbuffern das die Daten aktualisieren
 
590
    if(update && SETTINGS.video.vbo)
 
591
    {
 
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]);
 
595
    }
 
596
}
 
597
 
 
598
void TerrainRenderer::UpdateBorderTriangleTerrain(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv, const bool update)
 
599
{
 
600
    unsigned int pos = y * width + x;
 
601
 
 
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;
 
607
 
 
608
 
 
609
    // Rand links - rechts
 
610
    for(unsigned char i = 0; i < 2; ++i)
 
611
    {
 
612
        if(borders[pos].left_right[i])
 
613
        {
 
614
            unsigned int offset = borders[pos].left_right_offset[i];
 
615
 
 
616
            if(!first_offset)
 
617
                first_offset = offset;
 
618
 
 
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;
 
625
 
 
626
            ++count_borders;
 
627
        }
 
628
    }
 
629
 
 
630
    // Rand rechts - links
 
631
    for(unsigned char i = 0; i < 2; ++i)
 
632
    {
 
633
        if(borders[pos].right_left[i])
 
634
        {
 
635
            unsigned int offset = borders[pos].right_left_offset[i];
 
636
 
 
637
            if(!first_offset)
 
638
                first_offset = offset;
 
639
 
 
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;
 
646
 
 
647
            ++count_borders;
 
648
        }
 
649
    }
 
650
 
 
651
    // Rand oben - unten
 
652
    for(unsigned char i = 0; i < 2; ++i)
 
653
    {
 
654
        if(borders[pos].top_down[i])
 
655
        {
 
656
            unsigned int offset = borders[pos].top_down_offset[i];
 
657
 
 
658
            if(!first_offset)
 
659
                first_offset = offset;
 
660
 
 
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;
 
667
 
 
668
            ++count_borders;
 
669
        }
 
670
    }
 
671
 
 
672
    /// Bei Vertexbuffern das die Daten aktualisieren
 
673
    if(update && SETTINGS.video.vbo)
 
674
    {
 
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]);
 
678
    }
679
679
}
680
680
 
681
681
///////////////////////////////////////////////////////////////////////////////
685
685
 *  @author OLiver
686
686
 *  @author FloSoft
687
687
 */
688
 
void TerrainRenderer::Draw(GameWorldView * gwv, unsigned int *water)
 
688
void TerrainRenderer::Draw(GameWorldView* gwv, unsigned int* water)
689
689
{
690
 
        assert(gl_vertices);
691
 
        assert(borders);
692
 
 
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))
694
 
        {
695
 
                glCallList(gwv->terrain_list);
696
 
                *water = gwv->terrain_last_water;
697
 
                return;
698
 
        }
699
 
 
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);
703
 
 
704
 
        if (gwv->terrain_list == 0)
705
 
                gwv->terrain_list = glGenLists(1);
706
 
 
707
 
        glNewList(gwv->terrain_list, GL_COMPILE_AND_EXECUTE);*/
708
 
 
709
 
        PrepareWays(gwv);
710
 
 
711
 
        // nach Texture in Listen sortieren
712
 
        std::list<MapTile> sorted_textures[16];
713
 
        std::list<BorderTile> sorted_borders[5];
714
 
 
715
 
        int lastxo = 0, lastyo = 0;
716
 
        int xo, yo;
717
 
        unsigned short tx,ty;
718
 
        unsigned int offset = width * height * 2;
719
 
 
720
 
        // Beim zeichnen immer nur beginnen, wo man auch was sieht
721
 
        for(int y = gwv->GetFirstY(); y < gwv->GetLastY(); ++y)
722
 
        {
723
 
                unsigned char last = 255;
724
 
                unsigned char last_border = 255;
725
 
 
726
 
                for(int x = gwv->GetFirstX(); x < gwv->GetLastX(); ++x)
727
 
                {
728
 
                        ConvertCoords(x, y, tx, ty, &xo, &yo);
729
 
 
730
 
                        unsigned char t = gwv->GetGameWorldViewer()->GetNode(tx,ty).t1;
731
 
                        if(xo != lastxo || yo != lastyo)
732
 
                                last = 255;
733
 
 
734
 
                        if(t == last)
735
 
                                ++sorted_textures[t].back().count;
736
 
                        else
737
 
                        {
738
 
                                MapTile tmp = {tx * 2, ty, 1, xo, yo};
739
 
                                sorted_textures[t].push_back(tmp);
740
 
                        }
741
 
 
742
 
                        last = t;
743
 
 
744
 
                        t = gwv->GetGameWorldViewer()->GetNode(tx,ty).t2;
745
 
 
746
 
                        if(t == last)
747
 
                                ++sorted_textures[t].back().count;
748
 
                        else
749
 
                        {
750
 
                                MapTile tmp = {tx * 2 + 1, ty, 1, xo, yo};
751
 
                                sorted_textures[t].push_back(tmp);
752
 
                        }
753
 
 
754
 
                        last = t;
755
 
 
756
 
                        unsigned char tiles[6] =
757
 
                        {
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],
764
 
                        };
765
 
 
766
 
                        unsigned int offsets[6] =
767
 
                        {
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],
774
 
                        };
775
 
 
776
 
                        for(unsigned char i = 0; i < 6; ++i)
777
 
                        {
778
 
                                if(tiles[i])
779
 
                                {
780
 
                                        if(tiles[i] == last_border)
781
 
                                                ++sorted_borders[last_border-1].back().count;
782
 
                                        else
783
 
                                        {
784
 
                                                last_border = tiles[i];
785
 
                                                BorderTile tmp = { (int)offsets[ i ], 1, xo, yo};
786
 
                                                sorted_borders[last_border-1].push_back(tmp);
787
 
                                        }
788
 
                                        ++offset;
789
 
                                }
790
 
                        }
791
 
 
792
 
                        PrepareWaysPoint(gwv, tx, ty, xo, yo);
793
 
 
794
 
                        lastxo = xo;
795
 
                        lastyo = yo;
796
 
                }
797
 
        }
798
 
 
799
 
        if (water)
800
 
        {
801
 
                unsigned water_count = 0;
802
 
 
803
 
                for(std::list<MapTile>::iterator it = sorted_textures[TT_WATER].begin(); it != sorted_textures[TT_WATER].end(); ++it)
804
 
                {
805
 
                        water_count += it->count;
806
 
                }
807
 
 
808
 
                if( (gwv->GetLastX() - gwv->GetFirstX()) && (gwv->GetLastY() - gwv->GetFirstY()) )
809
 
                        *water = 50 * water_count / ( (gwv->GetLastX() - gwv->GetFirstX()) * (gwv->GetLastY() - gwv->GetFirstY()) );
810
 
                else
811
 
                        *water = 0;
812
 
        }
813
 
 
814
 
        lastxo = 0;
815
 
        lastyo = 0;
816
 
 
817
 
        if(SETTINGS.video.vbo)
818
 
        {
819
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
820
 
                glVertexPointer(2, GL_FLOAT, 0, NULL);
821
 
 
822
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_texcoords);
823
 
                glTexCoordPointer(2, GL_FLOAT, 0, NULL);
824
 
 
825
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_colors);
826
 
                glColorPointer(3, GL_FLOAT, 0, NULL);
827
 
        } else
828
 
        {
829
 
                glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
830
 
                glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
831
 
                glColorPointer(3, GL_FLOAT, 0, gl_colors);
832
 
        }
833
 
 
834
 
        // Arrays aktivieren
835
 
        glEnableClientState(GL_VERTEX_ARRAY);
836
 
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
837
 
        glEnableClientState(GL_COLOR_ARRAY);
838
 
 
839
 
        // Modulate2x
840
 
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
841
 
        glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
842
 
 
843
 
        // Verschieben gem�� x und y offset
844
 
        glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
845
 
 
846
 
        // Alphablending aus
847
 
        glDisable(GL_BLEND);
848
 
 
849
 
        for(unsigned char i = 0; i < 16; ++i)
850
 
        {
851
 
                if(sorted_textures[i].size())
852
 
                {
853
 
                        switch(i)
854
 
                        {
855
 
                        case TT_WATER:
856
 
                                VideoDriverWrapper::inst().BindTexture(GetImage(water, GAMECLIENT.GetGlobalAnimation(8, 5, 2, 0))->GetTexture());
857
 
                                break;
858
 
                        case TT_LAVA:
859
 
                                VideoDriverWrapper::inst().BindTexture(GetImage(lava, GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0))->GetTexture());
860
 
                                break;
861
 
                        default:
862
 
                                VideoDriverWrapper::inst().BindTexture(GetImage(textures, i)->GetTexture());
863
 
                        }
864
 
 
865
 
                        for(std::list<MapTile>::iterator it = sorted_textures[i].begin(); it != sorted_textures[i].end(); ++it)
866
 
                        {
867
 
                                if(it->xo != lastxo || it->yo != lastyo)
868
 
                                {
869
 
                                        glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
870
 
                                        lastxo = it->xo;
871
 
                                        lastyo = it->yo;
872
 
                                }
873
 
 
874
 
                                glDrawArrays(GL_TRIANGLES, it->y * width * 3 * 2 + it->x * 3, it->count * 3);
875
 
                        }
876
 
                }
877
 
        }
878
 
 
879
 
        glEnable(GL_BLEND);
880
 
 
881
 
        glLoadIdentity();
882
 
        glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
883
 
 
884
 
        lastxo = 0;
885
 
        lastyo = 0;
886
 
        for(unsigned short i = 0;i<5;++i)
887
 
        {
888
 
                if(sorted_borders[i].size())
889
 
                {
890
 
                        VideoDriverWrapper::inst().BindTexture(GetImage(borders, i)->GetTexture());
891
 
 
892
 
                        for(std::list<BorderTile>::iterator it = sorted_borders[i].begin(); it != sorted_borders[i].end(); ++it)
893
 
                        {
894
 
                                if(it->xo != lastxo || it->yo != lastyo)
895
 
                                {
896
 
                                        glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
897
 
                                        lastxo = it->xo;
898
 
                                        lastyo = it->yo;
899
 
                                }
900
 
                                glDrawArrays(GL_TRIANGLES, it->offset * 3, it->count * 3);
901
 
                        }
902
 
                }
903
 
        }
904
 
 
905
 
        glLoadIdentity();
906
 
 
907
 
        DrawWays(gwv);
908
 
 
909
 
        // Wieder zur�ck ins normale modulate
910
 
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
911
 
 
912
 
/*      glEndList();
913
 
 
914
 
        gwv->terrain_last_water = *water;*/
 
690
    assert(gl_vertices);
 
691
    assert(borders);
 
692
 
 
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))
 
694
        {
 
695
            glCallList(gwv->terrain_list);
 
696
            *water = gwv->terrain_last_water;
 
697
            return;
 
698
        }
 
699
 
 
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);
 
703
 
 
704
        if (gwv->terrain_list == 0)
 
705
            gwv->terrain_list = glGenLists(1);
 
706
 
 
707
        glNewList(gwv->terrain_list, GL_COMPILE_AND_EXECUTE);*/
 
708
 
 
709
    PrepareWays(gwv);
 
710
 
 
711
    // nach Texture in Listen sortieren
 
712
    std::list<MapTile> sorted_textures[16];
 
713
    std::list<BorderTile> sorted_borders[5];
 
714
 
 
715
    int lastxo = 0, lastyo = 0;
 
716
    int xo, yo;
 
717
    unsigned short tx, ty;
 
718
    unsigned int offset = width * height * 2;
 
719
 
 
720
    // Beim zeichnen immer nur beginnen, wo man auch was sieht
 
721
    for(int y = gwv->GetFirstY(); y < gwv->GetLastY(); ++y)
 
722
    {
 
723
        unsigned char last = 255;
 
724
        unsigned char last_border = 255;
 
725
 
 
726
        for(int x = gwv->GetFirstX(); x < gwv->GetLastX(); ++x)
 
727
        {
 
728
            ConvertCoords(x, y, tx, ty, &xo, &yo);
 
729
 
 
730
            unsigned char t = gwv->GetGameWorldViewer()->GetNode(tx, ty).t1;
 
731
            if(xo != lastxo || yo != lastyo)
 
732
                last = 255;
 
733
 
 
734
            if(t == last)
 
735
                ++sorted_textures[t].back().count;
 
736
            else
 
737
            {
 
738
                MapTile tmp = {tx * 2, ty, 1, xo, yo};
 
739
                sorted_textures[t].push_back(tmp);
 
740
            }
 
741
 
 
742
            last = t;
 
743
 
 
744
            t = gwv->GetGameWorldViewer()->GetNode(tx, ty).t2;
 
745
 
 
746
            if(t == last)
 
747
                ++sorted_textures[t].back().count;
 
748
            else
 
749
            {
 
750
                MapTile tmp = {tx * 2 + 1, ty, 1, xo, yo};
 
751
                sorted_textures[t].push_back(tmp);
 
752
            }
 
753
 
 
754
            last = t;
 
755
 
 
756
            unsigned char tiles[6] =
 
757
            {
 
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],
 
764
            };
 
765
 
 
766
            unsigned int offsets[6] =
 
767
            {
 
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],
 
774
            };
 
775
 
 
776
            for(unsigned char i = 0; i < 6; ++i)
 
777
            {
 
778
                if(tiles[i])
 
779
                {
 
780
                    if(tiles[i] == last_border)
 
781
                        ++sorted_borders[last_border - 1].back().count;
 
782
                    else
 
783
                    {
 
784
                        last_border = tiles[i];
 
785
                        BorderTile tmp = { (int)offsets[ i ], 1, xo, yo};
 
786
                        sorted_borders[last_border - 1].push_back(tmp);
 
787
                    }
 
788
                    ++offset;
 
789
                }
 
790
            }
 
791
 
 
792
            PrepareWaysPoint(gwv, tx, ty, xo, yo);
 
793
 
 
794
            lastxo = xo;
 
795
            lastyo = yo;
 
796
        }
 
797
    }
 
798
 
 
799
    if (water)
 
800
    {
 
801
        unsigned water_count = 0;
 
802
 
 
803
        for(std::list<MapTile>::iterator it = sorted_textures[TT_WATER].begin(); it != sorted_textures[TT_WATER].end(); ++it)
 
804
        {
 
805
            water_count += it->count;
 
806
        }
 
807
 
 
808
        if( (gwv->GetLastX() - gwv->GetFirstX()) && (gwv->GetLastY() - gwv->GetFirstY()) )
 
809
            *water = 50 * water_count / ( (gwv->GetLastX() - gwv->GetFirstX()) * (gwv->GetLastY() - gwv->GetFirstY()) );
 
810
        else
 
811
            *water = 0;
 
812
    }
 
813
 
 
814
    lastxo = 0;
 
815
    lastyo = 0;
 
816
 
 
817
    if(SETTINGS.video.vbo)
 
818
    {
 
819
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices);
 
820
        glVertexPointer(2, GL_FLOAT, 0, NULL);
 
821
 
 
822
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords);
 
823
        glTexCoordPointer(2, GL_FLOAT, 0, NULL);
 
824
 
 
825
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors);
 
826
        glColorPointer(3, GL_FLOAT, 0, NULL);
 
827
    }
 
828
    else
 
829
    {
 
830
        glVertexPointer(2, GL_FLOAT, 0, gl_vertices);
 
831
        glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords);
 
832
        glColorPointer(3, GL_FLOAT, 0, gl_colors);
 
833
    }
 
834
 
 
835
    // Arrays aktivieren
 
836
    glEnableClientState(GL_VERTEX_ARRAY);
 
837
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
838
    glEnableClientState(GL_COLOR_ARRAY);
 
839
 
 
840
    // Modulate2x
 
841
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
 
842
    glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
 
843
 
 
844
    // Verschieben gem�� x und y offset
 
845
    glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
 
846
 
 
847
    // Alphablending aus
 
848
    glDisable(GL_BLEND);
 
849
 
 
850
    for(unsigned char i = 0; i < 16; ++i)
 
851
    {
 
852
        if(sorted_textures[i].size())
 
853
        {
 
854
            switch(i)
 
855
            {
 
856
                case TT_WATER:
 
857
                    VideoDriverWrapper::inst().BindTexture(GetImage(water, GAMECLIENT.GetGlobalAnimation(8, 5, 2, 0))->GetTexture());
 
858
                    break;
 
859
                case TT_LAVA:
 
860
                    VideoDriverWrapper::inst().BindTexture(GetImage(lava, GAMECLIENT.GetGlobalAnimation(4, 5, 4, 0))->GetTexture());
 
861
                    break;
 
862
                default:
 
863
                    VideoDriverWrapper::inst().BindTexture(GetImage(textures, i)->GetTexture());
 
864
            }
 
865
 
 
866
            for(std::list<MapTile>::iterator it = sorted_textures[i].begin(); it != sorted_textures[i].end(); ++it)
 
867
            {
 
868
                if(it->xo != lastxo || it->yo != lastyo)
 
869
                {
 
870
                    glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
 
871
                    lastxo = it->xo;
 
872
                    lastyo = it->yo;
 
873
                }
 
874
 
 
875
                glDrawArrays(GL_TRIANGLES, it->y * width * 3 * 2 + it->x * 3, it->count * 3);
 
876
            }
 
877
        }
 
878
    }
 
879
 
 
880
    glEnable(GL_BLEND);
 
881
 
 
882
    glLoadIdentity();
 
883
    glTranslatef( float(-gwv->GetXOffset()), float(-gwv->GetYOffset()), 0.0f);
 
884
 
 
885
    lastxo = 0;
 
886
    lastyo = 0;
 
887
    for(unsigned short i = 0; i < 5; ++i)
 
888
    {
 
889
        if(sorted_borders[i].size())
 
890
        {
 
891
            VideoDriverWrapper::inst().BindTexture(GetImage(borders, i)->GetTexture());
 
892
 
 
893
            for(std::list<BorderTile>::iterator it = sorted_borders[i].begin(); it != sorted_borders[i].end(); ++it)
 
894
            {
 
895
                if(it->xo != lastxo || it->yo != lastyo)
 
896
                {
 
897
                    glTranslatef( float(it->xo - lastxo), float(it->yo - lastyo), 0.0f);
 
898
                    lastxo = it->xo;
 
899
                    lastyo = it->yo;
 
900
                }
 
901
                glDrawArrays(GL_TRIANGLES, it->offset * 3, it->count * 3);
 
902
            }
 
903
        }
 
904
    }
 
905
 
 
906
    glLoadIdentity();
 
907
 
 
908
    DrawWays(gwv);
 
909
 
 
910
    // Wieder zur�ck ins normale modulate
 
911
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
912
 
 
913
    /*  glEndList();
 
914
 
 
915
        gwv->terrain_last_water = *water;*/
915
916
}
916
917
 
917
918
 
926
927
 *
927
928
 *  @author OLiver
928
929
 */
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
930
931
{
931
 
        bool mx = false, my = false;
932
 
 
933
 
        while(x < 0)
934
 
        {
935
 
                x += width;
936
 
                mx = true;
937
 
        }
938
 
 
939
 
        while(y < 0)
940
 
        {
941
 
                y += height;
942
 
                my = true;
943
 
        }
944
 
 
945
 
        if(xo)
946
 
                *xo = (mx ? (x / width) * TR_W - width * TR_W : (x / width) * TR_W * width );
947
 
        if(yo)
948
 
                *yo = (my ? (y / height) * TR_H - height * TR_H : (y / height) * TR_H * height);
949
 
 
950
 
        x %= width;
951
 
        y %= height;
952
 
 
953
 
        x_out = static_cast<unsigned short>(x);
954
 
        y_out = static_cast<unsigned short>(y);
 
932
    bool mx = false, my = false;
 
933
 
 
934
    while(x < 0)
 
935
    {
 
936
        x += width;
 
937
        mx = true;
 
938
    }
 
939
 
 
940
    while(y < 0)
 
941
    {
 
942
        y += height;
 
943
        my = true;
 
944
    }
 
945
 
 
946
    if(xo)
 
947
        *xo = (mx ? (x / width) * TR_W - width * TR_W : (x / width) * TR_W * width );
 
948
    if(yo)
 
949
        *yo = (my ? (y / height) * TR_H - height * TR_H : (y / height) * TR_H * height);
 
950
 
 
951
    x %= width;
 
952
    y %= height;
 
953
 
 
954
    x_out = static_cast<unsigned short>(x);
 
955
    y_out = static_cast<unsigned short>(y);
955
956
}
956
957
 
957
958
struct GL_T2F_C3F_V3F_Struct
958
959
{
959
 
        GLfloat tx, ty;
960
 
        GLfloat r, g, b;
961
 
        GLfloat x, y, z;
 
960
    GLfloat tx, ty;
 
961
    GLfloat r, g, b;
 
962
    GLfloat x, y, z;
962
963
};
963
964
 
964
 
void TerrainRenderer::PrepareWays(GameWorldView *gwv)
965
 
{
966
 
        for (unsigned char type = 0; type < 4; type++)
967
 
        {
968
 
                gwv->sorted_roads[type].clear();
969
 
        }
970
 
}
971
 
 
972
 
void TerrainRenderer::PrepareWaysPoint(GameWorldView *gwv, unsigned short tx, unsigned short ty, int xo, int yo)
973
 
{
974
 
        float xpos = GetTerrainX(tx,ty)-gwv->GetXOffset()+xo;
975
 
        float ypos = GetTerrainY(tx,ty)-gwv->GetYOffset()+yo;
976
 
 
977
 
        // Wegtypen f�r die drei Richtungen
978
 
        unsigned char type;
979
 
 
980
 
        Visibility visibility = gwv->GetGameWorldViewer()->GetVisibility(tx,ty);
981
 
 
982
 
        for(unsigned dir = 0; dir < 3; ++dir)
983
 
        {
984
 
                if ((type = gwv->GetGameWorldViewer()->GetVisibleRoad(tx,ty, dir, visibility)))
985
 
                {
986
 
                        MapCoord xa = gwv->GetGameWorldViewer()->GetXA(tx, ty, 3 + dir);
987
 
                        MapCoord ya = gwv->GetGameWorldViewer()->GetYA(tx, ty, 3 + dir);
988
 
 
989
 
                        float xpos2 = GetTerrainX(xa, ya) - gwv->GetXOffset() + xo;
990
 
                        float ypos2 = GetTerrainY(xa, ya) - gwv->GetYOffset() + yo;
991
 
 
992
 
                        // Gehen wir �ber einen Kartenrand (horizontale Richung?)
993
 
                        if(abs(xpos-xpos2) >= gwv->GetGameWorldViewer()->GetWidth() * TR_W / 2)
994
 
                        {
995
 
                                if(abs(xpos2-int(gwv->GetGameWorldViewer()->GetWidth())*TR_W-xpos) < abs(xpos-xpos2))
996
 
                                        xpos2 -= gwv->GetGameWorldViewer()->GetWidth()*TR_W;
997
 
                                else
998
 
                                        xpos2 += gwv->GetGameWorldViewer()->GetWidth()*TR_W;
999
 
                        }
1000
 
                        // Und dasselbe f�r vertikale Richtung
1001
 
                        if(abs(ypos-ypos2) >= gwv->GetGameWorldViewer()->GetHeight() * TR_H / 2)
1002
 
                        {
1003
 
                                if(abs(ypos2-int(gwv->GetGameWorldViewer()->GetHeight())*TR_H-ypos) < abs(ypos-ypos2))
1004
 
                                        ypos2 -= gwv->GetGameWorldViewer()->GetHeight()*TR_H;
1005
 
                                else
1006
 
                                        ypos2 += gwv->GetGameWorldViewer()->GetHeight()*TR_H;
1007
 
                        }
1008
 
 
1009
 
                        --type;
1010
 
 
1011
 
                        // Wegtypen "konvertieren"
1012
 
                        switch(type)
1013
 
                        {
1014
 
                        case RoadSegment::RT_DONKEY:
1015
 
                        case RoadSegment::RT_NORMAL:
1016
 
                                {
1017
 
                                        unsigned t1 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 2);
1018
 
                                        unsigned t2 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 3);
1019
 
 
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))
1024
 
                                                type = 3;
1025
 
 
1026
 
                                } break;
1027
 
                        case RoadSegment::RT_BOAT:
1028
 
                                {
1029
 
                                        type = 2;
1030
 
                                } break;
1031
 
                        }
1032
 
 
1033
 
                        gwv->sorted_roads[type].push_back(
1034
 
                                PreparedRoad(type,
1035
 
                                        xpos, ypos, xpos2, ypos2,
1036
 
                                        GetColor(tx, ty), GetColor(xa, ya),
1037
 
                                        dir
1038
 
                                )
1039
 
                        );
1040
 
                }
1041
 
        }
1042
 
}
1043
 
 
1044
 
void TerrainRenderer::DrawWays(GameWorldView *gwv)
1045
 
{
1046
 
        const float begin_end_coords[24] =
1047
 
        {
1048
 
                -3.0f,-3.0f,
1049
 
                -3.0f, 3.0f,
1050
 
                -3.0f, 3.0f,
1051
 
                -3.0f,-3.0f,
1052
 
 
1053
 
                 3.0f,-3.0f,
1054
 
                -3.0f, 3.0f,
1055
 
                -3.0f, 3.0f,
1056
 
                 3.0f,-3.0f,
1057
 
 
1058
 
                 3.0f, 3.0f,
1059
 
                -3.0f,-3.0f,
1060
 
                -3.0f,-3.0f,
1061
 
                 3.0f, 3.0f,
1062
 
        };
1063
 
 
1064
 
        if (SETTINGS.video.vbo)
1065
 
        {
1066
 
                // unbind VBO
1067
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
1068
 
        }
1069
 
 
1070
 
        for (unsigned char type = 0; type < 4; type++)
1071
 
        {
1072
 
                unsigned int i = 0;
1073
 
                GL_T2F_C3F_V3F_Struct *tmp = new GL_T2F_C3F_V3F_Struct[gwv->sorted_roads[type].size() * 4];
1074
 
 
1075
 
                for (std::list<PreparedRoad>::iterator it = gwv->sorted_roads[type].begin(); it != gwv->sorted_roads[type].end(); ++it)
1076
 
                {
1077
 
                        tmp[i].tx = 0.0f;
1078
 
                        tmp[i].ty = 0.0f;
1079
 
 
1080
 
                        tmp[i].r = (*it).color1;
1081
 
                        tmp[i].g = (*it).color1;
1082
 
                        tmp[i].b = (*it).color1;
1083
 
 
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];
1086
 
                        tmp[i].z = 0.0f;
1087
 
 
1088
 
                        i++;
1089
 
 
1090
 
                        tmp[i].tx = 0.0f;
1091
 
                        tmp[i].ty = 1.0f;
1092
 
 
1093
 
                        tmp[i].r = (*it).color1;
1094
 
                        tmp[i].g = (*it).color1;
1095
 
                        tmp[i].b = (*it).color1;
1096
 
 
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];
1099
 
                        tmp[i].z = 0.0f;
1100
 
 
1101
 
                        i++;
1102
 
 
1103
 
                        tmp[i].tx = 0.78f;
1104
 
                        tmp[i].ty = 1.0f;
1105
 
 
1106
 
                        tmp[i].r = (*it).color2;
1107
 
                        tmp[i].g = (*it).color2;
1108
 
                        tmp[i].b = (*it).color2;
1109
 
 
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];
1112
 
                        tmp[i].z = 0.0f;
1113
 
 
1114
 
                        i++;
1115
 
 
1116
 
                        tmp[i].tx = 0.78f;
1117
 
                        tmp[i].ty = 0.0f;
1118
 
 
1119
 
                        tmp[i].r = (*it).color2;
1120
 
                        tmp[i].g = (*it).color2;
1121
 
                        tmp[i].b = (*it).color2;
1122
 
 
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];
1125
 
                        tmp[i].z = 0.0f;
1126
 
 
1127
 
                        i++;
1128
 
                }
1129
 
 
1130
 
                glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp);
1131
 
                VideoDriverWrapper::inst().BindTexture(GetImage(roads, type)->GetTexture());
1132
 
                glDrawArrays(GL_QUADS, 0, i);
1133
 
 
1134
 
                delete[] tmp;
1135
 
        }
1136
 
}
1137
 
 
1138
 
void TerrainRenderer::AltitudeChanged(const MapCoord x, const MapCoord y, const GameWorldViewer * gwv)
1139
 
{
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);
1143
 
 
1144
 
        for(unsigned i = 0;i<6;++i)
1145
 
                UpdateVertexColor(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1146
 
 
1147
 
 
1148
 
        // und f�r die R�nder
1149
 
        UpdateBorderVertex(x,y,gwv);
1150
 
 
1151
 
        for(unsigned i = 0;i<6;++i)
1152
 
                UpdateBorderVertex(gwv->GetXA(x,y,i),gwv->GetYA(x,y,i),gwv);
1153
 
 
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);
1157
 
 
1158
 
        for(unsigned i = 0;i<6;++i)
1159
 
        {
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);
1162
 
        }
1163
 
 
1164
 
 
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);
1169
 
 
1170
 
 
1171
 
        // und f�r die R�nder
1172
 
        UpdateBorderTrianglePos(x,y,gwv,true);
1173
 
        UpdateBorderTriangleColor(x,y,gwv,true);
1174
 
 
1175
 
        for(unsigned i = 0;i<6;++i)
1176
 
        {
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);
1179
 
        }
1180
 
 
1181
 
        for(unsigned i = 0;i<12;++i)
1182
 
                UpdateBorderTriangleColor(gwv->GetXA2(x,y,i),gwv->GetYA2(x,y,i),gwv,true);
1183
 
}
1184
 
 
1185
 
void TerrainRenderer::VisibilityChanged(const MapCoord x, const MapCoord y, const GameWorldViewer * gwv)
1186
 
{
1187
 
        /// Noch kein Terrain gebaut? abbrechen
1188
 
        if(!vertices)
1189
 
                return;
1190
 
 
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);
1194
 
 
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);
1199
 
 
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);
1204
 
 
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);
1209
 
}
1210
 
 
1211
 
 
1212
 
void TerrainRenderer::UpdateAllColors(const GameWorldViewer * gwv)
1213
 
{
1214
 
        for(MapCoord y = 0;y<height;++y)
1215
 
        {
1216
 
                for(MapCoord x = 0;x<width;++x)
1217
 
                {
1218
 
                        UpdateVertexColor(x,y,gwv);
1219
 
                }
1220
 
        }
1221
 
 
1222
 
        for(MapCoord y = 0;y<height;++y)
1223
 
        {
1224
 
                for(MapCoord x = 0;x<width;++x)
1225
 
                {
1226
 
                        UpdateBorderVertex(x,y,gwv);
1227
 
                }
1228
 
        }
1229
 
 
1230
 
        for(MapCoord y = 0;y<height;++y)
1231
 
        {
1232
 
                for(MapCoord x = 0;x<width;++x)
1233
 
                {
1234
 
                        UpdateTriangleColor(x,y,gwv,false);
1235
 
                }
1236
 
        }
1237
 
 
1238
 
        for(MapCoord y = 0;y<height;++y)
1239
 
        {
1240
 
                for(MapCoord x = 0;x<width;++x)
1241
 
                {
1242
 
                        UpdateBorderTriangleColor(x,y,gwv,false);
1243
 
                }
1244
 
        }
1245
 
 
1246
 
 
1247
 
        if(SETTINGS.video.vbo)
1248
 
        {
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);
1254
 
        }
1255
 
        else
1256
 
                glColorPointer(3, GL_FLOAT, 0, gl_colors);
 
965
void TerrainRenderer::PrepareWays(GameWorldView* gwv)
 
966
{
 
967
    for (unsigned char type = 0; type < 4; type++)
 
968
    {
 
969
        gwv->sorted_roads[type].clear();
 
970
    }
 
971
}
 
972
 
 
973
void TerrainRenderer::PrepareWaysPoint(GameWorldView* gwv, unsigned short tx, unsigned short ty, int xo, int yo)
 
974
{
 
975
    float xpos = GetTerrainX(tx, ty) - gwv->GetXOffset() + xo;
 
976
    float ypos = GetTerrainY(tx, ty) - gwv->GetYOffset() + yo;
 
977
 
 
978
    // Wegtypen f�r die drei Richtungen
 
979
    unsigned char type;
 
980
 
 
981
    Visibility visibility = gwv->GetGameWorldViewer()->GetVisibility(tx, ty);
 
982
 
 
983
    for(unsigned dir = 0; dir < 3; ++dir)
 
984
    {
 
985
        if ((type = gwv->GetGameWorldViewer()->GetVisibleRoad(tx, ty, dir, visibility)))
 
986
        {
 
987
            MapCoord xa = gwv->GetGameWorldViewer()->GetXA(tx, ty, 3 + dir);
 
988
            MapCoord ya = gwv->GetGameWorldViewer()->GetYA(tx, ty, 3 + dir);
 
989
 
 
990
            float xpos2 = GetTerrainX(xa, ya) - gwv->GetXOffset() + xo;
 
991
            float ypos2 = GetTerrainY(xa, ya) - gwv->GetYOffset() + yo;
 
992
 
 
993
            // Gehen wir �ber einen Kartenrand (horizontale Richung?)
 
994
            if(abs(xpos - xpos2) >= gwv->GetGameWorldViewer()->GetWidth() * TR_W / 2)
 
995
            {
 
996
                if(abs(xpos2 - int(gwv->GetGameWorldViewer()->GetWidth())*TR_W - xpos) < abs(xpos - xpos2))
 
997
                    xpos2 -= gwv->GetGameWorldViewer()->GetWidth() * TR_W;
 
998
                else
 
999
                    xpos2 += gwv->GetGameWorldViewer()->GetWidth() * TR_W;
 
1000
            }
 
1001
            // Und dasselbe f�r vertikale Richtung
 
1002
            if(abs(ypos - ypos2) >= gwv->GetGameWorldViewer()->GetHeight() * TR_H / 2)
 
1003
            {
 
1004
                if(abs(ypos2 - int(gwv->GetGameWorldViewer()->GetHeight())*TR_H - ypos) < abs(ypos - ypos2))
 
1005
                    ypos2 -= gwv->GetGameWorldViewer()->GetHeight() * TR_H;
 
1006
                else
 
1007
                    ypos2 += gwv->GetGameWorldViewer()->GetHeight() * TR_H;
 
1008
            }
 
1009
 
 
1010
            --type;
 
1011
 
 
1012
            // Wegtypen "konvertieren"
 
1013
            switch(type)
 
1014
            {
 
1015
                case RoadSegment::RT_DONKEY:
 
1016
                case RoadSegment::RT_NORMAL:
 
1017
                {
 
1018
                    unsigned t1 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 2);
 
1019
                    unsigned t2 = gwv->GetGameWorldViewer()->GetTerrainAround(tx, ty, dir + 3);
 
1020
 
 
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))
 
1025
                        type = 3;
 
1026
 
 
1027
                } break;
 
1028
                case RoadSegment::RT_BOAT:
 
1029
                {
 
1030
                    type = 2;
 
1031
                } break;
 
1032
            }
 
1033
 
 
1034
            gwv->sorted_roads[type].push_back(
 
1035
                PreparedRoad(type,
 
1036
                             xpos, ypos, xpos2, ypos2,
 
1037
                             GetColor(tx, ty), GetColor(xa, ya),
 
1038
                             dir
 
1039
                            )
 
1040
            );
 
1041
        }
 
1042
    }
 
1043
}
 
1044
 
 
1045
void TerrainRenderer::DrawWays(GameWorldView* gwv)
 
1046
{
 
1047
    const float begin_end_coords[24] =
 
1048
    {
 
1049
        -3.0f, -3.0f,
 
1050
        -3.0f, 3.0f,
 
1051
        -3.0f, 3.0f,
 
1052
        -3.0f, -3.0f,
 
1053
 
 
1054
        3.0f, -3.0f,
 
1055
        -3.0f, 3.0f,
 
1056
        -3.0f, 3.0f,
 
1057
        3.0f, -3.0f,
 
1058
 
 
1059
        3.0f, 3.0f,
 
1060
        -3.0f, -3.0f,
 
1061
        -3.0f, -3.0f,
 
1062
        3.0f, 3.0f,
 
1063
    };
 
1064
 
 
1065
    if (SETTINGS.video.vbo)
 
1066
    {
 
1067
        // unbind VBO
 
1068
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 
1069
    }
 
1070
 
 
1071
    for (unsigned char type = 0; type < 4; type++)
 
1072
    {
 
1073
        unsigned int i = 0;
 
1074
        GL_T2F_C3F_V3F_Struct* tmp = new GL_T2F_C3F_V3F_Struct[gwv->sorted_roads[type].size() * 4];
 
1075
 
 
1076
        for (std::list<PreparedRoad>::iterator it = gwv->sorted_roads[type].begin(); it != gwv->sorted_roads[type].end(); ++it)
 
1077
        {
 
1078
            tmp[i].tx = 0.0f;
 
1079
            tmp[i].ty = 0.0f;
 
1080
 
 
1081
            tmp[i].r = (*it).color1;
 
1082
            tmp[i].g = (*it).color1;
 
1083
            tmp[i].b = (*it).color1;
 
1084
 
 
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];
 
1087
            tmp[i].z = 0.0f;
 
1088
 
 
1089
            i++;
 
1090
 
 
1091
            tmp[i].tx = 0.0f;
 
1092
            tmp[i].ty = 1.0f;
 
1093
 
 
1094
            tmp[i].r = (*it).color1;
 
1095
            tmp[i].g = (*it).color1;
 
1096
            tmp[i].b = (*it).color1;
 
1097
 
 
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];
 
1100
            tmp[i].z = 0.0f;
 
1101
 
 
1102
            i++;
 
1103
 
 
1104
            tmp[i].tx = 0.78f;
 
1105
            tmp[i].ty = 1.0f;
 
1106
 
 
1107
            tmp[i].r = (*it).color2;
 
1108
            tmp[i].g = (*it).color2;
 
1109
            tmp[i].b = (*it).color2;
 
1110
 
 
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];
 
1113
            tmp[i].z = 0.0f;
 
1114
 
 
1115
            i++;
 
1116
 
 
1117
            tmp[i].tx = 0.78f;
 
1118
            tmp[i].ty = 0.0f;
 
1119
 
 
1120
            tmp[i].r = (*it).color2;
 
1121
            tmp[i].g = (*it).color2;
 
1122
            tmp[i].b = (*it).color2;
 
1123
 
 
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];
 
1126
            tmp[i].z = 0.0f;
 
1127
 
 
1128
            i++;
 
1129
        }
 
1130
 
 
1131
        glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp);
 
1132
        VideoDriverWrapper::inst().BindTexture(GetImage(roads, type)->GetTexture());
 
1133
        glDrawArrays(GL_QUADS, 0, i);
 
1134
 
 
1135
        delete[] tmp;
 
1136
    }
 
1137
}
 
1138
 
 
1139
void TerrainRenderer::AltitudeChanged(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
 
1140
{
 
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);
 
1144
 
 
1145
    for(unsigned i = 0; i < 6; ++i)
 
1146
        UpdateVertexColor(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
 
1147
 
 
1148
 
 
1149
    // und f�r die R�nder
 
1150
    UpdateBorderVertex(x, y, gwv);
 
1151
 
 
1152
    for(unsigned i = 0; i < 6; ++i)
 
1153
        UpdateBorderVertex(gwv->GetXA(x, y, i), gwv->GetYA(x, y, i), gwv);
 
1154
 
 
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);
 
1158
 
 
1159
    for(unsigned i = 0; i < 6; ++i)
 
1160
    {
 
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);
 
1163
    }
 
1164
 
 
1165
 
 
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);
 
1170
 
 
1171
 
 
1172
    // und f�r die R�nder
 
1173
    UpdateBorderTrianglePos(x, y, gwv, true);
 
1174
    UpdateBorderTriangleColor(x, y, gwv, true);
 
1175
 
 
1176
    for(unsigned i = 0; i < 6; ++i)
 
1177
    {
 
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);
 
1180
    }
 
1181
 
 
1182
    for(unsigned i = 0; i < 12; ++i)
 
1183
        UpdateBorderTriangleColor(gwv->GetXA2(x, y, i), gwv->GetYA2(x, y, i), gwv, true);
 
1184
}
 
1185
 
 
1186
void TerrainRenderer::VisibilityChanged(const MapCoord x, const MapCoord y, const GameWorldViewer* gwv)
 
1187
{
 
1188
    /// Noch kein Terrain gebaut? abbrechen
 
1189
    if(!vertices)
 
1190
        return;
 
1191
 
 
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);
 
1195
 
 
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);
 
1200
 
 
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);
 
1205
 
 
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);
 
1210
}
 
1211
 
 
1212
 
 
1213
void TerrainRenderer::UpdateAllColors(const GameWorldViewer* gwv)
 
1214
{
 
1215
    for(MapCoord y = 0; y < height; ++y)
 
1216
    {
 
1217
        for(MapCoord x = 0; x < width; ++x)
 
1218
        {
 
1219
            UpdateVertexColor(x, y, gwv);
 
1220
        }
 
1221
    }
 
1222
 
 
1223
    for(MapCoord y = 0; y < height; ++y)
 
1224
    {
 
1225
        for(MapCoord x = 0; x < width; ++x)
 
1226
        {
 
1227
            UpdateBorderVertex(x, y, gwv);
 
1228
        }
 
1229
    }
 
1230
 
 
1231
    for(MapCoord y = 0; y < height; ++y)
 
1232
    {
 
1233
        for(MapCoord x = 0; x < width; ++x)
 
1234
        {
 
1235
            UpdateTriangleColor(x, y, gwv, false);
 
1236
        }
 
1237
    }
 
1238
 
 
1239
    for(MapCoord y = 0; y < height; ++y)
 
1240
    {
 
1241
        for(MapCoord x = 0; x < width; ++x)
 
1242
        {
 
1243
            UpdateBorderTriangleColor(x, y, gwv, false);
 
1244
        }
 
1245
    }
 
1246
 
 
1247
 
 
1248
    if(SETTINGS.video.vbo)
 
1249
    {
 
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);
 
1255
    }
 
1256
    else
 
1257
        glColorPointer(3, GL_FLOAT, 0, gl_colors);
1257
1258
}