int main(int argc, char* argv[]){ if (argc > 1 ){ CommandLineOptions(argc, argv); } QApplication app(argc, argv); MainWindow tux(argc>1 ? argv[1] : ""); app.setMainWidget( &tux ); return app.exec(); }
static int sapi_tux_read_post(char *buffer, uint count_bytes) { #if 0 int amount = 0; TSRMLS_FETCH(); TG(req)->objectlen = count_bytes; TG(req)->object_addr = buffer; if (tux(TUX_ACTION_READ_POST_DATA, TG(req))) return 0; TG(read_post_data) = 1; return TG(req)->objectlen; #else return 0; #endif }
// The start of the Application int App::start(const std::vector<CL_String> &args) { quit = false; CL_GL1WindowDescription desc; desc.set_title("ClanLib Object 3D Example"); desc.set_size(CL_Size(640, 480), true); desc.set_multisampling(4); desc.set_depth_size(16); CL_DisplayWindow window(desc); #ifdef _DEBUG //struct aiLogStream stream; //stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); //aiAttachLogStream(&stream); //stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt"); //aiAttachLogStream(&stream); #endif // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); // Connect a keyboard handler to on_key_up() CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); // Get the graphic context CL_GraphicContext gc = window.get_gc(); #ifdef USE_OPENGL_1 CL_GraphicContext_GL1 gc_gl1 = gc; #endif // Prepare the display gc.set_map_mode(cl_user_projection); CL_PolygonRasterizer polygon_rasterizer; polygon_rasterizer.set_culled(true); polygon_rasterizer.set_face_cull_mode(cl_cull_back); polygon_rasterizer.set_front_face(cl_face_side_clockwise); gc.set_polygon_rasterizer(polygon_rasterizer); CL_BufferControl buffer_control; buffer_control.enable_depth_test(true); buffer_control.set_depth_compare_function(cl_comparefunc_lequal); buffer_control.enable_depth_write(true); gc.set_buffer_control(buffer_control); #ifdef USE_OPENGL_1 // Set the lights CL_LightModel_GL1 light_model; light_model.enable_lighting(true); light_model.set_flat_shading(false); light_model.set_scene_ambient_light(CL_Colorf(0.2f, 0.2f, 0.2f, 1.0f)); gc_gl1.set_light_model(light_model); CL_LightSource_GL1 light_distant; light_distant.set_spot_cutoff(180.0f); light_distant.set_diffuse_intensity(CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); light_distant.set_position(CL_Vec4f(0.0f, -2.0f, 30.0f, 0.0f).normalize3()); gc_gl1.set_light(0, light_distant); cl1Enable(GL_NORMALIZE); #endif #ifdef USE_OPENGL_2 Shader shader(gc); #endif // Create the objects aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,89.53f); const struct aiScene* scene_teapot = aiImportFile("../Clan3D/Resources/teapot.dae",aiProcessPreset_TargetRealtime_MaxQuality); if (!scene_teapot) throw CL_Exception("Cannot load the teapot model"); const struct aiScene* scene_clanlib = aiImportFile("../Clan3D/Resources/clanlib.dae",aiProcessPreset_TargetRealtime_MaxQuality); if (!scene_clanlib) throw CL_Exception("Cannot load the clanlib model"); const struct aiScene* scene_tuxball = aiImportFile("../Clan3D/Resources/tux_ball.dae",aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_FlipUVs); if (!scene_tuxball) throw CL_Exception("Cannot load the tux ball model"); // Load the texture CL_Texture tux(gc, "../Clan3D/Resources/tux.png"); float angle = 0.0f; // Run until someone presses escape while (!quit) { CL_Mat4f perp = CL_Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 1000.0f); gc.set_projection(perp); gc.clear(CL_Colorf::black); gc.clear_depth(1.0f); angle += 1.0f; if (angle >= 360.0f) angle -= 360.0f; #ifdef USE_OPENGL_2 shader.Set(gc); shader.Use(gc); #else gc.set_program_object(cl_program_color_only); #endif CL_PrimitivesArray prim_array(gc); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.0f, 0.0f, 2.0f); gc.mult_rotate(CL_Angle(angle, cl_degrees), 0.0f, 1.0f, 0.0f, false); gc.push_modelview(); recursive_render(gc, scene_teapot, scene_teapot->mRootNode, false); gc.pop_modelview(); gc.push_modelview(); gc.mult_scale(0.5f, 0.5f, 0.5f); gc.mult_translate(0.0f, -0.5f, 0.0f); recursive_render(gc, scene_clanlib, scene_clanlib->mRootNode, false); gc.pop_modelview(); #ifdef USE_OPENGL_2 shader.Set(gc, 0); shader.Use(gc); #else gc.set_program_object(cl_program_single_texture); #endif gc.set_texture(0, tux); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.7f, 0.5f, 2.0f); gc.mult_scale(0.05f, 0.05f, 0.05f); gc.mult_rotate(CL_Angle(angle * 4.0f, cl_degrees), 0.0f, 1.0f, 0.0f, false); recursive_render(gc, scene_tuxball, scene_tuxball->mRootNode, true); gc.reset_texture(0); gc.reset_program_object(); // Flip the display, showing on the screen what we have drawed // since last call to flip() window.flip(1); // This call processes user input and other events CL_KeepAlive::process(); } aiReleaseImport(scene_tuxball); aiReleaseImport(scene_clanlib); aiReleaseImport(scene_teapot); aiDetachAllLogStreams(); return 0; }
// The start of the Application int App::start(const std::vector<std::string> &args) { clan::DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("PixelBuffer Example"); win_desc.set_size(clan::Size( 600, 630 ), false); clan::DisplayWindow window(win_desc); clan::Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); clan::Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); clan::Canvas canvas(window); clan::PixelBuffer tux("../../3D/Object3D/Resources/tux.png"); clan::PixelBuffer cpu_buffer = tux.copy(); const int num_gpu_buffers = 2; clan::TransferTexture gpu_buffer[num_gpu_buffers]; for (int cnt=0; cnt < num_gpu_buffers; cnt++) { // Note - This example only uses PIXEL_UNPACK_BUFFER_ARB, it does not use PIXEL_PACK_BUFFER_ARB gpu_buffer[cnt] = clan::TransferTexture(canvas, tux); } const int num_textures = 2; clan::Texture2D textures[num_textures]; for (int cnt=0; cnt < num_textures; cnt++) { textures[cnt] = clan::Texture2D(canvas, tux.get_width(), tux.get_height(), clan::tf_rgba8); } clan::Font font(canvas, "Tahoma", 24); clan::GameTime game_time; int gpu_buffer_cycle = 0; int texture_cycle = 0; cpu_active = true; while (!quit) { game_time.update(); canvas.clear(clan::Colorf(0.0f,0.0f,0.2f)); // Modify the pixel buffer read_write_pixel_buffer(canvas, tux); // Control the texture buffering int texture_cycle_first = texture_cycle; int texture_cycle_second = texture_cycle + 1; if (texture_cycle_second >= num_textures) texture_cycle_second -= num_textures; // Control the gpu buffering int gpu_buffer_cycle_first = gpu_buffer_cycle; int gpu_buffer_cycle_second = gpu_buffer_cycle + 1; if (gpu_buffer_cycle_second >= num_gpu_buffers) gpu_buffer_cycle_second -= num_gpu_buffers; // Always draw the same text, to ensure matching speed calculation if (cpu_active) { font.draw_text(canvas, 8, 24, "GPU Transfer Texture Object", clan::Colorf(0.0f, 0.0f, 0.2f, 1.0f)); font.draw_text(canvas, 8, 24, "CPU Pixel Buffer", clan::Colorf(1.0f, 1.0f, 1.0f, 1.0f)); draw_cpu(canvas, cpu_buffer, tux, textures[texture_cycle_first], textures[texture_cycle_second]); } else { font.draw_text(canvas, 8, 24, "CPU Pixel Buffer", clan::Colorf(0.0f, 0.0f, 0.2f, 1.0f)); font.draw_text(canvas, 8, 24, "GPU Transfer Texture Object", clan::Colorf(1.0f, 1.0f, 1.0f, 1.0f)); draw_gpu(canvas, gpu_buffer[gpu_buffer_cycle_first], gpu_buffer[gpu_buffer_cycle_second], tux, textures[texture_cycle_first], textures[texture_cycle_second]); } font.draw_text(canvas, 8, canvas.get_height() - 16, "Press any key to toggle method"); texture_cycle = texture_cycle_second; gpu_buffer_cycle = gpu_buffer_cycle_second; std::string fps(clan::string_format("%1 fps", clan::StringHelp::float_to_text(game_time.get_updates_per_second(), 1))); font.draw_text(canvas, canvas.get_width() - 100, canvas.get_height()-16, fps, clan::Colorf(1.0f, 1.0f, 1.0f, 1.0f)); // Use flip(1) to lock the fps window.flip(0); clan::KeepAlive::process(0); } return 0; }