Exemple #1
0
static void _init_gfx(game *g, int win_width, int win_height) {
    _sdl_init(g, win_width, win_height);

    char *res_path = get_res_path(""),
         *w_vs_path = join_path(res_path, "world_vert.glsl"),
         *w_fs_path = join_path(res_path, "world_frag.glsl"),
         *o_vs_path = join_path(res_path, "overlay_vert.glsl"),
         *o_fs_path = join_path(res_path, "overlay_frag.glsl");

    g->world_shader = _shader_init(w_vs_path, w_fs_path);
    g->overlay_shader = _shader_init(o_vs_path, o_fs_path);

    free(w_vs_path);
    free(w_fs_path);
    free(o_vs_path);
    free(o_fs_path);
    free(res_path);

    if (g->world_shader == -1) {
        puts("Error creating world shader!");
        _destroy_gfx(g);
        exit(EXIT_FAILURE);
    }

    if (g->overlay_shader == -1) {
        puts("Error creating overlay shader!");
        _destroy_gfx(g);
        exit(EXIT_FAILURE);
    }
}
Exemple #2
0
static int window_create_show()
{
    char *tmp;

    // window
    m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    tmp = get_res_path(ICON_APP);
    gtk_window_set_icon_from_file(GTK_WINDOW(m_window), tmp, NULL);
    free(tmp);
    gtk_window_set_title(GTK_WINDOW(m_window), "jnXssh");
    gtk_window_maximize(GTK_WINDOW(m_window));
    gtk_widget_set_events(m_window, GDK_BUTTON_PRESS_MASK|GDK_KEY_PRESS_MASK);
    g_signal_connect(G_OBJECT(m_window), "key-press-event", G_CALLBACK(on_window_key_press), NULL);
    g_signal_connect(G_OBJECT(m_window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
    
        // vbox
        GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
        gtk_container_add(GTK_CONTAINER(m_window), vbox);

            // notebook
            GtkWidget *notebook = page_get_notebook();
            gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);

            // pty + vte
            GtkWidget *vte = vte_terminal_new();
            gtk_box_pack_start(GTK_BOX(vbox), vte, FALSE, FALSE, 1);
            vte_terminal_set_size((VteTerminal*)vte, 1, 1);
            VtePty *pty = vte_pty_new(VTE_PTY_DEFAULT, NULL); 
            vte_terminal_set_pty_object((VteTerminal*)vte, pty);
            pthread_t tid;
            pthread_create(&tid, NULL, proc_allvte, pty);

    gtk_widget_show_all(m_window);

    return 0;
}
Exemple #3
0
static void _init_overlay(game *g) {
    overlay *o = &g->o;

    // Texture values
    o->tex_format = GL_RGBA;
    o->int_format = GL_RGBA8;
    o->tex_type = GL_UNSIGNED_INT_8_8_8_8;
    o->alignment = 4;

    // Font values
    o->update_text_max = 8;
    o->label_text_max = 32;
    o->text_pad = 0.5;
    o->font_spacing = 1.2;

    // Surface values
    Uint32 rmask = 0xff000000;
    Uint32 gmask = 0x00ff0000;
    Uint32 bmask = 0x0000ff00;
    Uint32 amask = 0x000000ff;

    // Overlay stuff
    o->size = 0.4;
    o->mvp = malloc(sizeof(mat4x4));
    mat4x4_ortho(*o->mvp, -g->aspect, g->aspect, -1.0, 1.0, 0, 10);

    int win_width, win_height, overlay_width, overlay_height;
    SDL_GetWindowSize(g->win, &win_width, &win_height);

    overlay_width = win_width * o->size;
    overlay_height = win_height * o->size;

    float overlay_triangles[8] = {
        -g->aspect*o->size,  o->size, // Top left
        -g->aspect*o->size, -o->size, // Bottom left
         g->aspect*o->size, -o->size, // Bottom right
         g->aspect*o->size,  o->size, // Top right
    };

    GLubyte overlay_elements[6] = {
        0, 1, 2,
        0, 2, 3
    };

    float overlay_tex_coords[8] = {
        0.0, 0.0, // Top left
        0.0, 1.0, // Bottom left
        1.0, 1.0, // Bottom right
        1.0, 0.0, // Top right
    };

    o->matrix_id = glGetUniformLocation(g->overlay_shader, "MVP");
    o->tex_coords_id = glGetAttribLocation(g->overlay_shader, "tex_coord");

    glUseProgram(g->overlay_shader);
    glUniformMatrix4fv(o->matrix_id, 1, GL_FALSE, (GLfloat *) o->mvp);
    glUseProgram(0);

    glGenBuffers(1, &o->vert_buf);

    glBindBuffer(GL_ARRAY_BUFFER, o->vert_buf);
    glBufferData(GL_ARRAY_BUFFER, sizeof(overlay_triangles), &overlay_triangles, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenBuffers(1, &o->tex_coord_buf);

    glBindBuffer(GL_ARRAY_BUFFER, o->tex_coord_buf);
    glBufferData(GL_ARRAY_BUFFER, sizeof(overlay_tex_coords), &overlay_tex_coords, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenBuffers(1, &o->el_buf);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, o->el_buf);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(overlay_elements), &overlay_elements, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    // Set up font things
    char *res_path = get_res_path(""),
         *font_path = join_path(res_path, "DejaVuSansMono.ttf");

    o->font = TTF_OpenFont(font_path, 14);

    free(res_path);
    free(font_path);

    o->font_text = calloc(o->update_text_max+1, sizeof(char));

    o->bg = SDL_CreateRGBSurface(
        0, overlay_width, overlay_height, 32, rmask, gmask, bmask, amask
    );
    if (o->bg == NULL) {
        printf("BLARGH: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }
    o->font_text[0] = 'W';
    SDL_Surface *temp_surf;
    temp_surf = TTF_RenderText_Solid(o->font, o->font_text, o->font_col);
    int font_w = temp_surf->w;
    int font_h = temp_surf->h;
    SDL_free(temp_surf);

    o->font_surf = SDL_CreateRGBSurface(
        0, font_w * o->update_text_max + 1, font_h, 32, rmask, gmask, bmask, amask
    );

    // Render static text
    _update_colors(g, g->color_scheme);

    glGenTextures(1, &o->tex);
    glBindTexture(GL_TEXTURE_2D, o->tex);

    glPixelStorei(GL_UNPACK_ALIGNMENT, o->alignment);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, o->int_format, o->bg->w, o->bg->h, 0, o->tex_format, o->tex_type, o->bg->pixels);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
}