<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libtiger: simple.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>simple.c</h1><div class="fragment"><pre class="fragment"><span class="comment">/*</span> <span class="comment"> */</span> <span class="preprocessor">#include <stdio.h></span> <span class="preprocessor">#include <stdlib.h></span> <span class="preprocessor">#include <ogg/ogg.h></span> <span class="preprocessor">#include <kate/kate.h></span> <span class="preprocessor">#include "common.h"</span> <span class="comment">/* All the libtiger API is available from the main tiger header file: */</span> <span class="preprocessor">#include <tiger/tiger.h></span> <span class="preprocessor">#define FPS ((kate_float)25.0)</span> <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">void</span> step_render(tiger_renderer *tr,kate_float *t,kate_float t1) { <span class="keywordflow">for</span> (;*t<=t1;*t+=(kate_float)1.0/FPS) { tiger_renderer_update(tr,*t,1); <span class="keywordflow">if</span> (tiger_renderer_is_dirty(tr)) { tiger_renderer_render(tr); } } } <span class="keywordtype">int</span> main() { ogg_sync_state oy; ogg_stream_state os; <span class="keywordtype">int</span> init=0; ogg_packet op; kate_state k; <span class="keyword">const</span> kate_event *ev; kate_packet kp; <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *image; tiger_renderer *tr; kate_float render_time=(kate_float)0; kate_float end_time=(kate_float)0; set_binary_file(stdin); <span class="comment">/* create a buffer to draw to */</span> image=(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)malloc(640*480*4); <span class="comment">/* we initialize ogg, kate, and tiger */</span> ogg_sync_init(&oy); kate_high_decode_init(&k); tiger_renderer_create(&tr); tiger_renderer_set_buffer(tr,image,640,480,640*4,0); tiger_renderer_set_surface_clear_color(tr,1,0,0,0,0); <span class="comment">/*</span> <span class="comment"> We then read packets and feed them to the libkate high level API. When</span> <span class="comment"> kate_high_decode_packetin returns a positive number, this signals the</span> <span class="comment"> end of the stream.</span> <span class="comment"> */</span> <span class="keywordflow">while</span> (1) { <span class="keywordflow">if</span> (get_packet(&oy,&os,&init,&op)) <span class="keywordflow">break</span>; kate_packet_wrap(&kp,op.bytes,op.packet); <span class="keywordflow">if</span> (kate_high_decode_packetin(&k,&kp,&ev)>0) <span class="keywordflow">break</span>; <span class="comment">/* if the event is non NULL, we have an event */</span> <span class="keywordflow">if</span> (ev) { step_render(tr,&render_time,ev->start_time); <span class="keywordflow">if</span> (ev->end_time>end_time) end_time=ev->end_time; tiger_renderer_add_event(tr,k.ki,ev); } } step_render(tr,&render_time,end_time); <span class="comment">/* That's it, we can now cleanup */</span> tiger_renderer_destroy(tr); free(image); ogg_stream_clear(&os); ogg_sync_clear(&oy); kate_high_decode_clear(&k); <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Sat Dec 25 19:03:59 2010 for libtiger by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>