Compare commits
196 Commits
Author | SHA1 | Date | |
---|---|---|---|
e8cb874afe | |||
55ab515551 | |||
1266e4a181 | |||
f7f71043ca | |||
98047b1b65 | |||
f53d5da0f8 | |||
d6117e33d0 | |||
bc4ede656b | |||
b7d1b91e4b | |||
be8fb858cc | |||
b4ac413868 | |||
02a0967243 | |||
3ff04c95d5 | |||
52dd99915b | |||
0f25885b3d | |||
9d4d7f3381 | |||
298118fccc | |||
d19d8f40ba | |||
d170620816 | |||
4842ac3bc6 | |||
5e846612d3 | |||
80276ef07b | |||
6c3ab6fc9b | |||
a56768463a | |||
d750df9189 | |||
baa2328b99 | |||
d7a2a23457 | |||
8081e81e55 | |||
1a3ef63132 | |||
368d2c3568 | |||
0224d29a35 | |||
035ff302d2 | |||
95f489ac1f | |||
3e3d9f9a69 | |||
7ad4843f57 | |||
99a92ee7c5 | |||
8952b93b2f | |||
fcec337061 | |||
815168c7ef | |||
6ae8062ca0 | |||
c02f9b58ef | |||
fc6545830b | |||
faec745438 | |||
8cfd963fda | |||
355cbf6326 | |||
52c820e7b0 | |||
ba9317b924 | |||
5b053dd350 | |||
7eca4e2a7f | |||
fbb9113118 | |||
4565bf9813 | |||
6520b6c458 | |||
7a0004eb86 | |||
d10d0343b2 | |||
e681937f66 | |||
fd44b9440b | |||
b67593a4b1 | |||
8094aa78d2 | |||
827ff970cd | |||
d2701727b9 | |||
f2bed00d80 | |||
5ab23ab1c0 | |||
398ef1a212 | |||
245cf36522 | |||
890585cde8 | |||
08b1dd1035 | |||
fec09e37ab | |||
7d45c84f21 | |||
f4aae6b9ec | |||
09e8c4ec11 | |||
d81ba432ec | |||
2f574ef952 | |||
60dd221737 | |||
d041ebc6d4 | |||
b7e63c163c | |||
b36ff2fec3 | |||
12aba576fb | |||
81cebb9c85 | |||
e3b9a61883 | |||
ca042134ae | |||
1cd391146d | |||
67d93156df | |||
54c2665032 | |||
439040bb25 | |||
d03b046ef4 | |||
d35c1a9e66 | |||
ac56e4e209 | |||
af7f35d7c2 | |||
87ebe95fd6 | |||
3e4841765d | |||
acf58c6223 | |||
bfa7d86070 | |||
c3ced1bd71 | |||
25882c47a3 | |||
4d42760c0b | |||
de6dfe8c5d | |||
92b61d2ee4 | |||
6a22835f63 | |||
e7e2fcdd19 | |||
a17e47fe14 | |||
5782c69c2a | |||
9db4b35168 | |||
0ff2a6ff64 | |||
c52cefa2c2 | |||
0d5e6e125c | |||
0676efd37f | |||
b2b616be00 | |||
f3303fa84f | |||
2633325b9f | |||
8b4a470e1d | |||
56553f33b8 | |||
19e59421e5 | |||
46c440d186 | |||
c09af38804 | |||
a74ca9025f | |||
a8b5f77591 | |||
0292c82b9c | |||
2f21347803 | |||
7959fbe992 | |||
f04c2002d6 | |||
0d7ca3da24 | |||
61e551e0ee | |||
3b94c37efc | |||
f435e42561 | |||
b69d7d9df3 | |||
90ec28f6de | |||
067b7d909a | |||
d3c0bfefb3 | |||
b30d08d63a | |||
c71b183965 | |||
1318e1b74c | |||
4bb94a9e4d | |||
a8f0eb5ec6 | |||
bbdf36cd3a | |||
c3040dee35 | |||
077285ae57 | |||
aaefe458df | |||
ebfe4637d4 | |||
d57ee2458c | |||
5bf30bd6c4 | |||
71e9f2a3dd | |||
43dcd6ef47 | |||
0bf90770b0 | |||
0b98d3eb26 | |||
01cb0dc7f7 | |||
b360c83e92 | |||
7d860a0181 | |||
a76eea85c8 | |||
ade7661b3f | |||
e3f2ad728a | |||
cc3ed515ca | |||
e9b6e437eb | |||
1eafe86627 | |||
f00662a5ad | |||
08fd6a7e7d | |||
94c4e9564d | |||
86d1abf3f6 | |||
4f1acf0d4a | |||
1847270a5f | |||
43cb4038c6 | |||
0bb89ccee2 | |||
88725be381 | |||
bff9a6b6e3 | |||
c3a71f5472 | |||
dbc9b2ec9b | |||
6bdb8719e2 | |||
e0cd947904 | |||
1e69175403 | |||
431e391ccd | |||
14ddb81f7a | |||
39445cf23a | |||
7ab49f80ca | |||
1746b04065 | |||
13fab08cdb | |||
323ae8326e | |||
6ba7a74191 | |||
bb385fabd4 | |||
26991bb2ec | |||
ff1040a38d | |||
d77082af00 | |||
282532a92a | |||
138e292c4b | |||
2a04c2a7bb | |||
ea720963cf | |||
378eee490b | |||
8dd3f854fe | |||
470a8499fe | |||
af1f41dc6a | |||
f5c2f8c60d | |||
cf1554ebb5 | |||
2b032004a9 | |||
d69df3065f | |||
8ca3dc8e41 | |||
fdc8c0722f | |||
91684a428b | |||
d9757bb583 |
25
README.md
@ -22,7 +22,7 @@ ImGui is self-contained within 6 files that you can easily copy and compile into
|
||||
|
||||
Your code passes mouse/keyboard inputs and settings to ImGui (see example applications for more details). After ImGui is setup, you can use it like in this example:
|
||||
|
||||

|
||||

|
||||
|
||||
ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase.
|
||||
|
||||
@ -32,23 +32,20 @@ Demo
|
||||
----
|
||||
|
||||
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download binaries of the demo app here.
|
||||
- [imgui-demo-binaries-20150531.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150531.zip) (Windows binaries, ImGui 1.40 WIP 2015/05/31, 4 executables, 432 KB)
|
||||
- [imgui-demo-binaries-20150716.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150716.zip) (Windows binaries, ImGui 1.43 WIP 2015/07/16, 4 executables, 475 KB)
|
||||
|
||||
|
||||
Gallery
|
||||
-------
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
ImGui can load TTF fonts. UTF-8 is supported for text display and input. Here using Arial Unicode font to display Japanese. Initialize custom font with:
|
||||
```
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
@ -58,7 +55,7 @@ For Microsoft IME, pass your HWND to enable IME positioning:
|
||||
```
|
||||
io.ImeWindowHandle = my_hwnd;
|
||||
```
|
||||

|
||||

|
||||
|
||||
References
|
||||
----------
|
||||
@ -98,7 +95,7 @@ Down to the fundation of its visual design, ImGui is engineered to be fairly per
|
||||
|
||||
Mileage may vary but the following screenshot can give you a rough idea of the cost of running and rendering UI code (In the case of a trivial demo application like this one, your driver/os setup are likely to be the bottleneck. Testing performance as part of a real application is recommended).
|
||||
|
||||

|
||||

|
||||
|
||||
This is showing framerate for the full application loop on my 2011 iMac running Windows 7, OpenGL, AMD Radeon HD 6700M with an optimized executable. In contrast, librairies featuring higher-quality rendering and layouting techniques may have a higher resources footprint.
|
||||
|
||||
@ -140,7 +137,7 @@ Special supporters:
|
||||
- Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Stefano Cristiano.
|
||||
|
||||
And:
|
||||
- Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly.
|
||||
- Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly, Neil Blakey-Milner, Aleksei.
|
||||
|
||||
And other supporters; thanks!
|
||||
|
||||
|
@ -1,17 +1,35 @@
|
||||
Those are standalone ready-to-build applications to demonstrate ImGui.
|
||||
Unfortunately in 2015 it is still a massive pain to create and maintain portable build files.
|
||||
I choose to provide Visual Studio 10 .sln files and Makefile for Linux/OSX.
|
||||
Binaries of those demos are available from the main GitHub page.
|
||||
|
||||
TL;DR;
|
||||
Refer to 'opengl_example' (not 'opengl3_example') to understand how the library is setup.
|
||||
Copy the imgui_impl_xxx.cpp/.h file you need if you are using one of the rendering backend used in an example.
|
||||
If you are using a different or your own backend, copy opengl_example/imgui_impl_opengl.cpp/.h to get started.
|
||||
|
||||
|
||||
ImGui is highly portable and only requires a few things to run:
|
||||
- Providing mouse/keyboard inputs
|
||||
- Load the font atlas texture into GPU memory
|
||||
- Providing a render function to process the drawing commands (we rendere indexed textured triangles)
|
||||
- Extra just as clipboard support, mouse cursor supports, Windows IME support.
|
||||
So this is essentially what those examples are doing + the obligatory cruft for portability.
|
||||
|
||||
Unfortunately in 2015 it is still a massive pain to create and maintain portable build files using
|
||||
external library like the ones we're using here.
|
||||
For most example here I choose to provide Visual Studio 10 .sln files and Makefile for Linux/OSX.
|
||||
Please let me know if they don't work with your setup!
|
||||
You can probably just import the .cpp files into your own system and figure out the linkage from there.
|
||||
You can probably just import the imgui_impl_xxx.cpp/.h files into your own codebase or compile those
|
||||
directly with a command-line compiler.
|
||||
|
||||
opengl_example/
|
||||
OpenGL example, using GLFW + fixed pipeline.
|
||||
This is simple and should work for all OpenGL enabled applications.
|
||||
Prefer following this example to learn how ImGui works, because it is the simplest shortest one!
|
||||
Prefer following this example to learn how ImGui works!
|
||||
|
||||
opengl3_example/
|
||||
OpenGL example, using GLFW/GL3W + programmable pipeline.
|
||||
This uses more modern calls and custom shaders.
|
||||
This uses more modern OpenGL calls and custom shaders.
|
||||
Even if your application is using modern OpenGL you are better off copying the code from the fixed pipeline version!
|
||||
I don't think there is an advantage using this over the simpler example, but it is provided for reference.
|
||||
|
||||
directx9_example/
|
||||
@ -22,11 +40,11 @@ directx11_example/
|
||||
This is quite long and tedious, because: DirectX11.
|
||||
|
||||
ios_example/
|
||||
iOS example.
|
||||
Using Synergy to access keyboard/mouse data from server computer. Synergy keyboard integration is rather hacky.
|
||||
iOS example.
|
||||
Using Synergy to access keyboard/mouse data from server computer. Synergy keyboard integration is rather hacky.
|
||||
|
||||
sdl_opengl_example/
|
||||
SDL2 + OpenGL example.
|
||||
SDL2 + OpenGL example.
|
||||
|
||||
allegro5_example/
|
||||
Allegro 5 example.
|
||||
Allegro 5 example.
|
||||
|
@ -14,5 +14,3 @@ g++ -I ../imgui main.cpp imgui_impl_a5.cpp ../imgui/imgui.cpp -lallegro -lallegr
|
||||
```
|
||||
cl /MD /I <a5path\include> /I ..\imgui main.cpp imgui_impl_a5.cpp ..\imgui\imgui.cpp /link /LIBPATH:<a5path\lib> allegro-5.0.10-monolith-md.lib user32.lib
|
||||
```
|
||||
|
||||
public domain
|
||||
|
@ -1,6 +1,6 @@
|
||||
// ImGui Allegro 5 bindings
|
||||
// https://github.com/ocornut/imgui
|
||||
// by @birthggd, public domain
|
||||
// by @birthggd
|
||||
|
||||
#include <stdint.h> // uint64_t
|
||||
#include <cstring> // memcpy
|
||||
@ -29,22 +29,22 @@ struct ImDrawVertAllegro
|
||||
ALLEGRO_COLOR col;
|
||||
};
|
||||
|
||||
static void ImGui_ImplA5_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
int op, src, dst;
|
||||
al_get_blender(&op, &src, &dst);
|
||||
al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
|
||||
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
|
||||
// FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats
|
||||
static ImVector<ImDrawVertAllegro> vertices;
|
||||
vertices.resize(cmd_list->vtx_buffer.size());
|
||||
for (int i = 0; i < cmd_list->vtx_buffer.size(); ++i)
|
||||
vertices.resize(cmd_list->VtxBuffer.size());
|
||||
for (int i = 0; i < cmd_list->VtxBuffer.size(); ++i)
|
||||
{
|
||||
const ImDrawVert &dv = cmd_list->vtx_buffer[i];
|
||||
const ImDrawVert &dv = cmd_list->VtxBuffer[i];
|
||||
ImDrawVertAllegro v;
|
||||
v.pos = dv.pos;
|
||||
v.uv = dv.uv;
|
||||
@ -53,21 +53,27 @@ static void ImGui_ImplA5_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_l
|
||||
vertices[i] = v;
|
||||
}
|
||||
|
||||
int vtx_offset = 0;
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
|
||||
// FIXME-OPT: Unfortunately Allegro doesn't support 16-bit vertices
|
||||
static ImVector<int> indices;
|
||||
indices.resize(cmd_list->IdxBuffer.size());
|
||||
for (int i = 0; i < cmd_list->IdxBuffer.size(); ++i)
|
||||
indices[i] = (int)cmd_list->IdxBuffer.Data[i];
|
||||
|
||||
int idx_offset = 0;
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||
if (pcmd->user_callback)
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->texture_id;
|
||||
al_set_clipping_rectangle(pcmd->clip_rect.x, pcmd->clip_rect.y, pcmd->clip_rect.z-pcmd->clip_rect.x, pcmd->clip_rect.w-pcmd->clip_rect.y);
|
||||
al_draw_prim(&vertices[0], g_VertexDecl, texture, vtx_offset, vtx_offset+pcmd->vtx_count, ALLEGRO_PRIM_TRIANGLE_LIST);
|
||||
ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId;
|
||||
al_set_clipping_rectangle(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z-pcmd->ClipRect.x, pcmd->ClipRect.w-pcmd->ClipRect.y);
|
||||
al_draw_indexed_prim(&vertices[0], g_VertexDecl, texture, &indices[idx_offset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_offset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// ImGui Allegro 5 bindings
|
||||
// https://github.com/ocornut/imgui
|
||||
// by @birthggd, public domain
|
||||
// by @birthggd
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
// ImGui - standalone example application for Allegro 5
|
||||
// public domain
|
||||
|
||||
#include <stdint.h>
|
||||
#include <allegro5/allegro.h>
|
||||
@ -24,13 +23,22 @@ int main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplA5_Init(display);
|
||||
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
|
@ -18,6 +18,7 @@ static HWND g_hWnd = 0;
|
||||
static ID3D11Device* g_pd3dDevice = NULL;
|
||||
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
|
||||
static ID3D11Buffer* g_pVB = NULL;
|
||||
static ID3D11Buffer* g_pIB = NULL;
|
||||
static ID3D10Blob * g_pVertexShaderBlob = NULL;
|
||||
static ID3D11VertexShader* g_pVertexShader = NULL;
|
||||
static ID3D11InputLayout* g_pInputLayout = NULL;
|
||||
@ -28,7 +29,8 @@ static ID3D11SamplerState* g_pFontSampler = NULL;
|
||||
static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
|
||||
static ID3D11RasterizerState* g_pRasterizerState = NULL;
|
||||
static ID3D11BlendState* g_pBlendState = NULL;
|
||||
static int VERTEX_BUFFER_SIZE = 30000; // TODO: Make vertex buffer smaller and grow dynamically as needed.
|
||||
static int VERTEX_BUFFER_SIZE = 20000; // TODO: Make buffers smaller and grow dynamically as needed.
|
||||
static int INDEX_BUFFER_SIZE = 40000; // TODO: Make buffers smaller and grow dynamically as needed.
|
||||
|
||||
struct VERTEX_CONSTANT_BUFFER
|
||||
{
|
||||
@ -38,20 +40,26 @@ struct VERTEX_CONSTANT_BUFFER
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
// Copy and convert all vertices into a single contiguous buffer
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
|
||||
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
|
||||
if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
|
||||
return;
|
||||
ImDrawVert* vtx_dst = (ImDrawVert*)mappedResource.pData;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
if (g_pd3dDeviceContext->Map(g_pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK)
|
||||
return;
|
||||
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData;
|
||||
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData;
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
memcpy(vtx_dst, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
|
||||
vtx_dst += cmd_list->vtx_buffer.size();
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
memcpy(vtx_dst, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert));
|
||||
memcpy(idx_dst, &cmd_list->IdxBuffer[0], cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx));
|
||||
vtx_dst += cmd_list->VtxBuffer.size();
|
||||
idx_dst += cmd_list->IdxBuffer.size();
|
||||
}
|
||||
g_pd3dDeviceContext->Unmap(g_pVB, 0);
|
||||
g_pd3dDeviceContext->Unmap(g_pIB, 0);
|
||||
|
||||
// Setup orthographic projection matrix into our constant buffer
|
||||
{
|
||||
@ -93,6 +101,7 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd
|
||||
unsigned int offset = 0;
|
||||
g_pd3dDeviceContext->IASetInputLayout(g_pInputLayout);
|
||||
g_pd3dDeviceContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
|
||||
g_pd3dDeviceContext->IASetIndexBuffer(g_pIB, DXGI_FORMAT_R16_UINT, 0);
|
||||
g_pd3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
g_pd3dDeviceContext->VSSetShader(g_pVertexShader, NULL, 0);
|
||||
g_pd3dDeviceContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
|
||||
@ -106,25 +115,27 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd
|
||||
|
||||
// Render command lists
|
||||
int vtx_offset = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
int idx_offset = 0;
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||
if (pcmd->user_callback)
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
|
||||
g_pd3dDeviceContext->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->texture_id);
|
||||
const D3D11_RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w };
|
||||
g_pd3dDeviceContext->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->TextureId);
|
||||
g_pd3dDeviceContext->RSSetScissorRects(1, &r);
|
||||
g_pd3dDeviceContext->Draw(pcmd->vtx_count, vtx_offset);
|
||||
g_pd3dDeviceContext->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_offset += pcmd->ElemCount;
|
||||
}
|
||||
vtx_offset += cmd_list->VtxBuffer.size();
|
||||
}
|
||||
|
||||
// Restore modified state
|
||||
@ -368,6 +379,18 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the index buffer
|
||||
{
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
|
||||
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bufferDesc.ByteWidth = INDEX_BUFFER_SIZE * sizeof(ImDrawIdx);
|
||||
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
ImGui_ImplDX11_CreateFontsTexture();
|
||||
|
||||
return true;
|
||||
@ -380,6 +403,7 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
|
||||
|
||||
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
||||
if (g_pFontTextureView) { g_pFontTextureView->Release(); ImGui::GetIO().Fonts->TexID = 0; }
|
||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||
|
||||
if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; }
|
||||
|
@ -149,13 +149,22 @@ int main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
|
||||
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
|
@ -15,7 +15,9 @@ static INT64 g_Time = 0;
|
||||
static INT64 g_TicksPerSecond = 0;
|
||||
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
||||
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
|
||||
static int VERTEX_BUFFER_SIZE = 30000; // TODO: Make vertex buffer smaller and grow dynamically as needed.
|
||||
static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL;
|
||||
static int VERTEX_BUFFER_SIZE = 20000; // TODO: Make buffers smaller and grow dynamically as needed.
|
||||
static int INDEX_BUFFER_SIZE = 40000; // TODO: Make buffers smaller and grow dynamically as needed.
|
||||
|
||||
struct CUSTOMVERTEX
|
||||
{
|
||||
@ -28,23 +30,20 @@ struct CUSTOMVERTEX
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
static void ImGui_ImplDX9_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
int total_vtx_count = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
|
||||
if (total_vtx_count == 0)
|
||||
return;
|
||||
|
||||
// Copy and convert all vertices into a single contiguous buffer
|
||||
CUSTOMVERTEX* vtx_dst;
|
||||
if (g_pVB->Lock(0, (UINT)total_vtx_count, (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
|
||||
ImDrawIdx* idx_dst;
|
||||
if (g_pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
|
||||
return;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
if (g_pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0)
|
||||
return;
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
|
||||
for (int i = 0; i < cmd_list->vtx_buffer.size(); i++)
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const ImDrawVert* vtx_src = &cmd_list->VtxBuffer[0];
|
||||
for (int i = 0; i < cmd_list->VtxBuffer.size(); i++)
|
||||
{
|
||||
vtx_dst->pos.x = vtx_src->pos.x;
|
||||
vtx_dst->pos.y = vtx_src->pos.y;
|
||||
@ -55,9 +54,13 @@ static void ImGui_ImplDX9_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_
|
||||
vtx_dst++;
|
||||
vtx_src++;
|
||||
}
|
||||
memcpy(idx_dst, &cmd_list->IdxBuffer[0], cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx));
|
||||
idx_dst += cmd_list->IdxBuffer.size();
|
||||
}
|
||||
g_pVB->Unlock();
|
||||
g_pIB->Unlock();
|
||||
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
|
||||
g_pd3dDevice->SetIndices( g_pIB );
|
||||
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
|
||||
|
||||
// Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing
|
||||
@ -90,25 +93,27 @@ static void ImGui_ImplDX9_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_
|
||||
|
||||
// Render command lists
|
||||
int vtx_offset = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
int idx_offset = 0;
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||
if (pcmd->user_callback)
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
|
||||
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->texture_id );
|
||||
const RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w };
|
||||
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->TextureId );
|
||||
g_pd3dDevice->SetScissorRect(&r);
|
||||
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3);
|
||||
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.size(), idx_offset, pcmd->ElemCount/3);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_offset += pcmd->ElemCount;
|
||||
}
|
||||
vtx_offset += cmd_list->VtxBuffer.size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,6 +245,9 @@ bool ImGui_ImplDX9_CreateDeviceObjects()
|
||||
if (g_pd3dDevice->CreateVertexBuffer(VERTEX_BUFFER_SIZE * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
|
||||
return false;
|
||||
|
||||
if (g_pd3dDevice->CreateIndexBuffer(INDEX_BUFFER_SIZE * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0)
|
||||
return false;
|
||||
|
||||
ImGui_ImplDX9_CreateFontsTexture();
|
||||
return true;
|
||||
}
|
||||
@ -253,6 +261,11 @@ void ImGui_ImplDX9_InvalidateDeviceObjects()
|
||||
g_pVB->Release();
|
||||
g_pVB = NULL;
|
||||
}
|
||||
if (g_pIB)
|
||||
{
|
||||
g_pIB->Release();
|
||||
g_pIB = NULL;
|
||||
}
|
||||
if (LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)ImGui::GetIO().Fonts->TexID)
|
||||
{
|
||||
tex->Release();
|
||||
|
@ -73,16 +73,22 @@ int main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplDX9_Init(hwnd, g_pd3dDevice);
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
ShowWindow(hwnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(hwnd);
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
@ -91,6 +97,8 @@ int main(int, char**)
|
||||
// Main loop
|
||||
MSG msg;
|
||||
ZeroMemory(&msg, sizeof(msg));
|
||||
ShowWindow(hwnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(hwnd);
|
||||
while (msg.message != WM_QUIT)
|
||||
{
|
||||
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||
|
@ -157,7 +157,7 @@ static bool g_synergyPtrActive = false;
|
||||
static uint16_t g_mousePosX = 0;
|
||||
static uint16_t g_mousePosY = 0;
|
||||
|
||||
static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd_lists_count);
|
||||
static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data);
|
||||
bool ImGui_ImplIOS_CreateDeviceObjects();
|
||||
|
||||
static NSString *g_serverName;
|
||||
@ -611,11 +611,8 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
// NOTE: this is copied pretty much entirely from the opengl3_example, with only minor changes for ES
|
||||
static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data)
|
||||
{
|
||||
if (cmd_lists_count == 0)
|
||||
return;
|
||||
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
||||
GLint last_program, last_texture;
|
||||
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||
@ -642,61 +639,50 @@ static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd
|
||||
glUseProgram(g_ShaderHandle);
|
||||
glUniform1i(g_AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
|
||||
// Grow our buffer according to what we need
|
||||
size_t total_vtx_count = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
size_t needed_vtx_size = total_vtx_count * sizeof(ImDrawVert);
|
||||
if (g_VboSize < needed_vtx_size)
|
||||
{
|
||||
g_VboSize = needed_vtx_size + 5000 * sizeof(ImDrawVert); // Grow buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, g_VboSize, NULL, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
// Copy and convert all vertices into a single contiguous buffer
|
||||
unsigned char* buffer_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, g_VboSize, GL_MAP_WRITE_BIT);
|
||||
if (!buffer_data)
|
||||
return;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
|
||||
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(g_VaoHandle);
|
||||
|
||||
int cmd_offset = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
int vtx_offset = cmd_offset;
|
||||
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||
ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
int needed_vtx_size = cmd_list->VtxBuffer.size() * sizeof(ImDrawVert);
|
||||
if (g_VboSize < needed_vtx_size)
|
||||
{
|
||||
if (pcmd->user_callback)
|
||||
// Grow our buffer if needed
|
||||
g_VboSize = needed_vtx_size + 2000 * sizeof(ImDrawVert);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
unsigned char* vtx_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, needed_vtx_size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
|
||||
if (!vtx_data)
|
||||
continue;
|
||||
memcpy(vtx_data, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert));
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
|
||||
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
|
||||
{
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
|
||||
glScissor((int)(pcmd->clip_rect.x * g_displayScale),
|
||||
(int)((height - pcmd->clip_rect.w) * g_displayScale),
|
||||
(int)((pcmd->clip_rect.z - pcmd->clip_rect.x) * g_displayScale),
|
||||
(int)((pcmd->clip_rect.w - pcmd->clip_rect.y) * g_displayScale));
|
||||
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glScissor((int)(pcmd->ClipRect.x * g_displayScale),
|
||||
(int)((height - pcmd->ClipRect.w) * g_displayScale),
|
||||
(int)((pcmd->ClipRect.z - pcmd->ClipRect.x) * g_displayScale),
|
||||
(int)((pcmd->ClipRect.w - pcmd->ClipRect.y) * g_displayScale));
|
||||
glDrawElements( GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer );
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_buffer += pcmd->ElemCount;
|
||||
}
|
||||
cmd_offset = vtx_offset;
|
||||
}
|
||||
|
||||
// Restore modified state
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer( GL_ARRAY_BUFFER, 0);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glUseProgram(last_program);
|
||||
|
@ -29,7 +29,7 @@ static unsigned int g_VboHandle = 0, g_VaoHandle = 0;
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
||||
GLint last_program, last_texture;
|
||||
@ -56,58 +56,47 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawList** const cmd_lists, int
|
||||
glUseProgram(g_ShaderHandle);
|
||||
glUniform1i(g_AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
|
||||
// Grow our buffer according to what we need
|
||||
int total_vtx_count = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
int needed_vtx_size = total_vtx_count * sizeof(ImDrawVert);
|
||||
if (g_VboSize < needed_vtx_size)
|
||||
{
|
||||
g_VboSize = needed_vtx_size + 5000 * sizeof(ImDrawVert); // Grow buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
// Copy and convert all vertices into a single contiguous buffer
|
||||
unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
if (!buffer_data)
|
||||
return;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
|
||||
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
|
||||
}
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(g_VaoHandle);
|
||||
|
||||
int cmd_offset = 0;
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
int vtx_offset = cmd_offset;
|
||||
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
|
||||
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
int needed_vtx_size = cmd_list->VtxBuffer.size() * sizeof(ImDrawVert);
|
||||
if (g_VboSize < needed_vtx_size)
|
||||
{
|
||||
if (pcmd->user_callback)
|
||||
// Grow our buffer if needed
|
||||
g_VboSize = needed_vtx_size + 2000 * sizeof(ImDrawVert);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
unsigned char* vtx_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, needed_vtx_size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
|
||||
if (!vtx_data)
|
||||
continue;
|
||||
memcpy(vtx_data, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert));
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
|
||||
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
|
||||
{
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
|
||||
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
|
||||
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_buffer += pcmd->ElemCount;
|
||||
}
|
||||
cmd_offset = vtx_offset;
|
||||
}
|
||||
|
||||
// Restore modified state
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glUseProgram(last_program);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
|
@ -29,13 +29,22 @@ int main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplGlfwGL3_Init(window, true);
|
||||
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
|
@ -23,7 +23,7 @@ static GLuint g_FontTexture = 0;
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
static void ImGui_ImplGlfw_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
||||
// A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer.
|
||||
@ -53,29 +53,29 @@ static void ImGui_ImplGlfw_RenderDrawLists(ImDrawList** const cmd_lists, int cmd
|
||||
|
||||
// Render command lists
|
||||
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->vtx_buffer.front();
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front();
|
||||
const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos)));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv)));
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));
|
||||
|
||||
int vtx_offset = 0;
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||
if (pcmd->user_callback)
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
|
||||
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
|
||||
glDrawArrays(GL_TRIANGLES, vtx_offset, (GLsizei)pcmd->vtx_count);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_buffer += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
#undef OFFSETOF
|
||||
|
@ -21,13 +21,22 @@ int main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplGlfw_Init(window, true);
|
||||
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
|
@ -8,3 +8,9 @@
|
||||
```
|
||||
cl /MD /I <sdl2path\include> /I ..\.. main.cpp imgui_impl_sdl.cpp ..\..\imgui.cpp /link /LIBPATH:<sdl2path\lib> SDL2.lib SDL2main.lib
|
||||
```
|
||||
|
||||
- On Linux and similar Unices
|
||||
|
||||
```
|
||||
c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui.cpp `sdl2-config --libs` -lGL -o sdl2example
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
#include <SDL_OpenGL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include <imgui.h>
|
||||
#include "imgui_impl_sdl.h"
|
||||
|
||||
@ -16,7 +16,7 @@ static GLuint g_FontTexture = 0;
|
||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||
// If text or lines are blurry when integrating ImGui in your engine:
|
||||
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||
static void ImGui_ImplSdl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
static void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
||||
{
|
||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
||||
// A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer.
|
||||
@ -46,29 +46,29 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_
|
||||
|
||||
// Render command lists
|
||||
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
|
||||
for (int n = 0; n < cmd_lists_count; n++)
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||
{
|
||||
const ImDrawList* cmd_list = cmd_lists[n];
|
||||
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->vtx_buffer.front();
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front();
|
||||
const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos)));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv)));
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));
|
||||
|
||||
int vtx_offset = 0;
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
|
||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||
{
|
||||
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
|
||||
if (pcmd->user_callback)
|
||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->user_callback(cmd_list, pcmd);
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
|
||||
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
|
||||
glDrawArrays(GL_TRIANGLES, vtx_offset, (GLsizei)pcmd->vtx_count);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
||||
}
|
||||
vtx_offset += pcmd->vtx_count;
|
||||
idx_buffer += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
#undef OFFSETOF
|
||||
@ -118,9 +118,7 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event)
|
||||
case SDL_TEXTINPUT:
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
unsigned int c = event->text.text[0];
|
||||
if (c > 0 && c < 0x10000)
|
||||
io.AddInputCharacter((unsigned short)c);
|
||||
io.AddInputCharactersUTF8(event->text.text);
|
||||
return true;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_OpenGL.h>
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
int SDL_main(int, char**)
|
||||
int main(int, char**)
|
||||
{
|
||||
// Setup SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
@ -25,13 +25,22 @@ int SDL_main(int, char**)
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGui_ImplSdl_Init(window);
|
||||
|
||||
// Load Fonts
|
||||
// (see extra_fonts/README.txt for more details)
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//ImFont* my_font0 = io.Fonts->AddFontDefault();
|
||||
//ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
|
||||
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
|
||||
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
|
||||
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
||||
|
||||
bool show_test_window = true;
|
||||
bool show_another_window = false;
|
||||
|
BIN
extra_fonts/Cousine-Regular.ttf
Normal file
@ -30,6 +30,10 @@
|
||||
INCLUDED FONTS
|
||||
---------------------------------
|
||||
|
||||
Cousine-Regular.ttf
|
||||
Digitized data copyright (c) 2010 Google Corporation.
|
||||
Licensed under the SIL Open Font License, Version 1.1
|
||||
|
||||
DroidSans.ttf
|
||||
Copyright (c) Steve Matteson
|
||||
Apache License, version 2.0
|
||||
@ -53,16 +57,41 @@
|
||||
LOADING INSTRUCTIONS
|
||||
---------------------------------
|
||||
|
||||
Load default font with:
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
Load .TTF file with:
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels);
|
||||
|
||||
Add a third parameter to bake specific font ranges:
|
||||
Detailed options:
|
||||
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesDefault()); // Basic Latin, Extended Latin
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesJapanese()); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesChinese()); // Include full set of about 21000 CJK Unified Ideographs
|
||||
ImFontConfig config;
|
||||
config.OversampleH = 3;
|
||||
config.OversampleV = 3;
|
||||
config.GlyphExtraSpacing.x = 1.0f;
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config);
|
||||
|
||||
Merge two fonts:
|
||||
|
||||
// Load main font
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
// Add character ranges and merge into main font
|
||||
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
ImFontConfig config;
|
||||
config.MergeMode = true;
|
||||
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config, io.Fonts->GetGlyphRangesJapanese());
|
||||
|
||||
Add a fourth parameter to bake specific font ranges only:
|
||||
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault()); // Basic Latin, Extended Latin
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesChinese()); // Include full set of about 21000 CJK Unified Ideographs
|
||||
|
||||
Offset font vertically by altering the io.Font->DisplayOffset value:
|
||||
|
||||
|
190
imgui.h
@ -1,4 +1,4 @@
|
||||
// ImGui library v1.42
|
||||
// ImGui library v1.43
|
||||
// See .cpp file for documentation.
|
||||
// See ImGui::ShowTestWindow() for sample code.
|
||||
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
||||
@ -15,7 +15,7 @@
|
||||
#include <stdlib.h> // NULL, malloc, free, qsort, atoi
|
||||
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
|
||||
|
||||
#define IMGUI_VERSION "1.42"
|
||||
#define IMGUI_VERSION "1.43"
|
||||
|
||||
// Define assertion handler.
|
||||
#ifndef IM_ASSERT
|
||||
@ -31,6 +31,7 @@
|
||||
// Forward declarations
|
||||
struct ImDrawCmd;
|
||||
struct ImDrawList;
|
||||
struct ImDrawData;
|
||||
struct ImFont;
|
||||
struct ImFontAtlas;
|
||||
struct ImGuiIO;
|
||||
@ -170,7 +171,7 @@ namespace ImGui
|
||||
IMGUI_API void BeginGroup(); // once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc.
|
||||
IMGUI_API void EndGroup();
|
||||
IMGUI_API void Separator(); // horizontal line
|
||||
IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets or groups to layout them horizontally
|
||||
IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally
|
||||
IMGUI_API void Spacing(); // add spacing
|
||||
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size
|
||||
IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels
|
||||
@ -202,7 +203,7 @@ namespace ImGui
|
||||
IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
|
||||
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end);
|
||||
IMGUI_API void PushID(const void* ptr_id);
|
||||
IMGUI_API void PushID(const int int_id);
|
||||
IMGUI_API void PushID(int int_id);
|
||||
IMGUI_API void PopID();
|
||||
IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed
|
||||
IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end);
|
||||
@ -461,6 +462,8 @@ enum ImGuiInputTextFlags_
|
||||
ImGuiInputTextFlags_CallbackCharFilter = 1 << 9, // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character.
|
||||
ImGuiInputTextFlags_AllowTabInput = 1 << 10, // Pressing TAB input a '\t' character into the text field
|
||||
ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, // In multi-line mode, allow exiting edition by pressing Enter. Ctrl+Enter to add new line (by default adds new lines with Enter).
|
||||
ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, // Disable following the cursor horizontally
|
||||
ImGuiInputTextFlags_AlwaysInsertMode = 1 << 13, // Insert mode
|
||||
// [Internal]
|
||||
ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline()
|
||||
};
|
||||
@ -626,8 +629,11 @@ struct ImGuiStyle
|
||||
float ScrollbarWidth; // Width of the vertical scrollbar
|
||||
float ScrollbarRounding; // Radius of grab corners for scrollbar
|
||||
float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar
|
||||
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||
ImVec2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
|
||||
ImVec2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||||
bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
|
||||
bool AntiAliasedShapes; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
||||
ImVec4 Colors[ImGuiCol_COUNT];
|
||||
|
||||
IMGUI_API ImGuiStyle();
|
||||
@ -666,7 +672,7 @@ struct ImGuiIO
|
||||
|
||||
// REQUIRED: rendering function.
|
||||
// See example code if you are unsure of how to implement this.
|
||||
void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
|
||||
void (*RenderDrawListsFn)(ImDrawData* data);
|
||||
|
||||
// Optional: access OS clipboard
|
||||
// (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
|
||||
@ -697,8 +703,9 @@ struct ImGuiIO
|
||||
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data)
|
||||
ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
||||
|
||||
// Function
|
||||
IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]
|
||||
// Functions
|
||||
IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]
|
||||
IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Helper to add new characters into InputCharacters[] from an UTF-8 string
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
|
||||
@ -709,6 +716,7 @@ struct ImGuiIO
|
||||
float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
|
||||
int MetricsAllocs; // Number of active memory allocations
|
||||
int MetricsRenderVertices; // Vertices processed during last call to Render()
|
||||
int MetricsRenderIndices; //
|
||||
int MetricsActiveWindows; // Number of visible windows (exclude child windows)
|
||||
|
||||
//------------------------------------------------------------------
|
||||
@ -804,7 +812,7 @@ struct ImGuiOnceUponAFrame
|
||||
{
|
||||
ImGuiOnceUponAFrame() { RefFrame = -1; }
|
||||
mutable int RefFrame;
|
||||
operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
|
||||
operator bool() const { int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
|
||||
};
|
||||
|
||||
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
|
||||
@ -846,7 +854,7 @@ struct ImGuiTextBuffer
|
||||
ImGuiTextBuffer() { Buf.push_back(0); }
|
||||
const char* begin() const { return &Buf.front(); }
|
||||
const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator
|
||||
int size() const { return Buf.size()-1; }
|
||||
int size() const { return Buf.Size-1; }
|
||||
bool empty() { return size() >= 1; }
|
||||
void clear() { Buf.clear(); Buf.push_back(0); }
|
||||
IMGUI_API void append(const char* fmt, ...);
|
||||
@ -919,6 +927,7 @@ struct ImGuiTextEditCallbackData
|
||||
// NB: calling those function loses selection.
|
||||
void DeleteChars(int pos, int bytes_count);
|
||||
void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||
};
|
||||
|
||||
// ImColor() is just a helper that implicity converts to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
|
||||
@ -970,15 +979,15 @@ struct ImGuiListClipper
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draw List
|
||||
// Hold a series of drawing commands. The user provides a renderer for ImDrawList.
|
||||
// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Draw callbacks for advanced uses.
|
||||
// NB- You most likely DO NOT need to care about draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
|
||||
// NB- You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
|
||||
// Draw callback are useful for example if you want to render a complex 3D scene inside a UI element.
|
||||
// The expected behavior from your rendering loop is:
|
||||
// if (cmd.user_callback != NULL)
|
||||
// cmd.user_callback(parent_list, cmd);
|
||||
// if (cmd.UserCallback != NULL)
|
||||
// cmd.UserCallback(parent_list, cmd);
|
||||
// else
|
||||
// RenderTriangles()
|
||||
// It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state.
|
||||
@ -987,13 +996,16 @@ typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* c
|
||||
// Typically, 1 command = 1 gpu draw call (unless command is a callback)
|
||||
struct ImDrawCmd
|
||||
{
|
||||
unsigned int vtx_count; // Number of vertices (multiple of 3) to be drawn as triangles. The vertices are stored in the callee ImDrawList's vtx_buffer[] array.
|
||||
ImVec4 clip_rect; // Clipping rectangle (x1, y1, x2, y2)
|
||||
ImTextureID texture_id; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
|
||||
ImDrawCallback user_callback; // If != NULL, call the function instead of rendering the vertices. vtx_count will be 0. clip_rect and texture_id will be set normally.
|
||||
void* user_callback_data; // The draw callback code can access this.
|
||||
unsigned int ElemCount; // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[].
|
||||
ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2)
|
||||
ImTextureID TextureId; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
|
||||
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
||||
void* UserCallbackData; // The draw callback code can access this.
|
||||
};
|
||||
|
||||
// Vertex index
|
||||
typedef unsigned short ImDrawIdx;
|
||||
|
||||
// Vertex layout
|
||||
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
|
||||
struct ImDrawVert
|
||||
@ -1009,6 +1021,13 @@ struct ImDrawVert
|
||||
IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
|
||||
#endif
|
||||
|
||||
// Draw channels are used by the Columns API to "split" the render list into different channels while building, so items of each column can be batched together.
|
||||
struct ImDrawChannel
|
||||
{
|
||||
ImVector<ImDrawCmd> CmdBuffer;
|
||||
ImVector<ImDrawIdx> IdxBuffer;
|
||||
};
|
||||
|
||||
// Draw command list
|
||||
// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
|
||||
// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
|
||||
@ -1019,16 +1038,23 @@ IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
|
||||
struct ImDrawList
|
||||
{
|
||||
// This is what you have to render
|
||||
ImVector<ImDrawCmd> commands; // Commands. Typically 1 command = 1 gpu draw call.
|
||||
ImVector<ImDrawVert> vtx_buffer; // Vertex buffer. Each command consume ImDrawCmd::vtx_count of those
|
||||
ImVector<ImDrawCmd> CmdBuffer; // Commands. Typically 1 command = 1 gpu draw call.
|
||||
ImVector<ImDrawIdx> IdxBuffer; // Index buffer. Each command consume ImDrawCmd::ElemCount of those
|
||||
ImVector<ImDrawVert> VtxBuffer; // Vertex buffer.
|
||||
|
||||
// [Internal to ImGui]
|
||||
const char* owner_name; // Pointer to owner window's name, if any
|
||||
ImVector<ImVec4> clip_rect_stack; // [Internal]
|
||||
ImVector<ImTextureID> texture_id_stack; // [Internal]
|
||||
ImDrawVert* vtx_write; // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
|
||||
// [Internal, used while building lists]
|
||||
const char* _OwnerName; // Pointer to owner window's name (if any) for debugging
|
||||
unsigned int _VtxCurrentIdx; // [Internal] == VtxBuffer.Size
|
||||
ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
||||
ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
||||
ImVector<ImVec4> _ClipRectStack; // [Internal]
|
||||
ImVector<ImTextureID> _TextureIdStack; // [Internal]
|
||||
ImVector<ImVec2> _Path; // [Internal] current path building
|
||||
int _ChannelCurrent; // [Internal] current channel number (0)
|
||||
ImVector<ImDrawChannel> _Channels; // [Internal] draw channels for columns API
|
||||
|
||||
ImDrawList() { owner_name = NULL; Clear(); }
|
||||
ImDrawList() { _OwnerName = NULL; Clear(); }
|
||||
~ImDrawList() { ClearFreeMemory(); }
|
||||
IMGUI_API void Clear();
|
||||
IMGUI_API void ClearFreeMemory();
|
||||
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2.
|
||||
@ -1041,27 +1067,74 @@ struct ImDrawList
|
||||
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
|
||||
IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||
IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||
IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left);
|
||||
IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
|
||||
IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
|
||||
IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
|
||||
IMGUI_API void AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min_12, int a_max_12, bool filled = false, const ImVec2& third_point_offset = ImVec2(0,0)); // Angles in 0..12 range
|
||||
IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL);
|
||||
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);
|
||||
IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness, bool anti_aliased);
|
||||
IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col, bool anti_aliased);
|
||||
|
||||
// Stateful path API, add points then finish with PathFill() or PathStroke()
|
||||
inline void PathClear() { _Path.resize(0); }
|
||||
inline void PathLineTo(const ImVec2& p) { _Path.push_back(p); }
|
||||
IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min, int a_max);
|
||||
IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 12);
|
||||
IMGUI_API void PathRect(const ImVec2& a, const ImVec2& b, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||
inline void PathFill(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col, true); PathClear(); }
|
||||
inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness, true); PathClear(); }
|
||||
|
||||
// Advanced
|
||||
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'user_callback' in ImDrawCmd and call the function instead of rendering triangles.
|
||||
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles.
|
||||
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
|
||||
IMGUI_API void ChannelsSplit(int channel_count);
|
||||
IMGUI_API void ChannelsMerge(int channel_count);
|
||||
IMGUI_API void ChannelsSetCurrent(int idx);
|
||||
|
||||
// Internal helpers
|
||||
IMGUI_API void PrimReserve(unsigned int vtx_count);
|
||||
IMGUI_API void PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
|
||||
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
|
||||
IMGUI_API void PrimReserve(int idx_count, int vtx_count);
|
||||
IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col);
|
||||
IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col);
|
||||
IMGUI_API void PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col);
|
||||
IMGUI_API void PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
|
||||
inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); }
|
||||
inline void PrimWriteVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col){ _VtxWritePtr->pos = pos; _VtxWritePtr->uv = uv; _VtxWritePtr->col = col; _VtxWritePtr++; _VtxCurrentIdx++; }
|
||||
inline void PrimWriteIdx(ImDrawIdx idx) { *_IdxWritePtr = idx; _IdxWritePtr++; }
|
||||
IMGUI_API void UpdateClipRect();
|
||||
IMGUI_API void UpdateTextureID();
|
||||
IMGUI_API void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { vtx_write->pos = pos; vtx_write->uv = uv; vtx_write->col = col; vtx_write++; }
|
||||
};
|
||||
|
||||
// All draw data to render an ImGui frame
|
||||
struct ImDrawData
|
||||
{
|
||||
ImDrawList** CmdLists;
|
||||
int CmdListsCount;
|
||||
int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
|
||||
int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
|
||||
|
||||
// Functions
|
||||
void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
|
||||
};
|
||||
|
||||
struct ImFontConfig
|
||||
{
|
||||
void* FontData; // // TTF data
|
||||
int FontDataSize; // // TTF data size
|
||||
bool FontDataOwnedByAtlas; // true // TTF data ownership taken by the container ImFontAtlas (will delete memory itself). Set to true
|
||||
int FontNo; // 0 // Index of font within TTF file
|
||||
float SizePixels; // // Size in pixels for rasterizer
|
||||
int OversampleH, OversampleV; // 2, 2 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
|
||||
bool PixelSnapH; // false // Align every character to pixel boundary (if enabled, set OversampleH/V to 1)
|
||||
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs
|
||||
const ImWchar* GlyphRanges; // // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
|
||||
bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs).
|
||||
bool MergeGlyphCenterV; // false // When merging (multiple ImFontInput for one ImFont), vertically center new glyphs instead of aligning their baseline
|
||||
|
||||
// [Internal]
|
||||
char Name[32]; // Name (strictly for debugging)
|
||||
ImFont* DstFont;
|
||||
|
||||
IMGUI_API ImFontConfig();
|
||||
};
|
||||
|
||||
// Load and rasterize multiple TTF fonts into a same texture.
|
||||
@ -1076,10 +1149,11 @@ struct ImFontAtlas
|
||||
{
|
||||
IMGUI_API ImFontAtlas();
|
||||
IMGUI_API ~ImFontAtlas();
|
||||
IMGUI_API ImFont* AddFontDefault();
|
||||
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0);
|
||||
IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
||||
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // 'compressed_ttf_data' untouched and still owned by caller. Compress with binary_to_compressed_c.cpp
|
||||
IMGUI_API ImFont* AddFont(const ImFontConfig* font_cfg);
|
||||
IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL);
|
||||
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL);
|
||||
IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
||||
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data' untouched and still owned by caller. Compress with binary_to_compressed_c.cpp
|
||||
IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory.
|
||||
IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges)
|
||||
IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)
|
||||
@ -1112,47 +1186,45 @@ struct ImFontAtlas
|
||||
ImVector<ImFont*> Fonts;
|
||||
|
||||
// Private
|
||||
struct ImFontAtlasData;
|
||||
ImVector<ImFontAtlasData*> InputData; // Internal data
|
||||
ImVector<ImFontConfig> ConfigData; // Internal data
|
||||
IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
|
||||
IMGUI_API void RenderCustomTexData(int pass, void* rects);
|
||||
};
|
||||
|
||||
// TTF font loading and rendering
|
||||
// Font runtime data and rendering
|
||||
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
||||
// Kerning isn't supported. At the moment some ImGui code does per-character CalcTextSize calls, need something more state-ful.
|
||||
struct ImFont
|
||||
{
|
||||
// Members: Settings
|
||||
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
||||
float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
||||
ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
||||
float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
||||
ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||
ImFontConfig* ConfigData; // // Pointer within ImFontAtlas->ConfigData
|
||||
int ConfigDataCount; //
|
||||
|
||||
// Members: Runtime data
|
||||
struct Glyph
|
||||
{
|
||||
ImWchar Codepoint;
|
||||
signed short XAdvance;
|
||||
signed short Width, Height;
|
||||
signed short XOffset, YOffset;
|
||||
float U0, V0, U1, V1; // Texture coordinates
|
||||
ImWchar Codepoint;
|
||||
float XAdvance;
|
||||
float X0, Y0, X1, Y1;
|
||||
float U0, V0, U1, V1; // Texture coordinates
|
||||
};
|
||||
float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
float Descent; //
|
||||
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
||||
ImVector<Glyph> Glyphs;
|
||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||
float FallbackXAdvance; //
|
||||
ImVector<float> IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
||||
ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
||||
float Ascent, Descent; // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
||||
ImVector<Glyph> Glyphs;
|
||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||
float FallbackXAdvance; //
|
||||
ImVector<float> IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
||||
ImVector<int> IndexLookup; // Sparse. Index glyphs by Unicode code-point
|
||||
|
||||
// Methods
|
||||
IMGUI_API ImFont();
|
||||
IMGUI_API ~ImFont();
|
||||
IMGUI_API void Clear();
|
||||
IMGUI_API void BuildLookupTable();
|
||||
IMGUI_API float GetCharAdvance(unsigned short c) const { return ((int)c < IndexXAdvance.size()) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
|
||||
IMGUI_API float GetCharAdvance(unsigned short c) const { return ((int)c < IndexXAdvance.Size) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
|
||||
IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
|
||||
IMGUI_API void SetFallbackChar(ImWchar c);
|
||||
IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }
|
||||
|
@ -1,3 +1,6 @@
|
||||
// [ImGui] this is a slightly modified version of stb_truetype.h 1.4
|
||||
// [ImGui] we made a fix for using the END key on multi-line text edit, see https://github.com/ocornut/imgui/issues/275
|
||||
|
||||
// stb_textedit.h - v1.4 - public domain - Sean Barrett
|
||||
// Development of this library was sponsored by RAD Game Tools
|
||||
//
|
||||
@ -957,6 +960,8 @@ retry:
|
||||
stb_textedit_move_to_first(state);
|
||||
stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);
|
||||
state->cursor = find.first_char + find.length;
|
||||
if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)
|
||||
state->cursor--;
|
||||
state->has_preferred_x = 0;
|
||||
break;
|
||||
}
|
||||
@ -977,6 +982,8 @@ retry:
|
||||
stb_textedit_prep_selection_at_cursor(state);
|
||||
stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);
|
||||
state->cursor = state->select_end = find.first_char + find.length;
|
||||
if (find.length > 0 && STB_TEXTEDIT_GETCHAR(str, state->cursor-1) == STB_TEXTEDIT_NEWLINE)
|
||||
state->cursor = state->select_end = state->cursor - 1;
|
||||
state->has_preferred_x = 0;
|
||||
break;
|
||||
}
|
||||
|
581
stb_truetype.h
@ -1,7 +1,7 @@
|
||||
// [ImGui] this is a slightly modified version of stb_truetype.h 1.05
|
||||
// [ImGui] this is a slightly modified version of stb_truetype.h 1.06
|
||||
// [ImGui] we added stbtt_PackFontRangesGatherRects() and stbtt_PackFontRangesRenderIntoRects() and modified stbtt_PackBegin()
|
||||
|
||||
// stb_truetype.h - v1.05 - public domain
|
||||
// stb_truetype.h - v1.06 - public domain
|
||||
// authored from 2009-2014 by Sean Barrett / RAD Game Tools
|
||||
//
|
||||
// This library processes TrueType files:
|
||||
@ -48,6 +48,9 @@
|
||||
//
|
||||
// VERSION HISTORY
|
||||
//
|
||||
// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine)
|
||||
// also more precise AA rasterizer, except if shapes overlap
|
||||
// remove need for STBTT_sort
|
||||
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
|
||||
// 1.04 (2015-04-15) typo in example
|
||||
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
|
||||
@ -123,6 +126,15 @@
|
||||
// stbtt_GetFontVMetrics()
|
||||
// stbtt_GetCodepointKernAdvance()
|
||||
//
|
||||
// Starting with version 1.06, the rasterizer was replaced with a new,
|
||||
// faster and generally-more-precise rasterizer. The new rasterizer more
|
||||
// accurately measures pixel coverage for anti-aliasing, except in the case
|
||||
// where multiple shapes overlap, in which case it overestimates the AA pixel
|
||||
// coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If
|
||||
// this turns out to be a problem, you can re-enable the old rasterizer with
|
||||
// #define STBTT_RASTERIZER_VERSION 1
|
||||
// which will incur about a 15% speed hit.
|
||||
//
|
||||
// ADDITIONAL DOCUMENTATION
|
||||
//
|
||||
// Immediately after this block comment are a series of sample programs.
|
||||
@ -222,7 +234,15 @@
|
||||
// Baked bitmap interface 70 LOC /
|
||||
// Font name matching & access 150 LOC ---- 150
|
||||
// C runtime library abstraction 60 LOC ---- 60
|
||||
|
||||
//
|
||||
//
|
||||
// PERFORMANCE MEASUREMENTS FOR 1.06:
|
||||
//
|
||||
// 32-bit 64-bit
|
||||
// Previous release: 8.83 s 7.68 s
|
||||
// Pool allocations: 7.72 s 6.34 s
|
||||
// Inline sort : 6.54 s 5.65 s
|
||||
// New rasterizer : 5.63 s 5.00 s
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -333,7 +353,7 @@ int main(int arg, char **argv)
|
||||
stbtt_fontinfo font;
|
||||
int i,j,ascent,baseline,ch=0;
|
||||
float scale, xpos=2; // leave a little padding in case the character extends left
|
||||
char *text = "Heljo World!";
|
||||
char *text = "Heljo World!"; // intentionally misspelled to show 'lj' brokenness
|
||||
|
||||
fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb"));
|
||||
stbtt_InitFont(&font, buffer, 0);
|
||||
@ -391,12 +411,6 @@ int main(int arg, char **argv)
|
||||
typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];
|
||||
typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];
|
||||
|
||||
// #define your own STBTT_sort() to override this to avoid qsort
|
||||
#ifndef STBTT_sort
|
||||
#include <stdlib.h>
|
||||
#define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func)
|
||||
#endif
|
||||
|
||||
// #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
|
||||
#ifndef STBTT_ifloor
|
||||
#include <math.h>
|
||||
@ -915,6 +929,10 @@ enum { // languageID for STBTT_PLATFORM_ID_MAC
|
||||
|
||||
typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1];
|
||||
|
||||
#ifndef STBTT_RASTERIZER_VERSION
|
||||
#define STBTT_RASTERIZER_VERSION 2
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// accessors to parse data from file
|
||||
@ -1563,42 +1581,129 @@ STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codep
|
||||
stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Rasterizer
|
||||
|
||||
typedef struct stbtt__hheap_chunk
|
||||
{
|
||||
struct stbtt__hheap_chunk *next;
|
||||
} stbtt__hheap_chunk;
|
||||
|
||||
typedef struct stbtt__hheap
|
||||
{
|
||||
struct stbtt__hheap_chunk *head;
|
||||
void *first_free;
|
||||
int num_remaining_in_head_chunk;
|
||||
} stbtt__hheap;
|
||||
|
||||
static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata)
|
||||
{
|
||||
if (hh->first_free) {
|
||||
void *p = hh->first_free;
|
||||
hh->first_free = * (void **) p;
|
||||
return p;
|
||||
} else {
|
||||
if (hh->num_remaining_in_head_chunk == 0) {
|
||||
int count = (size < 32 ? 2000 : size < 128 ? 800 : 100);
|
||||
stbtt__hheap_chunk *c = (stbtt__hheap_chunk *) STBTT_malloc(sizeof(stbtt__hheap_chunk) + size * count, userdata);
|
||||
if (c == NULL)
|
||||
return NULL;
|
||||
c->next = hh->head;
|
||||
hh->head = c;
|
||||
hh->num_remaining_in_head_chunk = count;
|
||||
}
|
||||
--hh->num_remaining_in_head_chunk;
|
||||
return (char *) (hh->head) + size * hh->num_remaining_in_head_chunk;
|
||||
}
|
||||
}
|
||||
|
||||
static void stbtt__hheap_free(stbtt__hheap *hh, void *p)
|
||||
{
|
||||
*(void **) p = hh->first_free;
|
||||
hh->first_free = p;
|
||||
}
|
||||
|
||||
static void stbtt__hheap_cleanup(stbtt__hheap *hh, void *userdata)
|
||||
{
|
||||
stbtt__hheap_chunk *c = hh->head;
|
||||
while (c) {
|
||||
stbtt__hheap_chunk *n = c->next;
|
||||
STBTT_free(c, userdata);
|
||||
c = n;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct stbtt__edge {
|
||||
float x0,y0, x1,y1;
|
||||
int invert;
|
||||
} stbtt__edge;
|
||||
|
||||
|
||||
typedef struct stbtt__active_edge
|
||||
{
|
||||
struct stbtt__active_edge *next;
|
||||
#if STBTT_RASTERIZER_VERSION==1
|
||||
int x,dx;
|
||||
float ey;
|
||||
struct stbtt__active_edge *next;
|
||||
int valid;
|
||||
int direction;
|
||||
#elif STBTT_RASTERIZER_VERSION==2
|
||||
float fx,fdx,fdy;
|
||||
float direction;
|
||||
float sy;
|
||||
float ey;
|
||||
#else
|
||||
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
|
||||
#endif
|
||||
} stbtt__active_edge;
|
||||
|
||||
#define FIXSHIFT 10
|
||||
#define FIX (1 << FIXSHIFT)
|
||||
#define FIXMASK (FIX-1)
|
||||
#if STBTT_RASTERIZER_VERSION == 1
|
||||
#define STBTT_FIXSHIFT 10
|
||||
#define STBTT_FIX (1 << STBTT_FIXSHIFT)
|
||||
#define STBTT_FIXMASK (STBTT_FIX-1)
|
||||
|
||||
static stbtt__active_edge *new_active(stbtt__edge *e, int off_x, float start_point, void *userdata)
|
||||
static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata)
|
||||
{
|
||||
stbtt__active_edge *z = (stbtt__active_edge *) STBTT_malloc(sizeof(*z), userdata); // @TODO: make a pool of these!!!
|
||||
stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata);
|
||||
float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
|
||||
STBTT_assert(e->y0 <= start_point);
|
||||
if (!z) return z;
|
||||
// round dx down to avoid going too far
|
||||
|
||||
// round dx down to avoid overshooting
|
||||
if (dxdy < 0)
|
||||
z->dx = -STBTT_ifloor(FIX * -dxdy);
|
||||
z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy);
|
||||
else
|
||||
z->dx = STBTT_ifloor(FIX * dxdy);
|
||||
z->x = STBTT_ifloor(FIX * (e->x0 + dxdy * (start_point - e->y0)));
|
||||
z->x -= off_x * FIX;
|
||||
z->dx = STBTT_ifloor(STBTT_FIX * dxdy);
|
||||
|
||||
z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); // use z->dx so when we offset later it's by the same amount
|
||||
z->x -= off_x * STBTT_FIX;
|
||||
|
||||
z->ey = e->y1;
|
||||
z->next = 0;
|
||||
z->valid = e->invert ? 1 : -1;
|
||||
z->direction = e->invert ? 1 : -1;
|
||||
return z;
|
||||
}
|
||||
#elif STBTT_RASTERIZER_VERSION == 2
|
||||
static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata)
|
||||
{
|
||||
stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata);
|
||||
float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
|
||||
//STBTT_assert(e->y0 <= start_point);
|
||||
if (!z) return z;
|
||||
z->fdx = dxdy;
|
||||
z->fdy = (1/dxdy);
|
||||
z->fx = e->x0 + dxdy * (start_point - e->y0);
|
||||
z->fx -= off_x;
|
||||
z->direction = e->invert ? 1.0f : -1.0f;
|
||||
z->sy = e->y0;
|
||||
z->ey = e->y1;
|
||||
z->next = 0;
|
||||
return z;
|
||||
}
|
||||
#else
|
||||
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
|
||||
#endif
|
||||
|
||||
#if STBTT_RASTERIZER_VERSION == 1
|
||||
// note: this routine clips fills that extend off the edges... ideally this
|
||||
// wouldn't happen, but it could happen if the truetype glyph bounding boxes
|
||||
// are wrong, or if the user supplies a too-small bitmap
|
||||
@ -1610,26 +1715,26 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac
|
||||
while (e) {
|
||||
if (w == 0) {
|
||||
// if we're currently at zero, we need to record the edge start point
|
||||
x0 = e->x; w += e->valid;
|
||||
x0 = e->x; w += e->direction;
|
||||
} else {
|
||||
int x1 = e->x; w += e->valid;
|
||||
int x1 = e->x; w += e->direction;
|
||||
// if we went to zero, we need to draw
|
||||
if (w == 0) {
|
||||
int i = x0 >> FIXSHIFT;
|
||||
int j = x1 >> FIXSHIFT;
|
||||
int i = x0 >> STBTT_FIXSHIFT;
|
||||
int j = x1 >> STBTT_FIXSHIFT;
|
||||
|
||||
if (i < len && j >= 0) {
|
||||
if (i == j) {
|
||||
// x0,x1 are the same pixel, so compute combined coverage
|
||||
scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> FIXSHIFT);
|
||||
scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT);
|
||||
} else {
|
||||
if (i >= 0) // add antialiasing for x0
|
||||
scanline[i] = scanline[i] + (stbtt_uint8) (((FIX - (x0 & FIXMASK)) * max_weight) >> FIXSHIFT);
|
||||
scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT);
|
||||
else
|
||||
i = -1; // clip
|
||||
|
||||
if (j < len) // add antialiasing for x1
|
||||
scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & FIXMASK) * max_weight) >> FIXSHIFT);
|
||||
scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT);
|
||||
else
|
||||
j = len; // clip
|
||||
|
||||
@ -1646,6 +1751,7 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac
|
||||
|
||||
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
||||
{
|
||||
stbtt__hheap hh = { 0 };
|
||||
stbtt__active_edge *active = NULL;
|
||||
int y,j=0;
|
||||
int max_weight = (255 / vsubsample); // weight per vertical scanline
|
||||
@ -1673,9 +1779,9 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
||||
stbtt__active_edge * z = *step;
|
||||
if (z->ey <= scan_y) {
|
||||
*step = z->next; // delete from list
|
||||
STBTT_assert(z->valid);
|
||||
z->valid = 0;
|
||||
STBTT_free(z, userdata);
|
||||
STBTT_assert(z->direction);
|
||||
z->direction = 0;
|
||||
stbtt__hheap_free(&hh, z);
|
||||
} else {
|
||||
z->x += z->dx; // advance to position for current scanline
|
||||
step = &((*step)->next); // advance through list
|
||||
@ -1704,7 +1810,7 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
||||
// insert all edges that start before the center of this scanline -- omit ones that also end on this scanline
|
||||
while (e->y0 <= scan_y) {
|
||||
if (e->y1 > scan_y) {
|
||||
stbtt__active_edge *z = new_active(e, off_x, scan_y, userdata);
|
||||
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata);
|
||||
// find insertion point
|
||||
if (active == NULL)
|
||||
active = z;
|
||||
@ -1735,24 +1841,378 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
||||
++j;
|
||||
}
|
||||
|
||||
while (active) {
|
||||
stbtt__active_edge *z = active;
|
||||
active = active->next;
|
||||
STBTT_free(z, userdata);
|
||||
}
|
||||
stbtt__hheap_cleanup(&hh, userdata);
|
||||
|
||||
if (scanline != scanline_data)
|
||||
STBTT_free(scanline, userdata);
|
||||
}
|
||||
|
||||
static int stbtt__edge_compare(const void *p, const void *q)
|
||||
{
|
||||
stbtt__edge *a = (stbtt__edge *) p;
|
||||
stbtt__edge *b = (stbtt__edge *) q;
|
||||
#elif STBTT_RASTERIZER_VERSION == 2
|
||||
|
||||
if (a->y0 < b->y0) return -1;
|
||||
if (a->y0 > b->y0) return 1;
|
||||
return 0;
|
||||
// the edge passed in here does not cross the vertical line at x or the vertical line at x+1
|
||||
// (i.e. it has already been clipped to those)
|
||||
static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1)
|
||||
{
|
||||
if (y0 == y1) return;
|
||||
assert(y0 < y1);
|
||||
assert(e->sy <= e->ey);
|
||||
if (y0 > e->ey) return;
|
||||
if (y1 < e->sy) return;
|
||||
if (y0 < e->sy) {
|
||||
x0 += (x1-x0) * (e->sy - y0) / (y1-y0);
|
||||
y0 = e->sy;
|
||||
}
|
||||
if (y1 > e->ey) {
|
||||
x1 += (x1-x0) * (e->ey - y1) / (y1-y0);
|
||||
y1 = e->ey;
|
||||
}
|
||||
|
||||
if (x0 == x)
|
||||
assert(x1 <= x+1);
|
||||
else if (x0 == x+1)
|
||||
assert(x1 >= x);
|
||||
else if (x0 <= x)
|
||||
assert(x1 <= x);
|
||||
else if (x0 >= x+1)
|
||||
assert(x1 >= x+1);
|
||||
else
|
||||
assert(x1 >= x && x1 <= x+1);
|
||||
|
||||
if (x0 <= x && x1 <= x)
|
||||
scanline[x] += e->direction * (y1-y0);
|
||||
else if (x0 >= x+1 && x1 >= x+1)
|
||||
;
|
||||
else {
|
||||
assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1);
|
||||
scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position
|
||||
}
|
||||
}
|
||||
|
||||
static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top)
|
||||
{
|
||||
float y_bottom = y_top+1;
|
||||
|
||||
while (e) {
|
||||
// brute force every pixel
|
||||
|
||||
// compute intersection points with top & bottom
|
||||
assert(e->ey >= y_top);
|
||||
|
||||
if (e->fdx == 0) {
|
||||
float x0 = e->fx;
|
||||
if (x0 < len) {
|
||||
if (x0 >= 0) {
|
||||
stbtt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom);
|
||||
stbtt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom);
|
||||
} else {
|
||||
stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float x0 = e->fx;
|
||||
float dx = e->fdx;
|
||||
float xb = x0 + dx;
|
||||
float x_top, x_bottom;
|
||||
float y0,y1;
|
||||
float dy = e->fdy;
|
||||
assert(e->sy <= y_bottom && e->ey >= y_top);
|
||||
|
||||
// compute endpoints of line segment clipped to this scanline (if the
|
||||
// line segment starts on this scanline. x0 is the intersection of the
|
||||
// line with y_top, but that may be off the line segment.
|
||||
if (e->sy > y_top) {
|
||||
x_top = x0 + dx * (e->sy - y_top);
|
||||
y0 = e->sy;
|
||||
} else {
|
||||
x_top = x0;
|
||||
y0 = y_top;
|
||||
}
|
||||
if (e->ey < y_bottom) {
|
||||
x_bottom = x0 + dx * (e->ey - y_top);
|
||||
y1 = e->ey;
|
||||
} else {
|
||||
x_bottom = xb;
|
||||
y1 = y_bottom;
|
||||
}
|
||||
|
||||
if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) {
|
||||
// from here on, we don't have to range check x values
|
||||
|
||||
if ((int) x_top == (int) x_bottom) {
|
||||
float height;
|
||||
// simple case, only spans one pixel
|
||||
int x = (int) x_top;
|
||||
height = y1 - y0;
|
||||
assert(x >= 0 && x < len);
|
||||
scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height;
|
||||
scanline_fill[x] += e->direction * height; // everything right of this pixel is filled
|
||||
} else {
|
||||
int x,x1,x2;
|
||||
float y_crossing, step, sign, area;
|
||||
// covers 2+ pixels
|
||||
if (x_top > x_bottom) {
|
||||
// flip scanline vertically; signed area is the same
|
||||
float t;
|
||||
y0 = y_bottom - (y0 - y_top);
|
||||
y1 = y_bottom - (y1 - y_top);
|
||||
t = y0, y0 = y1, y1 = t;
|
||||
t = x_bottom, x_bottom = x_top, x_top = t;
|
||||
dx = -dx;
|
||||
dy = -dy;
|
||||
t = x0, x0 = xb, xb = t;
|
||||
}
|
||||
|
||||
x1 = (int) x_top;
|
||||
x2 = (int) x_bottom;
|
||||
// compute intersection with y axis at x1+1
|
||||
y_crossing = (x1+1 - x0) * dy + y_top;
|
||||
|
||||
sign = e->direction;
|
||||
// area of the rectangle covered from y0..y_crossing
|
||||
area = sign * (y_crossing-y0);
|
||||
// area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing)
|
||||
scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2);
|
||||
|
||||
step = sign * dy;
|
||||
for (x = x1+1; x < x2; ++x) {
|
||||
scanline[x] += area + step/2;
|
||||
area += step;
|
||||
}
|
||||
y_crossing += dy * (x2 - (x1+1));
|
||||
|
||||
assert(fabs(area) <= 1.01f);
|
||||
|
||||
scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (y1-y_crossing);
|
||||
|
||||
scanline_fill[x2] += sign * (y1-y0);
|
||||
}
|
||||
} else {
|
||||
// if edge goes outside of box we're drawing, we require
|
||||
// clipping logic. since this does not match the intended use
|
||||
// of this library, we use a different, very slow brute
|
||||
// force implementation
|
||||
int x;
|
||||
for (x=0; x < len; ++x) {
|
||||
// cases:
|
||||
//
|
||||
// there can be up to two intersections with the pixel. any intersection
|
||||
// with left or right edges can be handled by splitting into two (or three)
|
||||
// regions. intersections with top & bottom do not necessitate case-wise logic.
|
||||
float y0,y1;
|
||||
float y_cur = y_top, x_cur = x0;
|
||||
// x = e->x + e->dx * (y-y_top)
|
||||
// (y-y_top) = (x - e->x) / e->dx
|
||||
// y = (x - e->x) / e->dx + y_top
|
||||
y0 = (x - x0) / dx + y_top;
|
||||
y1 = (x+1 - x0) / dx + y_top;
|
||||
|
||||
if (y0 < y1) {
|
||||
if (y0 > y_top && y0 < y_bottom) {
|
||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0);
|
||||
y_cur = y0;
|
||||
x_cur = (float) x;
|
||||
}
|
||||
if (y1 >= y_cur && y1 < y_bottom) {
|
||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1);
|
||||
y_cur = y1;
|
||||
x_cur = (float) x+1;
|
||||
}
|
||||
} else {
|
||||
if (y1 >= y_cur && y1 < y_bottom) {
|
||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1);
|
||||
y_cur = y1;
|
||||
x_cur = (float) x+1;
|
||||
}
|
||||
if (y0 > y_top && y0 < y_bottom) {
|
||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0);
|
||||
y_cur = y0;
|
||||
x_cur = (float) x;
|
||||
}
|
||||
}
|
||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, xb,y_bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
e = e->next;
|
||||
}
|
||||
}
|
||||
|
||||
// directly AA rasterize edges w/o supersampling
|
||||
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
||||
{
|
||||
(void)vsubsample;
|
||||
stbtt__hheap hh = { 0 };
|
||||
stbtt__active_edge *active = NULL;
|
||||
int y,j=0, i;
|
||||
float scanline_data[129], *scanline, *scanline2;
|
||||
|
||||
if (result->w > 64)
|
||||
scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata);
|
||||
else
|
||||
scanline = scanline_data;
|
||||
|
||||
scanline2 = scanline + result->w;
|
||||
|
||||
y = off_y;
|
||||
e[n].y0 = (float) (off_y + result->h) + 1;
|
||||
|
||||
while (j < result->h) {
|
||||
// find center of pixel for this scanline
|
||||
float scan_y_top = y + 0.0f;
|
||||
float scan_y_bottom = y + 1.0f;
|
||||
stbtt__active_edge **step = &active;
|
||||
|
||||
STBTT_memset(scanline , 0, result->w*sizeof(scanline[0]));
|
||||
STBTT_memset(scanline2, 0, (result->w+1)*sizeof(scanline[0]));
|
||||
|
||||
// update all active edges;
|
||||
// remove all active edges that terminate before the top of this scanline
|
||||
while (*step) {
|
||||
stbtt__active_edge * z = *step;
|
||||
if (z->ey <= scan_y_top) {
|
||||
*step = z->next; // delete from list
|
||||
STBTT_assert(z->direction);
|
||||
z->direction = 0;
|
||||
stbtt__hheap_free(&hh, z);
|
||||
} else {
|
||||
step = &((*step)->next); // advance through list
|
||||
}
|
||||
}
|
||||
|
||||
// insert all edges that start before the bottom of this scanline
|
||||
while (e->y0 <= scan_y_bottom) {
|
||||
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
||||
assert(z->ey >= scan_y_top);
|
||||
// insert at front
|
||||
z->next = active;
|
||||
active = z;
|
||||
++e;
|
||||
}
|
||||
|
||||
// now process all active edges
|
||||
if (active)
|
||||
stbtt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top);
|
||||
|
||||
{
|
||||
float sum = 0;
|
||||
for (i=0; i < result->w; ++i) {
|
||||
float k;
|
||||
int m;
|
||||
sum += scanline2[i];
|
||||
k = scanline[i] + sum;
|
||||
k = (float) fabs(k)*255 + 0.5f;
|
||||
m = (int) k;
|
||||
if (m > 255) m = 255;
|
||||
result->pixels[j*result->stride + i] = (unsigned char) m;
|
||||
}
|
||||
}
|
||||
// advance all the edges
|
||||
step = &active;
|
||||
while (*step) {
|
||||
stbtt__active_edge *z = *step;
|
||||
z->fx += z->fdx; // advance to position for current scanline
|
||||
step = &((*step)->next); // advance through list
|
||||
}
|
||||
|
||||
++y;
|
||||
++j;
|
||||
}
|
||||
|
||||
stbtt__hheap_cleanup(&hh, userdata);
|
||||
|
||||
if (scanline != scanline_data)
|
||||
STBTT_free(scanline, userdata);
|
||||
}
|
||||
#else
|
||||
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
|
||||
#endif
|
||||
|
||||
#define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0)
|
||||
|
||||
static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n)
|
||||
{
|
||||
int i,j;
|
||||
for (i=1; i < n; ++i) {
|
||||
stbtt__edge t = p[i], *a = &t;
|
||||
j = i;
|
||||
while (j > 0) {
|
||||
stbtt__edge *b = &p[j-1];
|
||||
int c = STBTT__COMPARE(a,b);
|
||||
if (!c) break;
|
||||
p[j] = p[j-1];
|
||||
--j;
|
||||
}
|
||||
if (i != j)
|
||||
p[j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n)
|
||||
{
|
||||
/* threshhold for transitioning to insertion sort */
|
||||
while (n > 12) {
|
||||
stbtt__edge t;
|
||||
int c01,c12,c,m,i,j;
|
||||
|
||||
/* compute median of three */
|
||||
m = n >> 1;
|
||||
c01 = STBTT__COMPARE(&p[0],&p[m]);
|
||||
c12 = STBTT__COMPARE(&p[m],&p[n-1]);
|
||||
/* if 0 >= mid >= end, or 0 < mid < end, then use mid */
|
||||
if (c01 != c12) {
|
||||
/* otherwise, we'll need to swap something else to middle */
|
||||
int z;
|
||||
c = STBTT__COMPARE(&p[0],&p[n-1]);
|
||||
/* 0>mid && mid<n: 0>n => n; 0<n => 0 */
|
||||
/* 0<mid && mid>n: 0>n => 0; 0<n => n */
|
||||
z = (c == c12) ? 0 : n-1;
|
||||
t = p[z];
|
||||
p[z] = p[m];
|
||||
p[m] = t;
|
||||
}
|
||||
/* now p[m] is the median-of-three */
|
||||
/* swap it to the beginning so it won't move around */
|
||||
t = p[0];
|
||||
p[0] = p[m];
|
||||
p[m] = t;
|
||||
|
||||
/* partition loop */
|
||||
i=1;
|
||||
j=n-1;
|
||||
for(;;) {
|
||||
/* handling of equality is crucial here */
|
||||
/* for sentinels & efficiency with duplicates */
|
||||
for (;;++i) {
|
||||
if (!STBTT__COMPARE(&p[i], &p[0])) break;
|
||||
}
|
||||
for (;;--j) {
|
||||
if (!STBTT__COMPARE(&p[0], &p[j])) break;
|
||||
}
|
||||
/* make sure we haven't crossed */
|
||||
if (i >= j) break;
|
||||
t = p[i];
|
||||
p[i] = p[j];
|
||||
p[j] = t;
|
||||
|
||||
++i;
|
||||
--j;
|
||||
}
|
||||
/* recurse on smaller side, iterate on larger */
|
||||
if (j < (n-i)) {
|
||||
stbtt__sort_edges_quicksort(p,j);
|
||||
p = p+i;
|
||||
n = n-i;
|
||||
} else {
|
||||
stbtt__sort_edges_quicksort(p+i, n-i);
|
||||
n = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void stbtt__sort_edges(stbtt__edge *p, int n)
|
||||
{
|
||||
stbtt__sort_edges_quicksort(p, n);
|
||||
stbtt__sort_edges_ins_sort(p, n);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
@ -1765,7 +2225,13 @@ static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcou
|
||||
float y_scale_inv = invert ? -scale_y : scale_y;
|
||||
stbtt__edge *e;
|
||||
int n,i,j,k,m;
|
||||
#if STBTT_RASTERIZER_VERSION == 1
|
||||
int vsubsample = result->h < 8 ? 15 : 5;
|
||||
#elif STBTT_RASTERIZER_VERSION == 2
|
||||
int vsubsample = 1;
|
||||
#else
|
||||
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
|
||||
#endif
|
||||
// vsubsample should divide 255 evenly; otherwise we won't reach full opacity
|
||||
|
||||
// now we have to blow out the windings into explicit edge lists
|
||||
@ -1802,7 +2268,8 @@ static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcou
|
||||
}
|
||||
|
||||
// now sort the edges by their highest point (should snap to integer, and then by x)
|
||||
STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare);
|
||||
//STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare);
|
||||
stbtt__sort_edges(e, n);
|
||||
|
||||
// now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
|
||||
stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata);
|
||||
@ -2346,17 +2813,13 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
|
||||
for (j=0; j < ranges[i].num_chars_in_range; ++j) {
|
||||
int x0,y0,x1,y1;
|
||||
int glyph = stbtt_FindGlyphIndex(info,ranges[i].first_unicode_char_in_range + j);
|
||||
if (glyph) {
|
||||
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
||||
scale * spc->h_oversample,
|
||||
scale * spc->v_oversample,
|
||||
0,0,
|
||||
&x0,&y0,&x1,&y1);
|
||||
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
||||
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
||||
} else {
|
||||
rects[k].w = rects[k].h = 1;
|
||||
}
|
||||
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
||||
scale * spc->h_oversample,
|
||||
scale * spc->v_oversample,
|
||||
0,0,
|
||||
&x0,&y0,&x1,&y1);
|
||||
rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
|
||||
rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
|
||||
++k;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 16 KiB |