gale/gale_tutorial.html
2016-10-23 21:18:24 +02:00

169 lines
23 KiB
HTML

<!-- HTML header for doxygen 1.8.8-->
<!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="X-UA-Compatible" content="IE=edge">
<!-- For Mobile Devices -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<title>Gale: Graphic Abstraction Layer for Ewol: Tutorial</title>
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="doxy-boot.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">Gale: Graphic Abstraction Layer for Ewol 0.7.0</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Main&nbsp;Page</a></li>
<li><a href="pages.html">Related&nbsp;Pages</a></li>
<li><a href="namespaces.html">Namespaces</a></li>
<li><a href="annotated.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Link-libs<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
<li><a href="http://atria-soft.github.io/audio-ess">audio-ess</a></li>
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
</ul>
</li>
</ul>
<div id="search-box" class="input-group">
<div class="input-group-btn">
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-search"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Namespaces</a></li>
<li><a href="#">Files</a></li>
<li><a href="#">Functions</a></li>
<li><a href="#">Variables</a></li>
<li><a href="#">Typedefs</a></li>
<li><a href="#">Enumerations</a></li>
<li><a href="#">Enumerator</a></li>
<li><a href="#">Friends</a></li>
<li><a href="#">Macros</a></li>
<li><a href="#">Pages</a></li>
</ul>
</div>
<button id="search-close" type="button" class="close" aria-label="Close">
<span aria-hidden="true"></span>
</button>
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
<div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Tutorial </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#gale_tutorial_declare">Base: </a><ul><li class="level2"><a href="#gale_tutorial_base_main">Application declatration: </a></li>
</ul>
</li>
<li class="level1"><a href="#gale_tutorial_compleate_sample">Compleate Sample: </a></li>
</ul>
</div>
<div class="textblock"><h1><a class="anchor" id="gale_tutorial_declare"></a>
Base: </h1>
<p>To understand some choise, I designe this software to acces on all system (that provide openGL interface). But on some embended interface, we have only openGL-es ==&gt; then I limit all the design on OpenGL-ES (need to think to change this maybe)</p>
<p>All is based on the heritage of the single class: gale::Application.</p>
<p>For your fist application you just need to declare an application and create the smallest main that ever exit:</p>
<h2><a class="anchor" id="gale_tutorial_base_main"></a>
Application declatration: </h2>
<p>We declare the application: </p><div class="fragment"><div class="line"><span class="keyword">class </span>MainApplication : <span class="keyword">public</span> gale::Application {</div><div class="line"> <span class="comment">// application implementation here ...</span></div><div class="line">}</div></div><!-- fragment --><p>We create application on the main() </p><div class="fragment"><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> _argc, <span class="keyword">const</span> <span class="keywordtype">char</span> *_argv[]) {</div><div class="line"> <span class="keywordflow">return</span> gale::run(<span class="keyword">new</span> MainApplication(), _argc, _argv);</div><div class="line">}</div></div><!-- fragment --><p> At this point I need to explain one point on Android:</p>
<p>Android have an internal state engine that can create multiple aplication, then GALE can call a second time the main() if needed...</p>
<p>Then never forget to not use global value and singleton. We provide other mechanism to do it. (for exemple, you can acces at you Application intance everywhere you are).</p>
<h1><a class="anchor" id="gale_tutorial_compleate_sample"></a>
Compleate Sample: </h1>
<div class="fragment"><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/types__8hpp.html">etk/types.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;gale/gale.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;gale/context/commandLine.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;test-debug/debug.hpp&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;gale/Application.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;gale/context/Context.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;gale/resource/Program.hpp&gt;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">class </span>MainApplication : <span class="keyword">public</span> gale::Application {</div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> ememory::SharedPtr&lt;gale::resource::Program&gt; m_GLprogram;</div><div class="line"> int32_t m_GLPosition;</div><div class="line"> int32_t m_GLMatrix;</div><div class="line"> int32_t m_GLColor;</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keywordtype">void</span> onCreate(gale::Context&amp; _context)<span class="keyword"> override </span>{</div><div class="line"> setSize(<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">vec2</a>(800, 600));</div><div class="line"> m_GLprogram = gale::resource::Program::create(<span class="stringliteral">&quot;DATA:basic.prog&quot;</span>);</div><div class="line"> <span class="keywordflow">if</span> (m_GLprogram != <span class="keyword">nullptr</span>) {</div><div class="line"> m_GLPosition = m_GLprogram-&gt;getAttribute(<span class="stringliteral">&quot;EW_coord3d&quot;</span>);</div><div class="line"> m_GLColor = m_GLprogram-&gt;getAttribute(<span class="stringliteral">&quot;EW_color&quot;</span>);</div><div class="line"> m_GLMatrix = m_GLprogram-&gt;getUniform(<span class="stringliteral">&quot;EW_MatrixTransformation&quot;</span>);</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;==&gt; Init APPL (END)&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> onDraw(gale::Context&amp; _context)<span class="keyword"> override </span>{</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">ivec2</a> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/_matrix_8hpp.html#ab35a6d6d9aa161dbe3debb10b27613ef">size</a> = getSize();</div><div class="line"> <span class="comment">// set the basic openGL view port: (position drawed in the windows)</span></div><div class="line"> gale::openGL::setViewPort(<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">ivec2</a>(0,0),size);</div><div class="line"> <span class="comment">// Clear all the stacked matrix ...</span></div><div class="line"> gale::openGL::setBasicMatrix(<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_matrix4.html">mat4</a>());</div><div class="line"> <span class="comment">// clear background</span></div><div class="line"> gale::openGL::clearColor(<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk_1_1color.html#a002d237cb06c35ec373b454af2cbb072">etk::color::yellow</a>);</div><div class="line"> <span class="comment">// real clear request:</span></div><div class="line"> gale::openGL::clear(gale::openGL::clearFlag_colorBuffer);</div><div class="line"> <span class="comment">// create a local matrix environnement.</span></div><div class="line"> gale::openGL::push();</div><div class="line"> </div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_matrix4.html">mat4</a> tmpProjection = <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk.html#aad05fa6714ff5e51a7ed4c0f432f95b2">etk::matOrtho</a>(-1, 1,</div><div class="line"> -1, 1,</div><div class="line"> -2, 2);</div><div class="line"> <span class="comment">// set internal matrix system:</span></div><div class="line"> gale::openGL::setMatrix(tmpProjection);</div><div class="line"> </div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector3_d.html">vec3</a> vertices[3]={ <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector3_d.html">vec3</a>(-0.5,-0.5,0),</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector3_d.html">vec3</a>(0,0.5,0),</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector3_d.html">vec3</a>(0.5,-0.5,0)</div><div class="line"> };</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_color.html">etk::Color&lt;float&gt;</a> color[3] = { <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk_1_1color.html#a365a78d3068cd950ce25fda3f905554e">etk::color::red</a>,</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk_1_1color.html#a6fc96147de6d001202802bca7bcf2ba9">etk::color::green</a>,</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk_1_1color.html#a50f114c6849684e9984ae1322493572c">etk::color::blue</a></div><div class="line"> };</div><div class="line"> <span class="keywordflow">if</span> (m_GLprogram == <span class="keyword">nullptr</span>) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;No shader ...&quot;</span>);</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"> <span class="comment">//EWOL_DEBUG(&quot; display &quot; &lt;&lt; m_coord.size() &lt;&lt; &quot; elements&quot; );</span></div><div class="line"> m_GLprogram-&gt;use();</div><div class="line"> <span class="comment">// set Matrix : translation/positionMatrix</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_matrix4.html">mat4</a> projMatrix = gale::openGL::getMatrix();</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_matrix4.html">mat4</a> camMatrix = gale::openGL::getCameraMatrix();</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_matrix4.html">mat4</a> tmpMatrix = projMatrix * camMatrix;</div><div class="line"> m_GLprogram-&gt;uniformMatrix(m_GLMatrix, tmpMatrix);</div><div class="line"> <span class="comment">// position :</span></div><div class="line"> m_GLprogram-&gt;sendAttribute(m_GLPosition, 3<span class="comment">/*x,y,z,unused*/</span>, vertices, 4*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));</div><div class="line"> <span class="comment">// color :</span></div><div class="line"> m_GLprogram-&gt;sendAttribute(m_GLColor, 4<span class="comment">/*r,g,b,a*/</span>, color, 4*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));</div><div class="line"> <span class="comment">// Request the draw od the elements : </span></div><div class="line"> gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, 3 <span class="comment">/*number of points*/</span>);</div><div class="line"> m_GLprogram-&gt;unUse();</div><div class="line"> <span class="comment">// Restore context of matrix</span></div><div class="line"> gale::openGL::pop();</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> onPointer(<span class="keyword">enum</span> gale::key::type _type,</div><div class="line"> int32_t _pointerID,</div><div class="line"> <span class="keyword">const</span> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">vec2</a>&amp; _pos,</div><div class="line"> gale::key::status _state)<span class="keyword"> override </span>{</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;input event: type=&quot;</span> &lt;&lt; _type);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; id=&quot;</span> &lt;&lt; _pointerID);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; pos=&quot;</span> &lt;&lt; _pos);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; state=&quot;</span> &lt;&lt; _state);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> onKeyboard(<span class="keyword">const</span> gale::key::Special&amp; _special,</div><div class="line"> <span class="keyword">enum</span> gale::key::keyboard _type,</div><div class="line"> char32_t _value,</div><div class="line"> gale::key::status _state)<span class="keyword"> override </span>{</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Keyboard event: special=&quot;</span> &lt;&lt; _special);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; type=&quot;</span> &lt;&lt; _type);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; value=&quot;</span> &lt;&lt; uint32_t(_value));</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; state=&quot;</span> &lt;&lt; _state);</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> _argc, <span class="keyword">const</span> <span class="keywordtype">char</span> *_argv[]) {</div><div class="line"> <span class="keywordflow">return</span> gale::run(<span class="keyword">new</span> MainApplication(), _argc, _argv);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div></div><!-- fragment --></div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Mon Oct 24 2016 14:06:03 for Gale: Graphic Abstraction Layer for Ewol by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>