51 glRasterPos3f(
x,
y, 0);
52 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
54 printf(
"display %s\n", text);
56 for (c = text; *c !=
'\0'; c++) {
57 const uint8_t *bitmap = helvetica10_character_map[*c];
67 static string last_text;
69 if (text != last_text) {
78 const int height = 20;
82 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
83 glColor4f(0.1f, 0.1f, 0.1f, 0.8f);
84 glRectf(0.0f,
V.height - height,
V.width,
V.height);
87 glColor3f(0.5f, 0.5f, 0.5f);
93 glColor3f(1.0f, 1.0f, 1.0f);
99 const int w = (int)((
float)
V.width / 1.15f);
100 const int h = (int)((
float)
V.height / 1.15f);
102 const int x1 = (
V.width -
w) / 2;
104 const int x2 = x1 +
w;
107 const int y1 = (
V.height - h) / 2;
108 const int y2 = y1 + h;
112 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
113 glColor4f(0.5f, 0.5f, 0.5f, 0.8f);
114 glRectf(x1, y1, x2, y2);
117 glColor3f(0.8f, 0.8f, 0.8f);
138 glColor3f(1.0f, 1.0f, 1.0f);
144 if (
V.first_display) {
152 V.first_display =
false;
157 glViewport(0, 0,
V.width,
V.height);
159 glMatrixMode(GL_PROJECTION);
162 glMatrixMode(GL_MODELVIEW);
165 glClearColor(0.05f, 0.05f, 0.05f, 0.0f);
166 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
168 glMatrixMode(GL_PROJECTION);
170 glOrtho(0,
V.width, 0,
V.height, -1, 1);
172 glMatrixMode(GL_MODELVIEW);
175 glRasterPos3f(0, 0, 0);
181 SDL_GL_SwapWindow(
V.window);
187 if (
V.width != width ||
V.height != height) {
189 V.resize(width, height);
215 if (button == SDL_BUTTON_LEFT) {
216 if (
state == SDL_MOUSEBUTTONDOWN) {
221 else if (
state == SDL_MOUSEBUTTONUP) {
225 else if (button == SDL_BUTTON_RIGHT) {
226 if (
state == SDL_MOUSEBUTTONDOWN) {
231 else if (
state == SDL_MOUSEBUTTONUP) {
239 const int but =
V.mouseBut0 ? 0 : 2;
240 const int distX =
x -
V.mouseX;
241 const int distY =
y -
V.mouseY;
244 V.motion(distX, distY, but);
253 V.gl_context_mutex.lock();
254 SDL_GL_MakeCurrent(
V.window,
V.gl_context);
260 SDL_GL_MakeCurrent(
V.window,
nullptr);
261 V.gl_context_mutex.unlock();
276 V.first_display =
true;
282 V.keyboard = keyboard;
285 SDL_Init(SDL_INIT_VIDEO);
286 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
287 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
288 V.window = SDL_CreateWindow(title,
289 SDL_WINDOWPOS_UNDEFINED,
290 SDL_WINDOWPOS_UNDEFINED,
293 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
294 if (
V.window ==
nullptr) {
295 LOG_ERROR <<
"Failed to create window: " << SDL_GetError();
299 SDL_RaiseWindow(
V.window);
301 V.gl_context = SDL_GL_CreateContext(
V.window);
302 SDL_GL_MakeCurrent(
V.window,
nullptr);
310 while (!quit && SDL_PollEvent(&event)) {
311 if (event.type == SDL_TEXTINPUT) {
314 else if (event.type == SDL_MOUSEMOTION) {
317 else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
318 window_mouse(event.button.button, event.button.state, event.button.x, event.button.y);
320 else if (event.type == SDL_WINDOWEVENT) {
321 if (event.window.event == SDL_WINDOWEVENT_RESIZED ||
322 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
327 else if (event.type == SDL_QUIT) {
344 SDL_WaitEventTimeout(
nullptr, 100);
347 SDL_GL_DeleteContext(
V.gl_context);
348 SDL_DestroyWindow(
V.window);
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
#define CCL_NAMESPACE_END
#define LOG_INFO_IMPORTANT
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