コード例 #1
0
static inline jlong wrapped_Java_com_badlogic_jglfw_Glfw_glfwCreateCursor
(JNIEnv* env, jclass clazz, jobject obj_image, jint width, jint height, jint xhot, jint yhot, char* image) {

//@line:926

	const GLFWimage im = {width, height, (unsigned char*)image};
	return (jlong) glfwCreateCursor(&im, xhot, yhot);
	 
}
コード例 #2
0
static GLFWcursor* create_cursor_frame(float t)
{
    int i = 0, x, y;
    unsigned char buffer[64 * 64 * 4];
    const GLFWimage image = { 64, 64, buffer };

    for (y = 0;  y < image.width;  y++)
    {
        for (x = 0;  x < image.height;  x++)
        {
            buffer[i++] = 255;
            buffer[i++] = 255;
            buffer[i++] = 255;
            buffer[i++] = (unsigned char) (255 * star(x, y, t));
        }
    }

    return glfwCreateCursor(&image, image.width / 2, image.height / 2);
}
コード例 #3
0
int main( void )
{
    GLFWwindow *window;
    
    // Initialize the library
    if ( !glfwInit( ) )
    {
        return -1;
    }
    
    // Create a windowed mode window and its OpenGL context
    window = glfwCreateWindow( SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL );
    
    glfwSetCursorPosCallback( window, cursorPositionCallback );
    glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_NORMAL );
    
    glfwSetCursorEnterCallback( window, cursorEnterCallback );
    
    glfwSetMouseButtonCallback( window, mouseButtonCallback );
    glfwSetInputMode( window, GLFW_STICKY_MOUSE_BUTTONS, 1 );
    
    glfwSetScrollCallback( window, scrollCallback );
    
    unsigned char pixels[16 * 16 * 4];
    memset( pixels, 0xff, sizeof( pixels ) );
    GLFWimage image;
    image.width = 16;
    image.height = 16;
    image.pixels = pixels;
    GLFWcursor *cursor = glfwCreateCursor( &image, 0, 0 );
    glfwSetCursor( window, cursor ); // set to null to reset cursor
    
    int screenWidth, screenHeight;
    glfwGetFramebufferSize( window, &screenWidth, &screenHeight );

    if ( !window )
    {
        glfwTerminate( );
        return -1;
    }
    
    // Make the window's context current
    glfwMakeContextCurrent( window );
    
    glViewport( 0.0f, 0.0f, screenWidth, screenHeight ); // specifies the part of the window to which OpenGL will draw (in pixels), convert from normalised to pixels
    glMatrixMode( GL_PROJECTION ); // projection matrix defines the properties of the camera that views the objects in the world coordinate frame. Here you typically set the zoom factor, aspect ratio and the near and far clipping planes
    glLoadIdentity( ); // replace the current matrix with the identity matrix and starts us a fresh because matrix transforms such as glOrpho and glRotate cumulate, basically puts us at (0, 0, 0)
    glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1 ); // essentially set coordinate system
    glMatrixMode( GL_MODELVIEW ); // (default matrix mode) modelview matrix defines how your objects are transformed (meaning translation, rotation and scaling) in your world
    glLoadIdentity( ); // same as above comment
    
    
    // Loop until the user closes the window
    while ( !glfwWindowShouldClose( window ) )
    {
        glClear( GL_COLOR_BUFFER_BIT );
        
        // Render OpenGL here
        
        double xpos, ypos;
        glfwGetCursorPos( window, &xpos, &ypos );
        
        // Swap front and back buffers
        glfwSwapBuffers( window );
        
        // Poll for and process events
        glfwPollEvents( );
    }
    
    glfwTerminate( );
    
    return 0;
}
コード例 #4
0
ファイル: cursor.c プロジェクト: ColinGilbert/noobEngine
static void command_callback(int key)
{
    switch (key)
    {
        case GLFW_KEY_H:
        {
            printf("H: show this help\n");
            printf("C: call glfwCreateCursor()\n");
            printf("D: call glfwDestroyCursor()\n");
            printf("S: call glfwSetCursor()\n");
            printf("N: call glfwSetCursor() with NULL\n");
            printf("1: set GLFW_CURSOR_NORMAL\n");
            printf("2: set GLFW_CURSOR_HIDDEN\n");
            printf("3: set GLFW_CURSOR_DISABLED\n");
            printf("T: enable 3s delay for all previous commands\n");
        }
        break;

        case GLFW_KEY_C:
        {
            int x, y;
            GLFWimage image;
            unsigned char* pixels;

            if (cursor)
              break;

            image.width = cursorSize[currentSize].w;
            image.height = cursorSize[currentSize].h;

            pixels = malloc(4 * image.width * image.height);
            image.pixels = pixels;

            for (y = 0;  y < image.height;  y++)
            {
                for (x =  0;  x < image.width;  x++)
                {
                    *pixels++ = 0xff;
                    *pixels++ = 0;
                    *pixels++ = 255 * y / image.height;
                    *pixels++ = 255 * x / image.width;
                }
            }

            cursor = glfwCreateCursor(&image, image.width / 2, image.height / 2);
            currentSize = (currentSize + 1) % SizeCount;
            free(image.pixels);
            break;
        }

        case GLFW_KEY_D:
        {
            if (cursor != NULL)
            {
                glfwDestroyCursor(cursor);
                cursor = NULL;
            }

            break;
        }

        case GLFW_KEY_S:
        {
            if (cursor != NULL)
                glfwSetCursor(activeWindow, cursor);
            else
                printf("The cursor is not created\n");

            break;
        }

        case GLFW_KEY_N:
            glfwSetCursor(activeWindow, NULL);
            break;

        case GLFW_KEY_1:
            glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
            break;

        case GLFW_KEY_2:
            glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
            break;

        case GLFW_KEY_3:
            glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
            break;
    }
}