OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <time.h> | 8 #include <time.h> |
9 | 9 |
10 #include "main.h" | 10 #include "main.h" |
11 #include "utils.h" | 11 #include "utils.h" |
| 12 #include "xlib_window.h" |
12 | 13 |
13 | 14 |
14 GLuint GenerateAndBindTexture() { | 15 GLuint GenerateAndBindTexture() { |
15 GLuint name = ~0; | 16 GLuint name = ~0; |
16 glGenTextures(1, &name); | 17 glGenTextures(1, &name); |
17 glBindTexture(GL_TEXTURE_2D, name); | 18 glBindTexture(GL_TEXTURE_2D, name); |
18 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | 21 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
21 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | 22 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 int refresh = atoi(argv[i]); | 60 int refresh = atoi(argv[i]); |
60 if (refresh > 1) { | 61 if (refresh > 1) { |
61 delete g_sleep_duration; | 62 delete g_sleep_duration; |
62 g_sleep_duration = new struct timespec; | 63 g_sleep_duration = new struct timespec; |
63 g_sleep_duration->tv_sec = 0; | 64 g_sleep_duration->tv_sec = 0; |
64 g_sleep_duration->tv_nsec = static_cast<long>(1.e9 / refresh); | 65 g_sleep_duration->tv_nsec = static_cast<long>(1.e9 / refresh); |
65 } else { | 66 } else { |
66 printf("-r requires integer greater than one.\n"); | 67 printf("-r requires integer greater than one.\n"); |
67 } | 68 } |
68 } else if (strcmp("-o", argv[i]) == 0) { | 69 } else if (strcmp("-o", argv[i]) == 0) { |
69 g_override_redirect = false; | 70 g_override_redirect = true; |
70 } else if (strcmp("-r", argv[i]) == 0) { | 71 } else if (strcmp("-r", argv[i]) == 0) { |
71 refresh_arg = true; | 72 refresh_arg = true; |
72 } | 73 } |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 | 77 |
77 int main(int argc, char* argv[]) { | 78 int main(int argc, char* argv[]) { |
| 79 g_override_redirect = false; |
| 80 g_height = -1; |
78 ParseArgs(argc, argv); | 81 ParseArgs(argc, argv); |
79 g_height = -1; | |
80 if (!Init()) { | 82 if (!Init()) { |
81 printf("# Failed to initialize.\n"); | 83 printf("# Failed to initialize.\n"); |
82 return 1; | 84 return 1; |
83 } | 85 } |
84 | 86 |
85 InitContext(); | 87 InitContext(); |
86 glViewport(-g_width, -g_height, g_width*2, g_height*2); | 88 glViewport(-g_width, -g_height, g_width*2, g_height*2); |
87 | 89 |
88 char *bitmap = CreateBitmap(g_height, g_width*2); | 90 char *bitmap = CreateBitmap(g_height, g_width*2); |
89 GLuint texture = GenerateAndBindTexture(); | 91 GLuint texture = GenerateAndBindTexture(); |
(...skipping 12 matching lines...) Expand all Loading... |
102 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, vertices); | 104 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, vertices); |
103 glEnableVertexAttribArray(attribute_index); | 105 glEnableVertexAttribArray(attribute_index); |
104 | 106 |
105 int texture_sampler = glGetUniformLocation(program, "tex"); | 107 int texture_sampler = glGetUniformLocation(program, "tex"); |
106 glUniform1f(texture_sampler, 0); | 108 glUniform1f(texture_sampler, 0); |
107 | 109 |
108 int shift_uniform = glGetUniformLocation(program, "shift"); | 110 int shift_uniform = glGetUniformLocation(program, "shift"); |
109 int i = 0; | 111 int i = 0; |
110 SwapInterval(g_sleep_duration ? 0 : 1); | 112 SwapInterval(g_sleep_duration ? 0 : 1); |
111 for (;;) { | 113 for (;;) { |
| 114 XEvent event; |
| 115 Bool got_event = XCheckWindowEvent(xlib_display, xlib_window, |
| 116 KeyPressMask, &event); |
| 117 if (got_event) |
| 118 break; |
112 glClear(GL_COLOR_BUFFER_BIT); | 119 glClear(GL_COLOR_BUFFER_BIT); |
113 glUniform1f(shift_uniform, 1.f / g_width * | 120 glUniform1f(shift_uniform, 1.f / g_width * |
114 (i < g_width ? i : 2 * g_width - i)); | 121 (i < g_width ? i : 2 * g_width - i)); |
115 i = (i + 4) % (2 * g_width); | 122 i = (i + 4) % (2 * g_width); |
116 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 123 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
117 glFlush(); | 124 glFlush(); |
118 | 125 |
119 if (g_sleep_duration) | 126 if (g_sleep_duration) |
120 nanosleep(g_sleep_duration, NULL); | 127 nanosleep(g_sleep_duration, NULL); |
121 | 128 |
122 SwapBuffers(); | 129 SwapBuffers(); |
123 } | 130 } |
124 | 131 |
125 glDeleteTextures(1, &texture); | 132 glDeleteTextures(1, &texture); |
126 DestroyContext(); | 133 DestroyContext(); |
127 return 0; | 134 return 0; |
128 } | 135 } |
OLD | NEW |