int main(int argc, char *argv[]) { printf("===================================================\n"); while (openMapFile()); // Tries to open a file printf("Starting OpenGL...\n"); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(800, 600); glutCreateWindow("Epic Game"); glewExperimental = GL_TRUE; glewInit(); initialize(); // Event listeners glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouseClick); // Starts main timer glutTimerFunc(10, tick, 0); glutMainLoop(); return 0; }
void LocationDialog::displayMap(HWND hDlg, HWND hButton) // Draw the current map. { double latitude, longitude, width, height; double aspectRatio; double x1, x2, y1, y2; minLongitude = -180.; minLatitude = -90.; maxLongitude = 180.; maxLatitude = 90.; // Get the map file name. char mapName[32]; lstrcpy(mapName, mapTable[mapIndex].filename); HANDLE hMap = openMapFile(mapName); if (hMap == INVALID_HANDLE_VALUE) return; // Get the control dimensions. RECT mapRect; GetWindowRect(GetDlgItem(hDlg, IDC_MAP_PICTURE), &mapRect); mapWidth = (short)(mapRect.right - mapRect.left); mapHeight = (short)(mapRect.bottom - mapRect.top); // Read the map file header and record values. DWORD bytesRead; if (ReadFile(hMap, &latitude, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) { CloseHandle(hMap); return; } if (ReadFile(hMap, &longitude, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) { CloseHandle(hMap); return; } if (ReadFile(hMap, &width, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) { CloseHandle(hMap); return; } aspectRatio = ((double)mapHeight)/((double)mapWidth); height = width * aspectRatio; minLongitude = longitude - width / 2.; minLatitude = latitude - height / 2.; maxLongitude = longitude + width / 2.; maxLatitude = latitude + height / 2.; crossVisible = FALSE; HDC hDC = GetDC(hDlg); COLORREF bkColor = GetPixel(hDC, 2, 2); ReleaseDC(hDlg, hDC); // Read the rest of the file and draw. hDC = GetDC(hButton); if (hDC != NULL) { RECT rect; rect.left = rect.top = 0; rect.right = mapWidth; rect.bottom = mapHeight; HBRUSH bkBrush = CreateSolidBrush(bkColor); HBRUSH oBrush = (HBRUSH)SelectObject(hDC, bkBrush); GetClientRect(hButton, &mapRect); Rectangle(hDC, mapRect.left - 1, mapRect.top, mapRect.right + 2 , mapRect.bottom); while (TRUE) { if (ReadFile(hMap, &x1, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) break; if (ReadFile(hMap, &y1, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) break; if (ReadFile(hMap, &x2, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) break; if (ReadFile(hMap, &y2, sizeof(double), &bytesRead, NULL) == FALSE || bytesRead == 0) break; if (x1 * x2 > 0.0) { // only if they have the same sign short mx, my, lx, ly; mx = (short)((x1 - minLongitude) * mapWidth / width); my = (short)(mapHeight - ((y1 - minLatitude) * mapHeight / height)); #ifdef DEBUG if (mx > mapWidth) break;//mx = mapWidth; if (mx < 0) break;//mx = 0; if (my > mapHeight) break;//my = mapHeight; if (my < 0) break;//my = 0; #endif lx = (short)((x2 - minLongitude) * mapWidth / width); ly = (short)(mapHeight - ((y2 - minLatitude) * mapHeight / height)); #ifdef DEBUG if (lx > mapWidth) break;//lx = mapWidth; if (lx < 0) break;//lx = 0; if (ly > mapHeight) break;//ly = mapHeight; if (ly < 0) break;//ly = 0; #endif MoveToEx(hDC, mx, my, NULL); LineTo(hDC, lx, ly); } } SelectObject(hDC, oBrush); DeleteObject(bkBrush); ReleaseDC(hButton, hDC); } CloseHandle(hMap); // calculate for imageToLatLong. xBias = longitude - (width/2.); yBias = latitude - ((width/2.)*((double)mapHeight/(double)mapWidth)); scale = (double) mapWidth / width; mapLongWidth = width; mapLatHeight = height; }