So i have this code to draw a single shapefile layer i tried different ways to render mutliple layers the first layer draws countries borders and the second layer draws us roads and highways but i can only gett the countries borders to show but i deleted the code that supposed to draw the second layer but again that code did not work
void latLonToXYZ(double lat, double lon, double& x, double& y, double& z) {
const double R = 1.0 * 0.4666; // Multiply the radius by the scale factor
double latRad = lat * M_PI / 180.0;
double lonRad = lon * M_PI / 180.0;
x = R * cos(latRad) * cos(lonRad);
y = R * cos(latRad) * sin(lonRad);
z = R * sin(latRad);
}
void drawShapefilePolygons(const std::vector<SHPObject*>& objects) {
glColor3f(1.0f, 1.0f, 1.0f); // Set the color for the shapefile polygons
// Define translation and rotation values
float translationX = 0.0f; // Adjust this value to move the shapefile along the x-axis
float rotationZ = 0.0f; // Adjust this value to rotate the shapefile around the z-axis
float rotationX = 269.8f; // Adjust this value to tilt the shapefile up or down
// Apply translation and rotation transformations
glPushMatrix();
glTranslatef(translationX, 0, 0);
glRotatef(rotationX, 1, 0, 0); // Apply the rotation around the x-axis
glRotatef(rotationZ, 0, 0, 1);
for (const auto& object : objects) {
if (object->nSHPType == SHPT_POLYGON) {
for (int i = 0; i < object->nParts; i++) {
int startVertex = object->panPartStart[i];
int endVertex = (i == object->nParts - 1) ? object->nVertices : object->panPartStart[i + 1];
glBegin(GL_LINE_LOOP);
for (int j = startVertex; j < endVertex; j++) {
double x, y, z;
latLonToXYZ(object->padfY[j], object->padfX[j], x, y, z); // Convert lat/lon to 3D coordinates
glVertex3d(x, y, z); // Pass the 3D coordinates to OpenGL
}
glEnd();
}
}
}
glPopMatrix();
}
std::vector<SHPObject*> readShapefile(const char* filename) {
std::vector<SHPObject*> objects;
SHPHandle reader = SHPOpen(filename, "rb");
if (reader == nullptr) {
std::cerr << "Failed to open shapefile: " << filename << std::endl;
return objects;
}
int nEntities;
int nShapeType;
SHPGetInfo(reader, &nEntities, &nShapeType, nullptr, nullptr);
for (int i = 0; i < nEntities; i++) {
SHPObject* object = SHPReadObject(reader, i);
if (object == nullptr) {
std::cerr << "Failed to read shapefile object" << std::endl;
continue;
}
objects.push_back(object);
}
SHPClose(reader);
return objects;
}
int main() {
const char* filename = "C:/Users/---/Desktop/BOLTgui/BOLT/shapefiles/WorldBorders.shp";
SHPHandle reader = SHPOpen(filename, "rb");
if (reader == nullptr) {
std::cerr << "Failed to open shapefile: " << filename << std::endl;
return EXIT_FAILURE;
}
// Extract the first polygon from the shapefile
SHPObject* object = SHPReadObject(reader, 0);
if (object == nullptr) {
std::cerr << "Failed to read shapefile object" << std::endl;
SHPClose(reader);
return EXIT_FAILURE;
}
const int WINDOW_WIDTH = 1200;
const int WINDOW_HEIGHT = 700;
const int WIDGET_PANEL_HEIGHT = 70;
const int BUTTON_WIDTH = 100;
const int BUTTON_HEIGHT = 50;