Created
January 21, 2012 22:54
-
-
Save kayru/1654356 to your computer and use it in GitHub Desktop.
librush sample: embedded font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rush/Rush.h> | |
#include <Rush/Platform.h> | |
#include <Rush/RenderPrimitiveBatch.h> | |
#include <Rush/GraphicsBitmapFont.h> | |
#include <stdio.h> | |
using namespace Rush; | |
RushAppConfig g_appConfig; | |
static PrimitiveBatch* g_prim = NULL; | |
static BitmapFont* g_font = NULL; | |
static BlendStateHandle g_blend_alpha; | |
static void startup(RushPlatformContext* context) | |
{ | |
RenderDevice* dev = RushPlatform_GetRenderDevice(context); | |
g_prim = new PrimitiveBatch(dev); | |
g_font = new BitmapFont(dev, BitmapFont::embedded_font_data()); | |
g_blend_alpha = dev->create_blend_state(BlendStateDescr::make_alphablend()); | |
} | |
static void shutdown(RushPlatformContext* context) | |
{ | |
RenderDevice* dev = RushPlatform_GetRenderDevice(context); | |
dev->destroy_blend_state(g_blend_alpha); | |
delete g_font; | |
delete g_prim; | |
} | |
static void draw(RushPlatformContext* context) | |
{ | |
RenderDevice* dev = RushPlatform_GetRenderDevice(context); | |
RenderContext* rc = RushPlatform_GetRenderContext(context); | |
rc->set_blend_state(g_blend_alpha); | |
dev->clear(ColourRGBA8::Black()); | |
const RushAppConfig* cfg = RushPlatform_GetConfig(context); | |
g_prim->begin_2d(cfg->width, cfg->height); | |
Vector2 pos = Vector2(100,100); | |
pos = g_font->draw_string(g_prim, pos, "Hello world!\n", ColourRGBA8::Red()); | |
pos = g_font->draw_string(g_prim, pos, "This is line 2.", ColourRGBA8::Green()); | |
g_prim->end_2d(); | |
} | |
int main() | |
{ | |
RushAppConfig_Init(&g_appConfig); | |
g_appConfig.on_startup = startup; | |
g_appConfig.on_shutdown = shutdown; | |
g_appConfig.on_draw = draw; | |
g_appConfig.name = "Font"; | |
g_appConfig.width = 800; | |
g_appConfig.height = 600; | |
return RushPlatform_Run(&g_appConfig); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment