Esempio n. 1
0
static void vxo_rect_init()
{
    float verts_f[NVERTS*2] = {-0.5f,-0.5f,
                                0.5f,-0.5f,
                                0.5f, 0.5f,
                               -0.5f, 0.5f};
    uint32_t ind_i[NIDX] = {0,1,2,2,3,0};
    float norms_f[NVERTS*3] = {0,0,1,
                               0,0,1,
                               0,0,1,
                               0,0,1};


    points = vx_resc_copyf(verts_f, NVERTS*2);
    normals = vx_resc_copyf(norms_f, NVERTS*3);
    indices = vx_resc_copyui(ind_i, NIDX);

    vx_resc_inc_ref(points); // hold on to these references until vx_global_destroy()
    vx_resc_inc_ref(indices);
    vx_resc_inc_ref(normals);
}
Esempio n. 2
0
File: vxo_box.c Progetto: DH-std/A3
static void vxo_box_init()
{
    // for GL_POINTS
    float point_verts[NVERTS*3] =
        {
            -0.5f,-0.5f,-0.5f, // 0
            -0.5f,+0.5f,-0.5f, // 1
            +0.5f,+0.5f,-0.5f, // 2
            +0.5f,-0.5f,-0.5f, // 3
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,+0.5f, // 7
        };

    // for GL_LINES
    uint32_t line_idxs[N_LINE_IDX*2] =
        {
            0,1, 1,2, 2,3, 3,0, // bottom
            4,5, 5,6, 6,7, 7,4, // top
            0,4, 1,5, 2,6, 3,7  // sides
        };

    // for GL_TRIANGLES
    // Note: we could reduce the amount of vertex data
    // by using indices -- e.g. point 0 and 2 are listed twice with the
    // same normal on the bottom face (would save us 16 vertices out of 48)
    // each vertex is listed 6 times, has 3 coords
    float tri_verts[N_TRI_VERT*3] =
        {
            // Bottom Face
            +0.5f,+0.5f,-0.5f, // 2
            -0.5f,-0.5f,-0.5f, // 0
            -0.5f,+0.5f,-0.5f, // 1

            -0.5f,-0.5f,-0.5f, // 0
            +0.5f,+0.5f,-0.5f, // 2
            +0.5f,-0.5f,-0.5f, // 3

            // Top
            -0.5f,+0.5f,+0.5f, // 5
            -0.5f,-0.5f,+0.5f, // 4
            +0.5f,+0.5f,+0.5f, // 6

            +0.5f,+0.5f,+0.5f, // 6
            -0.5f,-0.5f,+0.5f, // 4
            +0.5f,-0.5f,+0.5f, // 7

            // Front
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,+0.5f, // 7
            +0.5f,-0.5f,-0.5f, // 3

            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,-0.5f,-0.5f, // 3
            +0.5f,+0.5f,-0.5f, // 2

            // Back
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,+0.5f, // 5
            -0.5f,+0.5f,-0.5f, // 1

            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,+0.5f,-0.5f, // 1
            -0.5f,-0.5f,-0.5f, // 0

            // Right
            +0.5f,-0.5f,+0.5f, // 7
            -0.5f,-0.5f,+0.5f, // 4
            -0.5f,-0.5f,-0.5f, // 0

            +0.5f,-0.5f,+0.5f, // 7
            -0.5f,-0.5f,-0.5f, // 0
            +0.5f,-0.5f,-0.5f, // 3

            // Left
            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,+0.5f, // 6
            +0.5f,+0.5f,-0.5f, // 2

            -0.5f,+0.5f,+0.5f, // 5
            +0.5f,+0.5f,-0.5f, // 2
            -0.5f,+0.5f,-0.5f, // 1
        };


    float tri_norms[N_TRI_VERT*3] =
    {
        // Bottom
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,
        +0.0f,+0.0f,-1.0f,

        // Top
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,
        +0.0f,+0.0f,+1.0f,

        // Front
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,
        +1.0f,+0.0f,+0.0f,

        // Back
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,
        -1.0f,+0.0f,+0.0f,

        // Right
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,
        +0.0f,-1.0f,+0.0f,

        // Left
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f,
        +0.0f,+1.0f,+0.0f
    };

    // triangles in CCW when viewed from outside the box
    /*
      2,0,1,0,2,3,  // bottom face
      5,4,6,6,4,7,  // top face
      6,7,3,6,3,2,  // front face
      4,5,1,4,1,0,  // back face
      7,4,0,7,0,3,  // right face
      5,6,2,5,2,1   // left face
    */

    vertex_points = vx_resc_copyf(point_verts, NVERTS*3);
    line_indices = vx_resc_copyui(line_idxs, N_LINE_IDX*2);
    tri_points = vx_resc_copyf(tri_verts, N_TRI_VERT*3);
    tri_normals = vx_resc_copyf(tri_norms, N_TRI_VERT*3);

    // hold on to these references until vx_global_destroy()
    vx_resc_inc_ref(vertex_points);
    vx_resc_inc_ref(line_indices);
    vx_resc_inc_ref(tri_points);
    vx_resc_inc_ref(tri_normals);
}
Esempio n. 3
0
File: vx_demo.c Progetto: DH-std/A3
static void draw(state_t * state, vx_world_t * world)
{
    if (1) {
        vx_buffer_add_back(vx_world_get_buffer(world, "grid"),
                           vxo_grid());
        vx_buffer_set_draw_order(vx_world_get_buffer(world, "grid"), -100);
        vx_buffer_swap(vx_world_get_buffer(world, "grid"));
    }

    // Draw from the vx shape library
    if (1) {
        vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"),
                           vxo_chain(vxo_mat_translate3(3.0,0,0),
                                     vxo_mat_scale3(2,2,2),
                                     /* vxo_box(vxo_mesh_style(vx_orange)))); */
                                     vxo_box(vxo_mesh_style_fancy(vx_orange, vx_orange, vx_white, 1.0, 400.0, 2))));


        vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"),
                           vxo_chain(vxo_mat_translate3(0,3.0,0),
                                     vxo_mat_scale3(1,1,1),
                                     vxo_depth_test(0,
                                                    vxo_box(vxo_mesh_style_solid(vx_green)))));
        vx_buffer_swap(vx_world_get_buffer(world, "fixed-cube"));
    }

    if (1) {
        float Tr = .2;
        float amb[] = {0.0,0.0,0.0};
        float diff[] = {0.0,0.0,0.0};
        float spec[] = {1.0,1.0,1.0};
        float specularity = 1.0;

        int type = 2;

        vx_buffer_add_back(vx_world_get_buffer(world, "window"),
                           vxo_chain(vxo_mat_translate3(0,0,2.5),
                                     vxo_mat_rotate_y(-M_PI/7),
                                     vxo_mat_rotate_z(M_PI/5),
                                     vxo_mat_rotate_x(M_PI/2),
                                     vxo_mat_scale3(10,10,1),
                                     vxo_rect(vxo_mesh_style_fancy(amb, diff, spec, Tr, specularity, type),
                                              vxo_lines_style(vx_black,2))));
        vx_buffer_swap(vx_world_get_buffer(world, "window"));
        vx_buffer_set_draw_order(vx_world_get_buffer(world, "window"), 100);
    }


    if (1) {
        // Draw a custom ellipse:
        int npoints = 35;
        float points[npoints*3];
        for (int i = 0; i < npoints; i++) {
            float angle = 2*M_PI*i/npoints;

            float x = 5.0f*cosf(angle);
            float y = 8.0f*sinf(angle);
            float z = 0.0f;

            points[3*i + 0] = x;
            points[3*i + 1] = y;
            points[3*i + 2] = z;
        }

        vx_buffer_add_back(vx_world_get_buffer(world, "ellipse"), vxo_lines(vx_resc_copyf (points, npoints*3),
                                                                            npoints, GL_LINE_LOOP,
                                                                            vxo_lines_style(vx_purple, 1.0f) ));
        vx_buffer_swap(vx_world_get_buffer(world, "ellipse"));
    }

    if (1) {
        vx_object_t *vt = vxo_text_create(VXO_TEXT_ANCHOR_TOP_RIGHT, "<<right,#0000ff>>Heads Up!\n");
        vx_buffer_t *vb = vx_world_get_buffer(world, "text");
        vx_buffer_add_back(vb, vxo_pix_coords(VX_ORIGIN_TOP_RIGHT,vt));
        vx_buffer_swap(vb);
    }

    // Draw a texture
    if (state->img != NULL){
        image_u32_t * img = state->img;
        vx_object_t * o3 = vxo_image_texflags(vx_resc_copyui(img->buf, img->stride*img->height),
                                              img->width, img->height, img->stride,
                                              GL_RGBA, VXO_IMAGE_FLIPY,
                                              VX_TEX_MIN_FILTER | VX_TEX_MAG_FILTER);

        // pack the image into the unit square
        vx_buffer_t * vb = vx_world_get_buffer(world, "texture");
        vx_buffer_add_back(vb,vxo_chain(
                               vxo_mat_scale(1.0/img->height),
                               vxo_mat_translate3(0, - img->height, 0),
                                        o3));
        vx_buffer_swap(vb);
    }
}