vx_object_t * _vxo_rect_private(vx_style_t * style, ...) { // Make sure the static geometry is initialized safely, correctly, and quickly if (points == NULL) { vx_global_lock(); if (points == NULL) { vxo_rect_init(); vx_global_register_destroy(vxo_rect_destroy, NULL); } vx_global_unlock(); } vx_object_t * vc = vxo_chain_create(); va_list va; va_start(va, style); for (vx_style_t * sty = style; sty != NULL; sty = va_arg(va, vx_style_t *)) { switch(sty->type) { case VXO_POINTS_STYLE: vxo_chain_add(vc, vxo_points(points, NVERTS, sty)); break; case VXO_LINES_STYLE: vxo_chain_add(vc, vxo_lines(points, NVERTS, GL_LINE_LOOP, sty)); break; case VXO_MESH_STYLE: vxo_chain_add(vc, vxo_mesh_indexed(points, NVERTS, normals, indices, GL_TRIANGLES, sty)); break; } } va_end(va); return vc; }
vx_object_t * _vxo_box_private(vx_style_t * style, ...) { // Make sure the static geometry is initialized safely, correctly, and quickly if (vertex_points == NULL) { pthread_mutex_lock(&vx_convenience_mutex); if (vertex_points == NULL) { vxo_box_init(); vx_global_register_destroy(vxo_box_destroy, NULL); } pthread_mutex_unlock(&vx_convenience_mutex); } vx_object_t * vc = vxo_chain_create(); va_list va; va_start(va, style); for (vx_style_t * sty = style; sty != NULL; sty = va_arg(va, vx_style_t *)) { switch(sty->type) { case VXO_POINTS_STYLE: vxo_chain_add(vc, vxo_points(vertex_points, NVERTS, sty)); break; case VXO_LINES_STYLE: vxo_chain_add(vc, vxo_lines_indexed(vertex_points, NVERTS, line_indices, GL_LINES, sty)); break; case VXO_MESH_STYLE: // XXX always pass normals? vxo_chain_add(vc, vxo_mesh(tri_points, N_TRI_VERT, tri_normals, GL_TRIANGLES, sty)); break; } } va_end(va); return vc; }
static void draw(state_t * state, vx_world_t * world) { // Draw from the vx shape library vx_buffer_add_back(vx_world_get_buffer(world, "fixed-cube"), vxo_chain(vxo_mat_translate3(3.0,0,0), vxo_mat_scale(2), vxo_box(vxo_mesh_style(vx_orange)))); vx_buffer_swap(vx_world_get_buffer(world, "fixed-cube")); // Draw some text if (1) { vx_object_t *vt = vxo_text_create(VXO_TEXT_ANCHOR_LEFT, "<<right>>hello!\n<<serif-italic-4>>line 2\nfoo<<#ff0000>>red<<sansserif-bold-30,#0000ff80>>blue semi\n<<serif-italic-4>>foo bar baz"); vx_buffer_t *vb = vx_world_get_buffer(world, "text"); vx_buffer_add_back(vb, vt); vx_buffer_swap(vb); } // 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")); } // Draw a sin wave { int npoints = 100; float points[npoints*3]; for (int i = 0; i < npoints; i++) { float angle = 2*M_PI*i/npoints; float x = i*.1; float y = 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, "sin"), vxo_points(vx_resc_copyf (points, npoints*3), npoints, vxo_points_style(vx_purple, 10.0))); vx_buffer_swap(vx_world_get_buffer(world, "sin")); } // Draw a cos wave { int npoints = 100; float points[npoints*3]; float colors[npoints*4]; for (int i = 0; i < npoints; i++) { float angle = 2*M_PI*i/npoints; float x = i*.1; float y = cosf(angle); float z = 0.0f; points[3*i + 0] = x; points[3*i + 1] = y; points[3*i + 2] = z; float r = angle/(2*M_PI); float g = 0.3f; float b = 1.0f-(angle/(2*M_PI)); colors[4*i + 0] = r; colors[4*i + 1] = g; colors[4*i + 2] = b; colors[4*i + 3] = 1.0f; } vx_buffer_add_back(vx_world_get_buffer(world, "cos"), vxo_points(vx_resc_copyf (points, npoints*3), npoints, vxo_points_style_multi_colored(vx_resc_copyf(colors, npoints*4), 10.0))); vx_buffer_swap(vx_world_get_buffer(world, "cos")); } // Draw a rose if (1) { int npoints = 100; float points[npoints*3]; float colors[npoints*4]; int k = 3; for (int i = 0; i < npoints; i++) { float angle = M_PI*i/npoints; // [0, Pi] for Odd float x = cosf(k*angle)*sin(angle); float y = cosf(k*angle)*cos(angle); float z = 0.0f; points[3*i + 0] = x; points[3*i + 1] = y; points[3*i + 2] = z; float r = angle/(M_PI); float g = 1.0f-(angle/(M_PI)); float b = 0.3f; colors[4*i + 0] = r; colors[4*i + 1] = g; colors[4*i + 2] = b; colors[4*i + 3] = 1.0f; } vx_buffer_add_back(vx_world_get_buffer(world, "rose"), vxo_lines(vx_resc_copyf (points, npoints*3), npoints, GL_LINE_LOOP, vxo_lines_style_multi_colored(vx_resc_copyf(colors, npoints*4), 1.0))); vx_buffer_swap(vx_world_get_buffer(world, "rose")); } if (1) { // draw a box with all the fixings vx_buffer_t * vb = vx_world_get_buffer(world, "rect"); // should draw purple square, with green lines, all occluded by red corners. vx_buffer_add_back(vb, vxo_depth_test(0,vxo_chain( vxo_mat_translate2(-5,-5), vxo_rect(vxo_mesh_style(vx_purple), vxo_lines_style(vx_green, 6.0f), vxo_points_style(vx_red, 6.0f))))); vx_buffer_swap(vb); } // Draw a texture if (state->img != NULL) { image_u8_t * img = state->img; vx_object_t * o3 = vxo_image(vx_resc_copyub(img->buf, img->width*img->height*img->bpp), img->width, img->height, img->bpp == 4? GL_RGBA : GL_RGB, VXO_IMAGE_FLIPY); // 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_scale3(1.0/img->width, 1.0/img->height, 1), o3)); vx_buffer_swap(vb); } }