5 static int create_glwin(int xsz, int ysz);
6 static void destroy_glwin(void);
7 static long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
13 static long start_time;
16 int WINAPI WinMain(HINSTANCE pid, HINSTANCE prevpid, char *cmdline, int showcmd)
18 if(memcmp(cmdline, "-c", 2) == 0) {
21 if(memcmp(cmdline, "-s", 2) == 0) {
25 if(create_glwin(1280, 800) == -1) {
29 if(app_init() == -1) {
32 start_time = timeGetTime();
36 while(PeekMessage(&ev, 0, 0, 0, PM_REMOVE)) {
37 if(ev.message == WM_QUIT) {
40 TranslateMessage(&ev);
45 msec = timeGetTime() - start_time;
60 void app_fullscreen(void)
64 void app_windowed(void)
69 static int create_glwin(int xsz, int ysz)
71 int x, y, win_xsz, win_ysz, pix_fmt;
75 PIXELFORMATDESCRIPTOR pfd;
78 pid = GetModuleHandle(0);
80 memset(&wc, 0, sizeof wc);
81 wc.cbSize = sizeof wc;
82 wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
83 wc.hCursor = LoadCursor(0, IDC_ARROW);
84 wc.hIcon = wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
86 wc.lpfnWndProc = (WNDPROC)handle_events;
87 wc.lpszClassName = "census";
88 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
93 win_xsz = xsz = GetSystemMetrics(SM_CXSCREEN);
94 win_ysz = ysz = GetSystemMetrics(SM_CYSCREEN);
98 x = y = CW_USEDEFAULT;
99 style = WS_OVERLAPPEDWINDOW;
101 rect.left = rect.top = 0;
104 AdjustWindowRect(&rect, style, 0);
106 win_xsz = rect.right - rect.left;
107 win_ysz = rect.bottom - rect.top;
110 printf("creating window: %dx%d\n", xsz, ysz);
111 win = CreateWindow("census", "census", style, x, y, win_xsz, win_ysz, 0, 0, pid, 0);
114 memset(&pfd, 0, sizeof pfd);
115 pfd.nSize = sizeof pfd;
117 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;
118 pfd.iPixelType = PFD_TYPE_RGBA;
121 pfd.iLayerType = PFD_MAIN_PLANE;
123 if(!(pix_fmt = ChoosePixelFormat(dc, &pfd)) || !SetPixelFormat(dc, pix_fmt, &pfd)) {
124 fprintf(stderr, "Failed to get suitable pixel format\n");
127 UnregisterClass("census", pid);
131 if(!(ctx = wglCreateContext(dc))) {
132 fprintf(stderr, "Failed to create WGL context\n");
135 UnregisterClass("census", pid);
138 wglMakeCurrent(dc, ctx);
140 ShowWindow(win, SW_SHOW);
144 app_reshape(xsz, ysz);
150 static void destroy_glwin(void)
152 wglMakeCurrent(0, 0);
153 wglDeleteContext(ctx);
156 UnregisterClass("census", GetModuleHandle(0));
159 static long CALLBACK handle_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
161 static int window_mapped;
165 window_mapped = wparam;
170 ValidateRect(win, 0);
180 app_keyboard(wparam, 1);
191 if(wparam == SC_SCREENSAVE) {
196 return DefWindowProc(win, msg, wparam, lparam);
201 int WINAPI RegisterDialogClasses(HINSTANCE pid)