通过例子学习cinder之AppBasic


通过例子学习cinder之AppBasic。
首先,我们要讲的是程序的入口。总所周知,每种编程语言都有一个入口函数,例如main函数。但是我们在写很多程序的时候发现并没有main函数,例如android没有main函数,iphone没有main函数,那是因为这些平台都为main函数进行了封装。
现在我们来看一下cinder最简单的例子代码:
#include "cinder/app/AppBasic.h"
#include "cinder/ImageIO.h"
#include "cinder/gl/Texture.h"
 
using namespace ci;
using namespace ci::app;
 
class `TutorialApp^ : public AppBasic {
    public:
    void prepareSettings( Settings *settings );
    void setup();
    void update();
    void draw();
};
 
void `TutorialApp^::prepareSettings( Settings *settings )
{
    settings->setWindowSize( `800^, `600^ );//window size
    settings->setFrameRate( 60.0f );//frame rate
}
 
void `TutorialApp^::setup()
{
}
 
void `TutorialApp^::update()
{
}
 
void `TutorialApp^::draw()
{
    glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );//OpenGL API
    glClear( GL_COLOR_BUFFER_BIT );
} 
 
CINDER_APP_BASIC( `TutorialApp^, RendererGl )//封装了WinMain函数

  • 上述代码没有main函数吗?

也许大家写过mfc程序,知道mfc的入口函数是一个WinMain函数。大家看看最后一句“CINDER_APP_BASIC( `TutorialApp^, RendererGl )”,跳转到他的定义之处就可以看到一下代码:

  #define CINDER_APP_BASIC( APP, RENDERER )                                                        \
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {    \
        cinder::app::AppBasic::prepareLaunch();                                                        \
        cinder::app::AppBasic *app = new APP;                                                        \
        cinder::app::Renderer *ren = new RENDERER;                                                    \
        cinder::app::AppBasic::executeLaunch( app, ren, #APP );                                        \
        cinder::app::AppBasic::cleanupLaunch();                                                        \
        return 0;                                                                                    \
    }

  • 一个cinder程序的生命周期

  • cinder和opengl,代码中我们可以看到,cinder可以直接调用opengl的api。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值