50 glRasterPos3f(
x,
y, 0);
51 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
53 printf(
"display %s\n", text);
55 for (c = text; *c !=
'\0'; c++) {
56 const uint8_t *bitmap = helvetica10_character_map[*c];
66 static string last_text;
68 if (text != last_text) {
77 const int height = 20;
81 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
82 glColor4f(0.1f, 0.1f, 0.1f, 0.8f);
83 glRectf(0.0f,
V.height - height,
V.width,
V.height);
86 glColor3f(0.5f, 0.5f, 0.5f);
92 glColor3f(1.0f, 1.0f, 1.0f);
98 const int w = (int)((
float)
V.width / 1.15f);
99 const int h = (int)((
float)
V.height / 1.15f);
101 const int x1 = (
V.width -
w) / 2;
103 const int x2 = x1 +
w;
106 const int y1 = (
V.height - h) / 2;
107 const int y2 = y1 + h;
111 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
112 glColor4f(0.5f, 0.5f, 0.5f, 0.8f);
113 glRectf(x1, y1, x2, y2);
116 glColor3f(0.8f, 0.8f, 0.8f);
137 glColor3f(1.0f, 1.0f, 1.0f);
143 if (
V.first_display) {
151 V.first_display =
false;
156 glViewport(0, 0,
V.width,
V.height);
158 glMatrixMode(GL_PROJECTION);
161 glMatrixMode(GL_MODELVIEW);
164 glClearColor(0.05f, 0.05f, 0.05f, 0.0f);
165 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
167 glMatrixMode(GL_PROJECTION);
169 glOrtho(0,
V.width, 0,
V.height, -1, 1);
171 glMatrixMode(GL_MODELVIEW);
174 glRasterPos3f(0, 0, 0);
180 SDL_GL_SwapWindow(
V.window);
186 if (
V.width != width ||
V.height != height) {
188 V.resize(width, height);
214 if (button == SDL_BUTTON_LEFT) {
215 if (
state == SDL_MOUSEBUTTONDOWN) {
220 else if (
state == SDL_MOUSEBUTTONUP) {
224 else if (button == SDL_BUTTON_RIGHT) {
225 if (
state == SDL_MOUSEBUTTONDOWN) {
230 else if (
state == SDL_MOUSEBUTTONUP) {
238 const int but =
V.mouseBut0 ? 0 : 2;
239 const int distX =
x -
V.mouseX;
240 const int distY =
y -
V.mouseY;
243 V.motion(distX, distY, but);
252 V.gl_context_mutex.lock();
253 SDL_GL_MakeCurrent(
V.window,
V.gl_context);
259 SDL_GL_MakeCurrent(
V.window,
nullptr);
260 V.gl_context_mutex.unlock();
275 V.first_display =
true;
281 V.keyboard = keyboard;
284 SDL_Init(SDL_INIT_VIDEO);
285 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
286 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
287 V.window = SDL_CreateWindow(title,
288 SDL_WINDOWPOS_UNDEFINED,
289 SDL_WINDOWPOS_UNDEFINED,
292 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
293 if (
V.window ==
nullptr) {
294 fprintf(stderr,
"Failed to create window: %s\n", SDL_GetError());
298 SDL_RaiseWindow(
V.window);
300 V.gl_context = SDL_GL_CreateContext(
V.window);
301 SDL_GL_MakeCurrent(
V.window,
nullptr);
309 while (!quit && SDL_PollEvent(&event)) {
310 if (event.type == SDL_TEXTINPUT) {
313 else if (event.type == SDL_MOUSEMOTION) {
316 else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
317 window_mouse(event.button.button, event.button.state, event.button.x, event.button.y);
319 else if (event.type == SDL_WINDOWEVENT) {
320 if (event.window.event == SDL_WINDOWEVENT_RESIZED ||
321 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
326 else if (event.type == SDL_QUIT) {
343 SDL_WaitEventTimeout(
nullptr, 100);
346 SDL_GL_DeleteContext(
V.gl_context);
347 SDL_DestroyWindow(
V.window);
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
#define CCL_NAMESPACE_END
WindowKeyboardFunc keyboard
WindowDisplayFunc display
thread_mutex gl_context_mutex
#define CYCLES_VERSION_STRING
static void window_motion(const int x, const int y)
void window_opengl_context_disable()
bool window_opengl_context_enable()
void window_display_info(const char *info)
static void window_mouse(const int button, const int state, const int x, int y)
void window_main_loop(const char *title, const int width, const int height, WindowInitFunc initf, WindowExitFunc exitf, WindowResizeFunc resize, WindowDisplayFunc display, WindowKeyboardFunc keyboard, WindowMotionFunc motion)
static void window_display()
static void window_reshape(const int width, const int height)
CCL_NAMESPACE_BEGIN struct Window V
static void window_display_text(int, int, const char *text)
static bool window_keyboard(unsigned char key)
void window_display_help()
void(*)(unsigned char) WindowKeyboardFunc
void(*)(int, int, int) WindowMotionFunc
void(*)() WindowDisplayFunc
void(*)(int, int) WindowResizeFunc