remove NuklearGL

This commit is contained in:
ikpil 2023-04-14 22:29:10 +09:00
parent 5806de7f82
commit c333ef7ce6
8 changed files with 0 additions and 981 deletions

View File

@ -1,200 +0,0 @@
/*
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using DotRecast.Core;
using DotRecast.Detour;
namespace DotRecast.Recast.Demo.Tools;
public static class PathUtils
{
private const int MAX_STEER_POINTS = 3;
public static SteerTarget getSteerTarget(NavMeshQuery navQuery, Vector3f startPos, Vector3f endPos,
float minTargetDist, List<long> path)
{
// Find steer target.
Result<List<StraightPathItem>> result = navQuery.findStraightPath(startPos, endPos, path, MAX_STEER_POINTS, 0);
if (result.failed())
{
return null;
}
List<StraightPathItem> straightPath = result.result;
float[] steerPoints = new float[straightPath.Count * 3];
for (int i = 0; i < straightPath.Count; i++)
{
steerPoints[i * 3] = straightPath[i].getPos()[0];
steerPoints[i * 3 + 1] = straightPath[i].getPos()[1];
steerPoints[i * 3 + 2] = straightPath[i].getPos()[2];
}
// Find vertex far enough to steer to.
int ns = 0;
while (ns < straightPath.Count)
{
// Stop at Off-Mesh link or when point is further than slop away.
if (((straightPath[ns].getFlags() & NavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0)
|| !inRange(straightPath[ns].getPos(), startPos, minTargetDist, 1000.0f))
break;
ns++;
}
// Failed to find good point to steer to.
if (ns >= straightPath.Count)
return null;
Vector3f steerPos = Vector3f.Of(
straightPath[ns].getPos()[0],
startPos[1],
straightPath[ns].getPos()[2]
);
int steerPosFlag = straightPath[ns].getFlags();
long steerPosRef = straightPath[ns].getRef();
SteerTarget target = new SteerTarget(steerPos, steerPosFlag, steerPosRef, steerPoints);
return target;
}
public static bool inRange(Vector3f v1, Vector3f v2, float r, float h)
{
float dx = v2[0] - v1[0];
float dy = v2[1] - v1[1];
float dz = v2[2] - v1[2];
return (dx * dx + dz * dz) < r * r && Math.Abs(dy) < h;
}
public static List<long> fixupCorridor(List<long> path, List<long> visited)
{
int furthestPath = -1;
int furthestVisited = -1;
// Find furthest common polygon.
for (int i = path.Count - 1; i >= 0; --i)
{
bool found = false;
for (int j = visited.Count - 1; j >= 0; --j)
{
if (path[i] == visited[j])
{
furthestPath = i;
furthestVisited = j;
found = true;
}
}
if (found)
break;
}
// If no intersection found just return current path.
if (furthestPath == -1 || furthestVisited == -1)
return path;
// Concatenate paths.
// Adjust beginning of the buffer to include the visited.
int req = visited.Count - furthestVisited;
int orig = Math.Min(furthestPath + 1, path.Count);
int size = Math.Max(0, path.Count - orig);
List<long> fixupPath = new();
// Store visited
for (int i = 0; i < req; ++i)
{
fixupPath.Add(visited[(visited.Count - 1) - i]);
}
for (int i = 0; i < size; i++)
{
fixupPath.Add(path[orig + i]);
}
return fixupPath;
}
// This function checks if the path has a small U-turn, that is,
// a polygon further in the path is adjacent to the first polygon
// in the path. If that happens, a shortcut is taken.
// This can happen if the target (T) location is at tile boundary,
// and we're (S) approaching it parallel to the tile edge.
// The choice at the vertex can be arbitrary,
// +---+---+
// |:::|:::|
// +-S-+-T-+
// |:::| | <-- the step can end up in here, resulting U-turn path.
// +---+---+
public static List<long> fixupShortcuts(List<long> path, NavMeshQuery navQuery)
{
if (path.Count < 3)
{
return path;
}
// Get connected polygons
List<long> neis = new();
Result<Tuple<MeshTile, Poly>> tileAndPoly = navQuery.getAttachedNavMesh().getTileAndPolyByRef(path[0]);
if (tileAndPoly.failed())
{
return path;
}
MeshTile tile = tileAndPoly.result.Item1;
Poly poly = tileAndPoly.result.Item2;
for (int k = tile.polyLinks[poly.index]; k != NavMesh.DT_NULL_LINK; k = tile.links[k].next)
{
Link link = tile.links[k];
if (link.refs != 0)
{
neis.Add(link.refs);
}
}
// If any of the neighbour polygons is within the next few polygons
// in the path, short cut to that polygon directly.
int maxLookAhead = 6;
int cut = 0;
for (int i = Math.Min(maxLookAhead, path.Count) - 1; i > 1 && cut == 0; i--)
{
for (int j = 0; j < neis.Count; j++)
{
if (path[i] == neis[j])
{
cut = i;
break;
}
}
}
if (cut > 1)
{
List<long> shortcut = new();
shortcut.Add(path[0]);
shortcut.AddRange(path.GetRange(cut, path.Count - cut));
return shortcut;
}
return path;
}
}

View File

@ -1,128 +0,0 @@
/*
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using DotRecast.Core;
namespace DotRecast.Recast.Demo.Tools;
public class PolyUtils
{
public static bool pointInPoly(float[] verts, Vector3f p)
{
int i, j;
bool c = false;
for (i = 0, j = verts.Length / 3 - 1; i < verts.Length / 3; j = i++)
{
Vector3f vi = Vector3f.Of(verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]);
Vector3f vj = Vector3f.Of(verts[j * 3], verts[j * 3 + 1], verts[j * 3 + 2]);
if (((vi[2] > p[2]) != (vj[2] > p[2]))
&& (p[0] < (vj[0] - vi[0]) * (p[2] - vi[2]) / (vj[2] - vi[2]) + vi[0]))
{
c = !c;
}
}
return c;
}
public static int offsetPoly(float[] verts, int nverts, float offset, float[] outVerts, int maxOutVerts)
{
float MITER_LIMIT = 1.20f;
int n = 0;
for (int i = 0; i < nverts; i++)
{
int a = (i + nverts - 1) % nverts;
int b = i;
int c = (i + 1) % nverts;
int va = a * 3;
int vb = b * 3;
int vc = c * 3;
float dx0 = verts[vb] - verts[va];
float dy0 = verts[vb + 2] - verts[va + 2];
float d0 = dx0 * dx0 + dy0 * dy0;
if (d0 > 1e-6f)
{
d0 = (float)(1.0f / Math.Sqrt(d0));
dx0 *= d0;
dy0 *= d0;
}
float dx1 = verts[vc] - verts[vb];
float dy1 = verts[vc + 2] - verts[vb + 2];
float d1 = dx1 * dx1 + dy1 * dy1;
if (d1 > 1e-6f)
{
d1 = (float)(1.0f / Math.Sqrt(d1));
dx1 *= d1;
dy1 *= d1;
}
float dlx0 = -dy0;
float dly0 = dx0;
float dlx1 = -dy1;
float dly1 = dx1;
float cross = dx1 * dy0 - dx0 * dy1;
float dmx = (dlx0 + dlx1) * 0.5f;
float dmy = (dly0 + dly1) * 0.5f;
float dmr2 = dmx * dmx + dmy * dmy;
bool bevel = dmr2 * MITER_LIMIT * MITER_LIMIT < 1.0f;
if (dmr2 > 1e-6f)
{
float scale = 1.0f / dmr2;
dmx *= scale;
dmy *= scale;
}
if (bevel && cross < 0.0f)
{
if (n + 2 >= maxOutVerts)
{
return 0;
}
float d = (1.0f - (dx0 * dx1 + dy0 * dy1)) * 0.5f;
outVerts[n * 3 + 0] = verts[vb] + (-dlx0 + dx0 * d) * offset;
outVerts[n * 3 + 1] = verts[vb + 1];
outVerts[n * 3 + 2] = verts[vb + 2] + (-dly0 + dy0 * d) * offset;
n++;
outVerts[n * 3 + 0] = verts[vb] + (-dlx1 - dx1 * d) * offset;
outVerts[n * 3 + 1] = verts[vb + 1];
outVerts[n * 3 + 2] = verts[vb + 2] + (-dly1 - dy1 * d) * offset;
n++;
}
else
{
if (n + 1 >= maxOutVerts)
{
return 0;
}
outVerts[n * 3 + 0] = verts[vb] - dmx * offset;
outVerts[n * 3 + 1] = verts[vb + 1];
outVerts[n * 3 + 2] = verts[vb + 2] - dmy * offset;
n++;
}
}
return n;
}
}

View File

@ -1,19 +0,0 @@
using DotRecast.Core;
namespace DotRecast.Recast.Demo.Tools;
public class SteerTarget
{
public readonly Vector3f steerPos;
public readonly int steerPosFlag;
public readonly long steerPosRef;
public readonly float[] steerPoints;
public SteerTarget(Vector3f steerPos, int steerPosFlag, long steerPosRef, float[] steerPoints)
{
this.steerPos = steerPos;
this.steerPosFlag = steerPosFlag;
this.steerPosRef = steerPosRef;
this.steerPoints = steerPoints;
}
}

View File

@ -1,154 +0,0 @@
/*
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Collections.Generic;
using Silk.NET.Input;
using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.UI;
public class Mouse
{
private double x;
private double y;
private double scrollX;
private double scrollY;
private double px;
private double py;
private double pScrollX;
private double pScrollY;
private readonly HashSet<int> pressed = new();
private readonly List<MouseListener> listeners = new();
public Mouse(IInputContext input)
{
foreach (IMouse mouse in input.Mice)
{
mouse.MouseDown += (mouse, button) => buttonPress((int)button, 0);
mouse.MouseUp += (mouse, button) => buttonRelease((int)button, 0);
// if (action == GLFW_PRESS) {
// buttonPress(button, mods);
// } else if (action == GLFW_RELEASE) {
// buttonRelease(button, mods);
// }
}
// glfwSetCursorPosCallback(window, (win, x, y) => cursorPos(x, y));
// glfwSetScrollCallback(window, (win, x, y) => scroll(x, y));
}
public void cursorPos(double x, double y)
{
foreach (MouseListener l in listeners)
{
l.position(x, y);
}
this.x = x;
this.y = y;
}
public void scroll(double xoffset, double yoffset)
{
foreach (MouseListener l in listeners)
{
l.scroll(xoffset, yoffset);
}
scrollX += xoffset;
scrollY += yoffset;
}
public double getDX()
{
return x - px;
}
public double getDY()
{
return y - py;
}
public double getDScrollX()
{
return scrollX - pScrollX;
}
public double getDScrollY()
{
return scrollY - pScrollY;
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
public void setDelta()
{
px = x;
py = y;
pScrollX = scrollX;
pScrollY = scrollY;
}
public void buttonPress(int button, int mods)
{
foreach (MouseListener l in listeners)
{
l.button(button, mods, true);
}
pressed.Add(button);
}
public void buttonRelease(int button, int mods)
{
foreach (MouseListener l in listeners)
{
l.button(button, mods, false);
}
pressed.Remove(button);
}
public bool isPressed(int button)
{
return pressed.Contains(button);
}
public void addListener(MouseListener listener)
{
listeners.Add(listener);
}
}

View File

@ -1,28 +0,0 @@
/*
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
namespace DotRecast.Recast.Demo.UI;
public interface MouseListener
{
void button(int button, int mods, bool down);
void scroll(double xoffset, double yoffset);
void position(double x, double y);
}

View File

@ -1,337 +0,0 @@
/*
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.IO;
using DotRecast.Core;
using DotRecast.Detour.Io;
using Microsoft.DotNet.PlatformAbstractions;
namespace DotRecast.Recast.Demo.UI;
public class NuklearGL
{
private static readonly int BUFFER_INITIAL_SIZE = 4 * 1024;
private static readonly int MAX_VERTEX_BUFFER = 512 * 1024;
private static readonly int MAX_ELEMENT_BUFFER = 128 * 1024;
private static readonly int FONT_BITMAP_W = 1024;
private static readonly int FONT_BITMAP_H = 1024;
private static readonly int FONT_HEIGHT = 15;
private readonly RcViewSystem context;
// private readonly NkDrawNullTexture null_texture = NkDrawNullTexture.create();
// private readonly NkBuffer cmds = NkBuffer.create();
// private readonly NkUserFont default_font;
private readonly int program;
private readonly int uniform_tex;
private readonly int uniform_proj;
private readonly int vbo;
private readonly int ebo;
private readonly int vao;
//private readonly Buffer vertexLayout;
public NuklearGL(RcViewSystem context)
{
this.context = context;
// nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE);
// vertexLayout = NkDrawVertexLayoutElement.create(4)//
// .position(0).attribute(NK_VERTEX_POSITION).format(NK_FORMAT_FLOAT).offset(0)//
// .position(1).attribute(NK_VERTEX_TEXCOORD).format(NK_FORMAT_FLOAT).offset(8)//
// .position(2).attribute(NK_VERTEX_COLOR).format(NK_FORMAT_R8G8B8A8).offset(16)//
// .position(3).attribute(NK_VERTEX_ATTRIBUTE_COUNT).format(NK_FORMAT_COUNT).offset(0)//
// .flip();
// string NK_SHADER_VERSION = Platform.get() == Platform.MACOSX ? "#version 150\n" : "#version 300 es\n";
// string vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n"
// + "in vec2 TexCoord;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n"
// + "void main() {\n" + " Frag_UV = TexCoord;\n" + " Frag_Color = Color;\n"
// + " gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n" + "}\n";
// string fragment_shader = NK_SHADER_VERSION + "precision mediump float;\n" + "uniform sampler2D Texture;\n"
// + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main(){\n"
// + " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" + "}\n";
//
// program = glCreateProgram();
// int vert_shdr = glCreateShader(GL_VERTEX_SHADER);
// int frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
// glShaderSource(vert_shdr, vertex_shader);
// glShaderSource(frag_shdr, fragment_shader);
// glCompileShader(vert_shdr);
// glCompileShader(frag_shdr);
// if (glGetShaderi(vert_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
// throw new IllegalStateException();
// }
// if (glGetShaderi(frag_shdr, GL_COMPILE_STATUS) != GL_TRUE) {
// throw new IllegalStateException();
// }
// glAttachShader(program, vert_shdr);
// glAttachShader(program, frag_shdr);
// glLinkProgram(program);
// if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) {
// throw new IllegalStateException();
// }
//
// uniform_tex = glGetUniformLocation(program, "Texture");
// uniform_proj = glGetUniformLocation(program, "ProjMtx");
// int attrib_pos = glGetAttribLocation(program, "Position");
// int attrib_uv = glGetAttribLocation(program, "TexCoord");
// int attrib_col = glGetAttribLocation(program, "Color");
//
// // buffer setup
// vbo = glGenBuffers();
// ebo = glGenBuffers();
// vao = glGenVertexArrays();
//
// glBindVertexArray(vao);
// glBindBuffer(GL_ARRAY_BUFFER, vbo);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
//
// glEnableVertexAttribArray(attrib_pos);
// glEnableVertexAttribArray(attrib_uv);
// glEnableVertexAttribArray(attrib_col);
//
// glVertexAttribPointer(attrib_pos, 2, GL_FLOAT, false, 20, 0);
// glVertexAttribPointer(attrib_uv, 2, GL_FLOAT, false, 20, 8);
// glVertexAttribPointer(attrib_col, 4, GL_UNSIGNED_BYTE, true, 20, 16);
//
// // null texture setup
// int nullTexID = glGenTextures();
//
// null_texture.texture().id(nullTexID);
// null_texture.uv().set(0.5f, 0.5f);
//
// glBindTexture(GL_TEXTURE_2D, nullTexID);
// try (MemoryStack stack = stackPush()) {
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV,
// stack.ints(0xFFFFFFFF));
// }
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//
// glBindTexture(GL_TEXTURE_2D, 0);
// glBindBuffer(GL_ARRAY_BUFFER, 0);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// glBindVertexArray(0);
// default_font = setupFont();
// nk_style_set_font(context.ctx, default_font);
}
private long setupFont()
{
return 0;
// NkUserFont font = NkUserFont.create();
// ByteBuffer ttf;
// try {
// ttf = IOUtils.toByteBuffer(Loader.ToBytes("fonts/DroidSans.ttf"), true);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
//
// int fontTexID = glGenTextures();
//
// STBTTFontinfo fontInfo = STBTTFontinfo.malloc();
// STBTTPackedchar.Buffer cdata = STBTTPackedchar.create(95);
//
// float scale;
// float descent;
//
// try (MemoryStack stack = stackPush()) {
// stbtt_InitFont(fontInfo, ttf);
// scale = stbtt_ScaleForPixelHeight(fontInfo, FONT_HEIGHT);
//
// int[] d = stack.mallocInt(1);
// stbtt_GetFontVMetrics(fontInfo, null, d, null);
// descent = d[0] * scale;
//
// ByteBuffer bitmap = memAlloc(FONT_BITMAP_W * FONT_BITMAP_H);
//
// STBTTPackContext pc = STBTTPackContext.mallocStack(stack);
// stbtt_PackBegin(pc, bitmap, FONT_BITMAP_W, FONT_BITMAP_H, 0, 1);
// stbtt_PackSetOversampling(pc, 1, 1);
// stbtt_PackFontRange(pc, ttf, 0, FONT_HEIGHT, 32, cdata);
// stbtt_PackEnd(pc);
//
// // Convert R8 to RGBA8
// ByteBuffer texture = memAlloc(FONT_BITMAP_W * FONT_BITMAP_H * 4);
// for (int i = 0; i < bitmap.capacity(); i++) {
// texture.putInt((bitmap[i] << 24) | 0x00FFFFFF);
// }
// texture.flip();
//
// glBindTexture(GL_TEXTURE_2D, fontTexID);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FONT_BITMAP_W, FONT_BITMAP_H, 0, GL_RGBA,
// GL_UNSIGNED_INT_8_8_8_8_REV, texture);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//
// memFree(texture);
// memFree(bitmap);
// }
// int[] cache = new int[1024];
// try (MemoryStack stack = stackPush()) {
// int[] advance = stack.mallocInt(1);
// for (int i = 0; i < 1024; i++) {
// stbtt_GetCodepointHMetrics(fontInfo, i, advance, null);
// cache[i] = advance[0];
// }
// }
// font.width((handle, h, text, len) => {
// float text_width = 0;
// try (MemoryStack stack = stackPush()) {
// int[] unicode = stack.mallocInt(1);
//
// int glyph_len = nnk_utf_decode(text, memAddress(unicode), len);
// int text_len = glyph_len;
//
// if (glyph_len == 0) {
// return 0;
// }
//
// int[] advance = stack.mallocInt(1);
// while (text_len <= len && glyph_len != 0) {
// if (unicode[0] == NK_UTF_INVALID) {
// break;
// }
//
// /* query currently drawn glyph information */
// // stbtt_GetCodepointHMetrics(fontInfo, unicode[0], advance, null);
// // text_width += advance[0] * scale;
//
// text_width += cache[unicode[0]] * scale;
// /* offset next glyph */
// glyph_len = nnk_utf_decode(text + text_len, memAddress(unicode), len - text_len);
// text_len += glyph_len;
// }
// }
// return text_width;
// }).height(FONT_HEIGHT).query((handle, font_height, glyph, codepoint, next_codepoint) => {
// try (MemoryStack stack = stackPush()) {
// float[] x = stack.floats(0.0f);
// float[] y = stack.floats(0.0f);
//
// STBTTAlignedQuad q = STBTTAlignedQuad.mallocStack(stack);
// // int[] advance = stack.mallocInt(1);
//
// stbtt_GetPackedQuad(cdata, FONT_BITMAP_W, FONT_BITMAP_H, codepoint - 32, x, y, q, false);
// // stbtt_GetCodepointHMetrics(fontInfo, codepoint, advance, null);
//
// NkUserFontGlyph ufg = NkUserFontGlyph.create(glyph);
//
// ufg.width(q.x1() - q.x0());
// ufg.height(q.y1() - q.y0());
// ufg.offset().set(q.x0(), q.y0() + (FONT_HEIGHT + descent));
// // ufg.xadvance(advance[0] * scale);
// ufg.xadvance(cache[codepoint] * scale);
// ufg.uv(0).set(q.s0(), q.t0());
// ufg.uv(1).set(q.s1(), q.t1());
// }
// }).texture().id(fontTexID);
// return font;
}
void render(long win, int AA)
{
// int width;
// int height;
// int display_width;
// int display_height;
// try (MemoryStack stack = stackPush()) {
// int[] w = stack.mallocInt(1);
// int[] h = stack.mallocInt(1);
//
// glfwGetWindowSize(win, w, h);
// width = w[0];
// height = h[0];
//
// glfwGetFramebufferSize(win, w, h);
// display_width = w[0];
// display_height = h[0];
// }
//
// try (MemoryStack stack = stackPush()) {
// // setup global state
// glEnable(GL_BLEND);
// glBlendEquation(GL_FUNC_ADD);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glDisable(GL_CULL_FACE);
// glDisable(GL_DEPTH_TEST);
// glEnable(GL_SCISSOR_TEST);
// glActiveTexture(GL_TEXTURE0);
//
// glUseProgram(program);
// // setup program
// glUniform1i(uniform_tex, 0);
// glUniformMatrix4fv(uniform_proj, false, stack.floats(2.0f / width, 0.0f, 0.0f, 0.0f, 0.0f, -2.0f / height,
// 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f));
// glViewport(0, 0, display_width, display_height);
// }
// // allocate vertex and element buffer
// glBindVertexArray(vao);
// glBindBuffer(GL_ARRAY_BUFFER, vbo);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
//
// glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_BUFFER, GL_STREAM_DRAW);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_BUFFER, GL_STREAM_DRAW);
//
// // load draw vertices & elements directly into vertex + element buffer
// ByteBuffer vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY, MAX_VERTEX_BUFFER, null);
// ByteBuffer elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY, MAX_ELEMENT_BUFFER, null);
//
// try (MemoryStack stack = stackPush()) {
// // fill convert configuration
// NkConvertConfig config = NkConvertConfig.callocStack(stack).vertex_layout(vertexLayout).vertex_size(20)
// .vertex_alignment(4).null_texture(null_texture).circle_segment_count(22).curve_segment_count(22)
// .arc_segment_count(22).global_alpha(1f).shape_AA(AA).line_AA(AA);
//
// // setup buffers to load vertices and elements
// NkBuffer vbuf = NkBuffer.mallocStack(stack);
// NkBuffer ebuf = NkBuffer.mallocStack(stack);
//
// nk_buffer_init_fixed(vbuf, vertices/* , max_vertex_buffer */);
// nk_buffer_init_fixed(ebuf, elements/* , max_element_buffer */);
// nk_convert(context.ctx, cmds, vbuf, ebuf, config);
// }
// glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
// glUnmapBuffer(GL_ARRAY_BUFFER);
//
// // iterate over and execute each draw command
// float fb_scale_x = (float) display_width / (float) width;
// float fb_scale_y = (float) display_height / (float) height;
//
// long offset = NULL;
// for (NkDrawCommand cmd = nk__draw_begin(context.ctx, cmds); cmd != null; cmd = nk__draw_next(cmd, cmds,
// context.ctx)) {
// if (cmd.elem_count() == 0) {
// continue;
// }
// glBindTexture(GL_TEXTURE_2D, cmd.texture().id());
// glScissor((int) (cmd.clip_rect().x() * fb_scale_x),
// (int) ((height - (int) (cmd.clip_rect().y() + cmd.clip_rect().h())) * fb_scale_y),
// (int) (cmd.clip_rect().w() * fb_scale_x), (int) (cmd.clip_rect().h() * fb_scale_y));
// glDrawElements(GL_TRIANGLES, cmd.elem_count(), GL_UNSIGNED_SHORT, offset);
// offset += cmd.elem_count() * 2;
// }
// nk_clear(context.ctx);
// glUseProgram(0);
// glBindTexture(GL_TEXTURE_2D, 0);
// glBindBuffer(GL_ARRAY_BUFFER, 0);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// glBindVertexArray(0);
// glDisable(GL_BLEND);
// glDisable(GL_SCISSOR_TEST);
}
}

View File

@ -1,74 +0,0 @@
/*
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices.JavaScript;
namespace DotRecast.Recast.Demo.UI;
public class NuklearUIHelper
{
// public static void nk_color_rgb(IWindow ctx, NkColorf color) {
// try (MemoryStack stack = stackPush()) {
// if (nk_combo_begin_color(ctx, nk_rgb_cf(color, NkColor.mallocStack(stack)),
// NkVec2.mallocStack(stack).set(nk_widget_width(ctx), 400))) {
// nk_layout_row_dynamic(ctx, 120, 1);
// nk_color_picker(ctx, color, NK_RGB);
// nk_layout_row_dynamic(ctx, 20, 1);
// color.r(nk_propertyf(ctx, "#R:", 0, color.r(), 1f, 0.01f, 0.005f));
// color.g(nk_propertyf(ctx, "#G:", 0, color.g(), 1f, 0.01f, 0.005f));
// color.b(nk_propertyf(ctx, "#B:", 0, color.b(), 1f, 0.01f, 0.005f));
// nk_combo_end(ctx);
// }
// }
// }
//
// public static <T extends Enum<?>> T nk_radio(IWindow ctx, T[] values, T currentValue, JSType.Function<T, string> nameFormatter) {
// try (MemoryStack stack = stackPush()) {
// foreach (T v in values) {
// nk_layout_row_dynamic(ctx, 20, 1);
// if (nk_option_text(ctx, nameFormatter.apply(v), currentValue == v)) {
// currentValue = v;
// }
// }
// }
// return currentValue;
// }
//
// public static <T extends Enum<?>> T nk_combo(IWindow ctx, T[] values, T currentValue) {
// try (MemoryStack stack = stackPush()) {
// if (nk_combo_begin_label(ctx, currentValue.toString(), NkVec2.mallocStack(stack).set(nk_widget_width(ctx), 200))) {
// nk_layout_row_dynamic(ctx, 20, 1);
// foreach (T v in values) {
// if (nk_combo_item_label(ctx, v.toString(), NK_TEXT_LEFT)) {
// currentValue = v;
// }
// }
// nk_combo_end(ctx);
// }
// }
// return currentValue;
// }
//
// public static NkColorf nk_colorf(int r, int g, int b) {
// NkColorf color = NkColorf.create();
// color.r(r / 255f);
// color.g(g / 255f);
// color.b(b / 255f);
// return color;
// }
}

View File

@ -36,60 +36,19 @@ public class RcViewSystem
// readonly NkColor background;
// readonly NkColor white;
private readonly IRcView[] _views;
private readonly NuklearGL glContext;
private bool _mouseOverUI;
public bool IsMouseOverUI() => _mouseOverUI;
public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views)
{
var mouse = new Mouse(input);
_window = window;
_gl = GL.GetApi(window);
setupMouse(mouse);
// setupClipboard(window);
// glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint));
// glContext = new NuklearGL(this);
_views = views;
}
private void setupMouse(Mouse mouse)
{
// mouse.addListener(new MouseListener() {
//
// @Override
// public void scroll(double xoffset, double yoffset) {
// if (mouseOverUI) {
// try (MemoryStack stack = stackPush()) {
// NkVec2 scroll = NkVec2.mallocStack(stack).x((float) xoffset).y((float) yoffset);
// nk_input_scroll(ctx, scroll);
// }
// }
// }
//
// @Override
// public void button(int button, int mods, bool down) {
// try (MemoryStack stack = stackPush()) {
// int nkButton;
// switch (button) {
// case GLFW_MOUSE_BUTTON_RIGHT:
// nkButton = NK_BUTTON_RIGHT;
// break;
// case GLFW_MOUSE_BUTTON_MIDDLE:
// nkButton = NK_BUTTON_MIDDLE;
// break;
// default:
// nkButton = NK_BUTTON_LEFT;
// }
// nk_input_button(ctx, nkButton, (int) mouse.getX(), (int) mouse.getY(), down);
// }
// }
//
// @Override
// public void position(double x, double y) {
// nk_input_motion(ctx, (int) x, (int) y);
// }
// });
}
private void setupClipboard(long window)
{