MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / imguiGraphInit

Function imguiGraphInit

demo/d3d11/imguiGraph.cpp:228–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226
227
228bool imguiGraphInit(const char* fontpath, const ImguiGraphDesc* desc)
229{
230 imguiGraphContextInit(desc);
231
232 for (int i = 0; i < CIRCLE_VERTS; ++i)
233 {
234 float a = (float)i / (float)CIRCLE_VERTS * PI * 2;
235 g_circleVerts[i * 2 + 0] = cosf(a);
236 g_circleVerts[i * 2 + 1] = sinf(a);
237 }
238
239 // Load font.
240 FILE* fp = fopen(fontpath, "rb");
241 if (!fp) return false;
242 fseek(fp, 0, SEEK_END);
243 int size = ftell(fp);
244 fseek(fp, 0, SEEK_SET);
245
246 unsigned char* ttfBuffer = (unsigned char*)malloc(size);
247 if (!ttfBuffer)
248 {
249 fclose(fp);
250 return false;
251 }
252
253 size_t len = fread(ttfBuffer, 1, size, fp);
254 (void)len;
255
256 fclose(fp);
257 fp = 0;
258
259 unsigned char* bmap = (unsigned char*)malloc(512 * 512);
260 if (!bmap)
261 {
262 free(ttfBuffer);
263 return false;
264 }
265
266 stbtt_BakeFontBitmap(ttfBuffer, 0, 15.0f, bmap, 512, 512, 32, 96, g_cdata);
267
268 // can free ttf_buffer at this point
269 imguiGraphFontTextureInit(bmap);
270
271 free(ttfBuffer);
272 free(bmap);
273
274 return true;
275}
276
277void imguiGraphUpdate(const ImguiGraphDesc* desc)
278{

Callers 1

InitRenderFunction · 0.85

Calls 3

imguiGraphContextInitFunction · 0.85
stbtt_BakeFontBitmapFunction · 0.85

Tested by

no test coverage detected