/** * erzeugt die OpenGL-Vertices. * * @author OLiver * @author FloSoft */ void TerrainRenderer::GenerateOpenGL(const GameWorldViewer * gwv) { width = gwv->GetWidth(); height = gwv->GetHeight(); LandscapeType lt = gwv->GetLandscapeType(); GenerateVertices(gwv); unsigned int offset = width * height * 2; // Ränder zählen borders = new Borders[width * height]; for(unsigned short y = 0; y < height; ++y) { for(unsigned short x = 0; x < width; ++x) { unsigned char t1 = gwv->GetNode(x, y).t1; unsigned char t2 = gwv->GetNode(x, y).t2; unsigned int pos = y * width + x; if( (borders[pos].left_right[0] = BORDER_TABLES[lt][t1][t2][1]) ) { borders[pos].left_right_offset[0] = offset + border_count; ++border_count; } if( (borders[pos].left_right[1] = BORDER_TABLES[lt][t1][t2][0]) ) { borders[pos].left_right_offset[1] = offset + border_count; ++border_count; } t1 = gwv->GetNodeAround(x, y,3).t1; if( (borders[pos].right_left[0] = BORDER_TABLES[lt][t2][t1][1]) ) { borders[pos].right_left_offset[0] = offset + border_count; ++border_count; } if( (borders[pos].right_left[1] = BORDER_TABLES[lt][t2][t1][0]) ) { borders[pos].right_left_offset[1] = offset + border_count; ++border_count; } t1 = gwv->GetNode(x, y).t1; t2 = gwv->GetNodeAround(x,y,5).t2; if( (borders[pos].top_down[0] = BORDER_TABLES[lt][t1][t2][1]) ) { borders[pos].top_down_offset[0] = offset + border_count; ++border_count; } if( (borders[pos].top_down[1] = BORDER_TABLES[lt][t1][t2][0]) ) { borders[pos].top_down_offset[1] = offset + border_count; ++border_count; } } } gl_vertices = new Triangle[offset + border_count]; gl_texcoords = new Triangle[offset + border_count]; gl_colors = new ColorTriangle[offset + border_count]; // Normales Terrain erzeugen for(unsigned short y = 0; y < height; ++y) { for(unsigned short x = 0; x < width; ++x) { UpdateTrianglePos(x,y,gwv,false); UpdateTriangleColor(x,y,gwv,false); UpdateTriangleTerrain(x,y,gwv,false); } } // Ränder erzeugen for(unsigned short y = 0; y < height; ++y) { for(unsigned short x = 0; x < width; ++x) { UpdateBorderTrianglePos(x,y,gwv,false); UpdateBorderTriangleColor(x,y,gwv,false); UpdateBorderTriangleTerrain(x,y,gwv,false); } } //unsigned buffer_size = (offset ) * 2 * 3 * sizeof(float); if(SETTINGS.video.vbo) { // Generiere und Binde den Vertex Buffer glGenBuffersARB(1, (GLuint*)&vbo_vertices); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices); glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_vertices, GL_STATIC_DRAW_ARB); glVertexPointer(2, GL_FLOAT, 0, NULL); // Generiere und Binde den Textur Koordinaten Buffer glGenBuffersARB(1, (GLuint*)&vbo_texcoords); glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_texcoords); glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 2 * sizeof(float), gl_texcoords, GL_STATIC_DRAW_ARB ); glTexCoordPointer(2, GL_FLOAT, 0, NULL); // Generiere und Binde den Color Buffer glGenBuffersARB(1, (GLuint*)&vbo_colors); glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_colors); glBufferDataARB(GL_ARRAY_BUFFER_ARB, (offset + border_count) * 3 * 3 * sizeof(float), gl_colors, GL_STATIC_DRAW_ARB ); glColorPointer(3, GL_FLOAT, 0, NULL); } else { glVertexPointer(2, GL_FLOAT, 0, gl_vertices); glTexCoordPointer(2, GL_FLOAT, 0, gl_texcoords); glColorPointer(3, GL_FLOAT, 0, gl_colors); } }
/** * erzeugt die OpenGL-Vertices. * * @author OLiver * @author FloSoft */ void TerrainRenderer::GenerateOpenGL(const GameWorldViewer& gwv) { width = gwv.GetWidth(); height = gwv.GetHeight(); LandscapeType lt = gwv.GetLandscapeType(); GenerateVertices(gwv); // We have 2 triangles per map point unsigned int triangleCount = width * height * 2; // Ränder zählen borders.resize(width * height); for(MapCoord y = 0; y < height; ++y) { for(MapCoord x = 0; x < width; ++x) { MapPoint pt(x, y); TerrainType t1 = gwv.GetNode(pt).t1; //-V807 TerrainType t2 = gwv.GetNode(pt).t2; unsigned int pos = GetVertexIdx(pt); if( (borders[pos].left_right[0] = TerrainData::GetEdgeType(lt, t2, t1)) ) borders[pos].left_right_offset[0] = triangleCount++; if( (borders[pos].left_right[1] = TerrainData::GetEdgeType(lt, t1, t2)) ) borders[pos].left_right_offset[1] = triangleCount++; t1 = gwv.GetNodeAround(pt, 3).t1; if( (borders[pos].right_left[0] = TerrainData::GetEdgeType(lt, t1, t2)) ) borders[pos].right_left_offset[0] = triangleCount++; if( (borders[pos].right_left[1] = TerrainData::GetEdgeType(lt, t2, t1)) ) borders[pos].right_left_offset[1] = triangleCount++; t1 = gwv.GetNode(pt).t1; t2 = gwv.GetNodeAround(pt, 5).t2; if( (borders[pos].top_down[0] = TerrainData::GetEdgeType(lt, t2, t1)) ) borders[pos].top_down_offset[0] = triangleCount++; if( (borders[pos].top_down[1] = TerrainData::GetEdgeType(lt, t1, t2)) ) borders[pos].top_down_offset[1] = triangleCount++; } } gl_vertices.resize(triangleCount); gl_texcoords.resize(triangleCount); gl_colors.resize(triangleCount); // Normales Terrain erzeugen for(MapCoord y = 0; y < height; ++y) { for(MapCoord x = 0; x < width; ++x) { MapPoint pt(x, y); UpdateTrianglePos(pt, gwv, false); UpdateTriangleColor(pt, gwv, false); UpdateTriangleTerrain(pt, gwv, false); } } // Ränder erzeugen for(MapCoord y = 0; y < height; ++y) { for(MapCoord x = 0; x < width; ++x) { MapPoint pt(x, y); UpdateBorderTrianglePos(pt, gwv, false); UpdateBorderTriangleColor(pt, gwv, false); UpdateBorderTriangleTerrain(pt, gwv, false); } } if(SETTINGS.video.vbo) { // Generiere und Binde den Vertex Buffer glGenBuffersARB(1, (GLuint*)&vbo_vertices); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_vertices); glBufferDataARB(GL_ARRAY_BUFFER_ARB, gl_vertices.size() * sizeof(Triangle), &gl_vertices.front(), GL_STATIC_DRAW_ARB); glVertexPointer(2, GL_FLOAT, 0, NULL); // Generiere und Binde den Textur Koordinaten Buffer glGenBuffersARB(1, (GLuint*)&vbo_texcoords); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_texcoords); glBufferDataARB(GL_ARRAY_BUFFER_ARB, gl_texcoords.size() * sizeof(Triangle), &gl_texcoords.front(), GL_STATIC_DRAW_ARB ); glTexCoordPointer(2, GL_FLOAT, 0, NULL); // Generiere und Binde den Color Buffer glGenBuffersARB(1, (GLuint*)&vbo_colors); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_colors); glBufferDataARB(GL_ARRAY_BUFFER_ARB, gl_colors.size() * sizeof(ColorTriangle), &gl_colors.front(), GL_STATIC_DRAW_ARB ); glColorPointer(3, GL_FLOAT, 0, NULL); vboBuffersUsed = true; } else { glVertexPointer(2, GL_FLOAT, 0, &gl_vertices.front()); glTexCoordPointer(2, GL_FLOAT, 0, &gl_texcoords.front()); glColorPointer(3, GL_FLOAT, 0, &gl_colors.front()); } }