winlivebg_test1
diff src/main.c @ 2:a9025f31ae2d
sortof works, testing with colcycle hack
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Oct 2019 16:07:25 +0200 |
parents | aa6a9521b088 |
children |
line diff
1.1 --- a/src/main.c Thu Oct 17 09:32:42 2019 +0300 1.2 +++ b/src/main.c Mon Oct 28 16:07:25 2019 +0200 1.3 @@ -5,6 +5,13 @@ 1.4 1.5 #define WCNAME "livebg_test" 1.6 1.7 +int colcycle_init(void); 1.8 +void colcycle_cleanup(void); 1.9 +void colcycle_draw(long time_msec); 1.10 + 1.11 +int scr_width, scr_height; 1.12 +long upd_interval; 1.13 + 1.14 void draw(void); 1.15 HWND create_window(int width, int height); 1.16 int init_gl(void); 1.17 @@ -25,7 +32,13 @@ 1.18 } 1.19 if(init_gl() == -1) { 1.20 DestroyWindow(win); 1.21 - return 1; 1.22 + goto done; 1.23 + } 1.24 + if(colcycle_init() == -1) { 1.25 + wglMakeCurrent(0, 0); 1.26 + wglDeleteContext(ctx); 1.27 + DestroyWindow(win); 1.28 + goto done; 1.29 } 1.30 1.31 start_time = timeGetTime(); 1.32 @@ -39,7 +52,6 @@ 1.33 } 1.34 1.35 draw(); 1.36 - Sleep(10); 1.37 } 1.38 done: 1.39 1.40 @@ -51,22 +63,17 @@ 1.41 1.42 void draw(void) 1.43 { 1.44 - float tm = (timeGetTime() - start_time) / 1000.0f; 1.45 - glClearColor(0.1, 0.1, 0.1, 1); 1.46 - glClear(GL_COLOR_BUFFER_BIT); 1.47 + long now, wait_msec; 1.48 + long tmsec = timeGetTime() - start_time; 1.49 1.50 - glMatrixMode(GL_MODELVIEW); 1.51 - glLoadIdentity(); 1.52 - glRotatef(tm * 10.0f, 0, 0, 1); 1.53 + colcycle_draw(tmsec); 1.54 1.55 - glBegin(GL_TRIANGLES); 1.56 - glColor3f(1, 0, 0); 1.57 - glVertex2f(-0.5, -0.5); 1.58 - glColor3f(0, 1, 0); 1.59 - glVertex2f(0.5, -0.5); 1.60 - glColor3f(0, 0, 1); 1.61 - glVertex2f(0, 0.68); 1.62 - glEnd(); 1.63 + now = timeGetTime() - start_time; 1.64 + wait_msec = upd_interval / 1000 - (now - tmsec); 1.65 + if(wait_msec > 0) { 1.66 + fprintf(stderr, "wait_msec: %ld\n", wait_msec); 1.67 + Sleep(wait_msec); 1.68 + } 1.69 1.70 SwapBuffers(dc); 1.71 } 1.72 @@ -131,6 +138,9 @@ 1.73 return 0; 1.74 } 1.75 dc = GetDC(win); 1.76 + 1.77 + scr_width = width; 1.78 + scr_height = height; 1.79 return win; 1.80 } 1.81 1.82 @@ -170,6 +180,9 @@ 1.83 break; 1.84 1.85 case WM_CLOSE: 1.86 + colcycle_cleanup(); 1.87 + wglMakeCurrent(0, 0); 1.88 + wglDeleteContext(ctx); 1.89 DestroyWindow(win); 1.90 break; 1.91