B_Block *spawn_bb_rect(float x, float y, float z,float w, float h, float d){ B_Block *rect = NULL; rect = newBBlock(); if(rect == NULL){ return NULL; } rect->position.x = x; rect->position.y = y; rect->position.z = z; rect->self = rect; rect->texture = sprite_load(const_cast<char *>("textures/block_tex.jpg"), 640, 640, 1); rect->normal_map = sprite_load(const_cast<char *>("textures/block_tex_normal.jpg"), 640, 640, 1); rect->shaderProgram = get_shader_program(NORMALMAP_SHADER); rect->update = b_update; rect->updateRate = 0; rect->mass = 10.0f; rect->halfExtents.x= w; rect->halfExtents.y= h; rect->halfExtents.z= d; rect->model = readOBJ(const_cast<char *>("textures/testblock.obj")); rect->body = add_new_box_to_world(rect->halfExtents.x,rect->halfExtents.y,rect->halfExtents.z,rect->mass,0.0f,0.0f,0.0f,1); //set_angular_props(rect->body,0,0,0,0,0,0); set_body_position(rect->body, x, y, z); set_body_friction(rect->body, 1000000.0f); set_body_restitution(rect->body, 0.0f); set_damping(rect->body,0.0f,0.0f); set_sleeping_thresholds(rect->body,0.5f,0.5f); plEnableCallbacks(rect->body->body); return rect; }
void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { struct gs_index_buffer *ib = device->cur_index_buffer; GLenum topology = convert_gs_topology(draw_mode); gs_effect_t *effect = gs_get_effect(); struct gs_program *program; if (!can_render(device)) goto fail; if (effect) gs_effect_update_params(effect); program = get_shader_program(device); if (!program) goto fail; load_vb_buffers(program, device->cur_vertex_buffer); if (program != device->cur_program && device->cur_program) { glUseProgram(0); gl_success("glUseProgram (zero)"); } if (program != device->cur_program) { device->cur_program = program; glUseProgram(program->obj); if (!gl_success("glUseProgram")) goto fail; } update_viewproj_matrix(device); program_update_params(program); if (ib) { if (num_verts == 0) num_verts = (uint32_t)device->cur_index_buffer->num; glDrawElements(topology, num_verts, ib->gl_type, (const GLvoid*)(start_vert * ib->width)); if (!gl_success("glDrawElements")) goto fail; } else { if (num_verts == 0) num_verts = (uint32_t)device->cur_vertex_buffer->num; glDrawArrays(topology, start_vert, num_verts); if (!gl_success("glDrawArrays")) goto fail; } return; fail: blog(LOG_ERROR, "device_draw (GL) failed"); }