33 #include <glad/glad.h> 38 #define _USE_MATH_DEFINES 47 #define CURSOR_FRAME_COUNT 60 52 "attribute vec2 vPos;\n" 55 " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 62 " gl_FragColor = vec4(1.0);\n" 75 fprintf(
stderr,
"Error: %s\n", description);
80 const float c = 64 / 2.f;
82 const float i = (0.25f * (float) sin(2.
f * M_PI * t) + 0.75f);
83 const float k = 64 * 0.046875f *
i;
85 const float dist = (float) sqrt((x - c) * (x -
c) + (y - c) * (y -
c));
87 const float salpha = 1.f - dist /
c;
88 const float xalpha = (float) x == c ? c : k / (
float) fabs(x - c);
89 const float yalpha = (float) y == c ? c : k / (
float) fabs(y - c);
91 return (
float) fmax(0.
f, fmin(1.
f, i * salpha * 0.2
f + salpha * xalpha * yalpha));
97 unsigned char buffer[64 * 64 * 4];
100 for (y = 0; y < image.
width; y++)
107 buffer[i++] = (
unsigned char) (255 *
star(
x, y, t));
116 printf(
"%0.3f: Cursor position: %f %f (%+f %+f)\n",
153 printf(
"(( cursor is normal ))\n");
158 printf(
"(( cursor is disabled ))\n");
163 printf(
"(( cursor is hidden ))\n");
174 printf(
"(( %sing for events ))\n",
wait_events ?
"wait" :
"poll");
217 GLuint vertex_buffer, vertex_shader, fragment_shader, program;
218 GLint mvp_location, vpos_location;
228 if (!star_cursors[i])
237 const int shapes[] = {
288 sizeof(vec2), (
void*) 0);
303 int wnd_width, wnd_height, fb_width, fb_height;
313 scale = (float) fb_width / (
float) wnd_width;
314 vertices[0][0] = 0.f;
315 vertices[0][1] = (float) (fb_height -
cursor_y * scale);
316 vertices[1][0] = (float) fb_width;
317 vertices[1][1] = (float) (fb_height -
cursor_y * scale);
318 vertices[2][0] = (float) (
cursor_x * scale);
319 vertices[2][1] = 0.f;
320 vertices[3][0] = (float) (
cursor_x * scale);
321 vertices[3][1] = (float) fb_height;
339 if (current_frame != star_cursors[i])
342 current_frame = star_cursors[
i];
346 current_frame =
NULL;
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
The header of the GLFW 3 API.
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
static void mat4x4_ortho(mat4x4 M, float l, float r, float b, float t, float n, float f)
#define glGetAttribLocation
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
#define GLFW_CONTEXT_VERSION_MAJOR
Context client API major version hint and attribute.
static float star(int x, int y, float t)
static void error_callback(int error, const char *description)
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
#define glUniformMatrix4fv
#define GLFW_CROSSHAIR_CURSOR
The crosshair shape.
#define GLFW_ARROW_CURSOR
The regular arrow cursor shape.
static const struct @17 vertices[3]
#define GLFW_CURSOR_DISABLED
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
#define GLFW_VRESIZE_CURSOR
The vertical resize arrow shape.
#define glVertexAttribPointer
static int animate_cursor
GLenum GLenum GLsizei void * image
#define glEnableVertexAttribArray
#define GL_COLOR_BUFFER_BIT
#define GLFW_CURSOR_NORMAL
#define CURSOR_FRAME_COUNT
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
#define GLFW_HAND_CURSOR
The hand shape.
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
void key(GLFWwindow *window, int k, int s, int action, int mods)
#define glGetUniformLocation
#define GL_FRAGMENT_SHADER
static GLFWcursor * create_cursor_frame(float t)
GLAPI int gladLoadGLLoader(GLADloadproc)
static GLFWcursor * standard_cursors[6]
static const textual_icon exit
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
GLFWAPI void glfwWaitEvents(void)
Waits until events are queued and processes them.
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
GLFWAPI void glfwWaitEventsTimeout(double timeout)
Waits with timeout until events are queued and processes them.
#define GLFW_CURSOR_HIDDEN
#define GLFW_HRESIZE_CURSOR
The horizontal resize arrow shape.
#define GLFW_IBEAM_CURSOR
The text input I-beam cursor shape.
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
static const char * fragment_shader_text
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
static const char * vertex_shader_text
#define GLFW_CONTEXT_VERSION_MINOR
Context client API minor version hint and attribute.
static void cursor_position_callback(GLFWwindow *window, double x, double y)
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.