qinyunti 发表于 2024-7-20 13:28

【超小型 Linux 开发套件Quantum Tiny Linux】移植tinygl实现3D显示

<div class='showpostmsg'> 本帖最后由 qinyunti 于 2024-7-20 13:39 编辑

<p>源码如下</p>

<p>&nbsp;</p>

<div></div>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>视频</p>

<p>e59e016f76e0ea72b0458e724f19f86f<br />
&nbsp;</p>

<p>b站视频</p>

<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1aE8ue2EHE&amp;page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
&nbsp;</p>

<p>微信公众号视频</p>

<p><a href="https://mp.weixin.qq.com/s/l_d1UUTtCxGflp7SXGLIXw">移植tinygl实现3D显示-基于Quantum开发板 (qq.com)</a><br />
<a href="https://mp.weixin.qq.com/s/l_d1UUTtCxGflp7SXGLIXw" target="_blank">视频号</a></p>

<ul>
        <li><b>前言</b></li>
</ul>

<p>前面我们基于fb实现了ftf操作接口,现在开始就可以移植各种GUI了,</p>

<p>我们前面实现了mpu6050的角度获取,后面就可以实现角度的3D显示。</p>

<p>这一篇我们先来移植tinygl为3D显示做准备。</p>

<p>&nbsp;</p>

<p>Tinygl项目网站见<a href="https://bellard.org/TinyGL/" target="_blank">https://bellard.org/TinyGL/</a></p>

<p>&nbsp;</p>

<p>Tinygl是OpenGL的一个嵌入式实现子集</p>

<p>&nbsp;</p>

<p>下载代码</p>

<p>git clone <a href="https://github.com/jserv/tinygl" target="_blank">https://github.com/jserv/tinygl</a></p>

<p>&nbsp;</p>

<p>或者直接下载打包源码</p>

<p><a href="https://bellard.org/TinyGL/TinyGL-0.4.1.tar.gz"><u>https://bellard.org/TinyGL/TinyGL-0.4.1.tar.gz</u></a></p>

<p>&nbsp;</p>

<p>将TinyGL-0.4.1.tar.gz导入到开发板</p>

<p>&nbsp;</p>

<p>解压</p>

<p>tar -xvf TinyGL-0.4.1.tar.gz</p>

<p>&nbsp;</p>

<p>cd TinyGL</p>

<p>&nbsp;</p>

<p>make</p>

<p> &nbsp;</p>

<p>&nbsp;</p>

<p>可以看到能够编译,</p>

<p>但是默认需要x X display,所以我们需要移植到我们的tft显示,使用之前的基于fb的lcd接口封装。</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>删除不必要的文件最终目录如下</p>

<p>&nbsp;</p>

<p> &nbsp;</p>

<p>&nbsp;</p>

<p>复制examples下raw下的gears.c样例程序进行修改。</p>

<ul>
        <li><b>接口移植</b></li>
</ul>

<p>Tinygl显示基于buffer,即最终显示内容是写入buffer的</p>

<p>初始化 ZB_open返回帧buffer,frameBuffer</p>

<p>&nbsp; &nbsp; // initialize TinyGL</p>

<p>&nbsp; &nbsp; ZBuffer&nbsp;*frameBuffer&nbsp;= ZB_open(winSizeX, winSizeY,</p>

<p>#if&nbsp;TGL_FEATURE_RENDER_BITS ==&nbsp;32</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ZB_MODE_RGBA,</p>

<p>#else</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ZB_MODE_5R6G5B,</p>

<p>#endif</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);</p>

<p>&nbsp; &nbsp; if&nbsp;(!frameBuffer) {</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;\nZB_open failed!&quot;);</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; exit(1);</p>

<p>&nbsp; &nbsp; }</p>

<p>&nbsp; &nbsp; glInit(frameBuffer);</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>需要刷新显示时将帧frameBuffer拷贝出来到imbuf,然后显示imbuf即可</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; ZB_copyFrameBuffer(frameBuffer, imbuf, winSizeX&nbsp;* sizeof(PIXEL));</p>

<p>或者直接修改&nbsp;ZB_copyFrameBuffer</p>

<p>将frameBuffer直接写入用户的显存,无需再经过imbuf中转,减少一次内存拷贝。</p>

<p>&nbsp;</p>

<p>这里在原来lcd.c上增加一个接口</p>

<p>int&nbsp;lcd_fill(uint8_t* buffer)</p>

<p>{</p>

<p>&nbsp; &nbsp; memcpy(s_fbp, buffer, s_vinfo.xres*s_vinfo.yres*s_vinfo.bits_per_pixel&nbsp;/ 8);</p>

<p>}</p>

<p>&nbsp;</p>

<p>如下进行显示</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; ZB_copyFrameBuffer(frameBuffer, imbuf, winSizeX&nbsp;* sizeof(PIXEL));</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; lcd_fill((uint8_t*)imbuf);</p>

<p>&nbsp;</p>

<ul>
        <li><b>配置</b></li>
</ul>

<p>修改显示的位宽,我们这里是16位</p>

<p>\include\zfeatures.h下修改</p>

<p>#define&nbsp;TGL_FEATURE_16_BITS 0</p>

<p>#define&nbsp;TGL_FEATURE_32_BITS 1</p>

<p>&nbsp;</p>

<p>为</p>

<p>#define&nbsp;TGL_FEATURE_16_BITS 0</p>

<p>#define&nbsp;TGL_FEATURE_32_BITS 0</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<ul>
        <li><b>测试</b></li>
</ul>

<p>编译</p>

<p>gcc&nbsp;tinygl/src/*.c&nbsp;gears.c&nbsp;lcd.c&nbsp;-I&nbsp;tinygl/include/&nbsp;-o&nbsp;gears&nbsp;-lm</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>运行</p>

<p>&nbsp;./gears</p>

<p>&nbsp;</p>

<p>测试效果见视频</p>

<p>&nbsp;</p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页: [1]
查看完整版本: 【超小型 Linux 开发套件Quantum Tiny Linux】移植tinygl实现3D显示