Closed adminy closed 5 years ago
It looks like your TinyGL API ressemble early legacy OpenGL so you should be able to base your code on the imgui_impl_opengl2.cpp example.
I have tried, Did everything by the book. Seems to not really work.
Well, what have you tried, and how did it end? You say that you only found code with shaders, but have you looked at https://github.com/ocornut/imgui/blob/master/examples/imgui_impl_opengl2.cpp?
Wait... let me walk back what you're doing for a moment. You wanted a TinyGL backend to do... javascript? Why?
The imgui-js port works with WebGL, I replicated my environment on the web to illustrate my problem, my environment isn't on the web, but for the sake of solving the problem I moved the environment to the web. I don't have WebGL in that environment and actually, I don't have anything, except javascript. So I have TinyGL and Dear ImGui in javascript. That's all I can use. I believe there isn’t any C solution for this with tinyGL otherwise I would have definitely used that.
I see, that's fair. However, TinyGL is based off Mesa3D, and being a software renderer, it gives you the ability to rasterize into a framebuffer: https://github.com/ska80/tinygl/blob/master/src/oscontext.c
The point is that you can create a simple plain-C++ piece of code, use SDL to create a 2D framebuffer, and associate it to the offscreen renderer of TinyGL in order to, well, render. So that's the way to use TinyGL in plain C on a desktop machine, and have a proper debugging environment like Visual Studio or similar.
This way this would most likely make it much easier for you to debug what's going on, and potentially even give you the ability to switch between two backends (real OpenGL and TinyGL) to compare their behaviors. The missing features shouldn't cause too drastic rendering issues, I think, so the reason for it not to work ought to be fairly simple.
At the end of the day, TinyGL seems like a very old piece of code. There are updated versions that cropped up. TinyGLES looks more recent and with more features. Also, the code is based off Mesa3D's offscreen renderer, and it might be relevant to just go to the source instead, which supports OpenGL3 and has much more up to date features and support.
Good luck!
Thank you. Yeah I didn't know about TinyGLES, now I do, so I'll probably use that instead. The thing is, it's very easy to make a mistake since I don't specialise in graphics ... I mainly just need it to work with the project I have to complete. It's kind of sad that Dear ImGui doesn't address this problem and implement software Rasterisation.
The problem with me trying to get it to work is that I'm no expert in this, and I might get some parts working, if I do everything in my power to, but is it worth it? ImGui is an abstraction layer in my eyes, so the least it can do is provide easier bindings for someone non-graphical to understand.
You know ... after getting TinyGLES to work I might even do what Dear ImGui does, I mean suppose I come that far, why not create another standard. And I know I'm mostly complaining because this small piece of the project turned out to be such a massive part to do.
Thanks again for the references, I hope I get to use them.
Getting support for TinyGL, a smaller subset of OpenGL with Dear Imgui.
The following static constants are available
ACCUM, ACCUM_ALPHA_BITS, ACCUM_BLUE_BITS, ACCUM_BUFFER_BIT, ACCUM_CLEAR_VALUE, ACCUM_GREEN_BITS, ACCUM_RED_BITS, ADD, ALL_ATTRIB_BITS, ALPHA, ALPHA4, ALPHA8, ALPHA12, ALPHA16, ALPHA_BIAS, ALPHA_BITS, ALPHA_SCALE, ALPHA_TEST, ALPHA_TEST_FUNC, ALPHA_TEST_REF, ALWAYS, AMBIENT, AMBIENT_AND_DIFFUSE, AND, AND_INVERTED, AND_REVERSE, ATTRIB_STACK_DEPTH, AUTO_NORMAL, AUX0, AUX1, AUX2, AUX3, AUX_BUFFERS, BACK, BACK_LEFT, BACK_RIGHT, BITMAP, BITMAP_TOKEN, BLEND, BLEND_COLOR_EXT, BLEND_DST, BLEND_EQUATION_EXT, BLEND_SRC, BLUE, BLUE_BIAS, BLUE_BITS, BLUE_SCALE, BYTE, C3F_V3F, C4F_N3F_V3F, C4UB_V2F, C4UB_V3F, CCW, CLAMP, CLEAR, CLIP_PLANE0, CLIP_PLANE1, CLIP_PLANE2, CLIP_PLANE3, CLIP_PLANE4, CLIP_PLANE5, COEFF, COLOR, COLOR_ARRAY, COLOR_ARRAY_COUNT, COLOR_ARRAY_COUNT_EXT, COLOR_ARRAY_EXT, COLOR_ARRAY_POINTER, COLOR_ARRAY_POINTER_EXT, COLOR_ARRAY_SIZE, COLOR_ARRAY_SIZE_EXT, COLOR_ARRAY_STRIDE, COLOR_ARRAY_STRIDE_EXT, COLOR_ARRAY_TYPE, COLOR_ARRAY_TYPE_EXT, COLOR_BUFFER_BIT, COLOR_CLEAR_VALUE, COLOR_INDEX, COLOR_INDEXES, COLOR_MATERIAL, COLOR_MATERIAL_FACE, COLOR_MATERIAL_PARAMETER, COLOR_WRITEMASK, COMPILE, COMPILE_AND_EXECUTE, CONSTANT_ALPHA, CONSTANT_ALPHA_EXT, CONSTANT_ATTENUATION, CONSTANT_COLOR, CONSTANT_COLOR_EXT, COPY, COPY_INVERTED, COPY_PIXEL_TOKEN, CULL_FACE, CULL_FACE_MODE, CURRENT_BIT, CURRENT_COLOR, CURRENT_INDEX, CURRENT_NORMAL, CURRENT_QUERY, CURRENT_RASTER_COLOR, CURRENT_RASTER_DISTANCE, CURRENT_RASTER_INDEX, CURRENT_RASTER_POSITION, CURRENT_RASTER_POSITION_VALID, CURRENT_RASTER_TEXTURE_COORDS, CURRENT_TEXTURE_COORDS, CW, DECAL, DECR, DEPTH, DEPTH_BIAS, DEPTH_BITS, DEPTH_BUFFER_BIT, DEPTH_CLEAR_VALUE, DEPTH_COMPONENT, DEPTH_FUNC, DEPTH_RANGE, DEPTH_SCALE, DEPTH_TEST, DEPTH_WRITEMASK, DIFFUSE, DITHER, DOMAIN, DONT_CARE, DOUBLE, DOUBLEBUFFER, DRAW_BUFFER, DRAW_PIXEL_TOKEN, DST_ALPHA, DST_COLOR, EDGE_FLAG, EDGE_FLAG_ARRAY, EDGE_FLAG_ARRAY_COUNT, EDGE_FLAG_ARRAY_COUNT_EXT, EDGE_FLAG_ARRAY_EXT, EDGE_FLAG_ARRAY_POINTER, EDGE_FLAG_ARRAY_POINTER_EXT, EDGE_FLAG_ARRAY_STRIDE, EDGE_FLAG_ARRAY_STRIDE_EXT, EMISSION, ENABLE_BIT, EQUAL, EQUIV, EVAL_BIT, EXP, EXP2, EXTENSIONS, EYE_LINEAR, EYE_PLANE, FALSE, FASTEST, FEEDBACK, FILL, FLAT, FLOAT, FOG, FOG_BIT, FOG_COLOR, FOG_DENSITY, FOG_END, FOG_HINT, FOG_INDEX, FOG_MODE, FOG_START, FRONT, FRONT_AND_BACK, FRONT_FACE, FRONT_LEFT, FRONT_RIGHT, FUNC_ADD_EXT, FUNC_REVERSE_SUBTRACT_EXT, FUNC_SUBTRACT_EXT, GEQUAL, GREATER, GREEN, GREEN_BIAS, GREEN_BITS, GREEN_SCALE, HINT_BIT, INCR, INDEX_ARRAY, INDEX_ARRAY_COUNT, INDEX_ARRAY_COUNT_EXT, INDEX_ARRAY_EXT, INDEX_ARRAY_POINTER, INDEX_ARRAY_POINTER_EXT, INDEX_ARRAY_STRIDE, INDEX_ARRAY_STRIDE_EXT, INDEX_ARRAY_TYPE, INDEX_ARRAY_TYPE_EXT, INDEX_BITS, INDEX_CLEAR_VALUE, INDEX_MODE, INDEX_OFFSET, INDEX_SHIFT, INDEX_WRITEMASK, INT, INTENSITY, INTENSITY4, INTENSITY8, INTENSITY12, INTENSITY16, INVALID_ENUM, INVALID_OPERATION, INVALID_VALUE, INVERT, KEEP, LEFT, LEQUAL, LESS, LIGHT0, LIGHT1, LIGHT2, LIGHT3, LIGHT4, LIGHT5, LIGHT6, LIGHT7, LIGHTING, LIGHTING_BIT, LIGHT_MODEL_AMBIENT, LIGHT_MODEL_LOCAL_VIEWER, LIGHT_MODEL_TWO_SIDE, LINE, LINEAR, LINEAR_ATTENUATION, LINEAR_MIPMAP_LINEAR, LINEAR_MIPMAP_NEAREST, LINES, LINE_BIT, LINE_LOOP, LINE_RESET_TOKEN, LINE_SMOOTH, LINE_SMOOTH_HINT, LINE_STIPPLE, LINE_STIPPLE_PATTERN, LINE_STIPPLE_REPEAT, LINE_STRIP, LINE_TOKEN, LINE_WIDTH, LINE_WIDTH_GRANULARITY, LINE_WIDTH_RANGE, LIST_BASE, LIST_BIT, LIST_INDEX, LIST_MODE, LOAD, LOGIC_OP, LOGIC_OP_MODE, LUMINANCE, LUMINANCE4, LUMINANCE4_ALPHA4, LUMINANCE6_ALPHA2, LUMINANCE8, LUMINANCE8_ALPHA8, LUMINANCE12, LUMINANCE12_ALPHA4, LUMINANCE12_ALPHA12, LUMINANCE16, LUMINANCE16_ALPHA16, LUMINANCE_ALPHA, MAP1_COLOR_4, MAP1_GRID_DOMAIN, MAP1_GRID_SEGMENTS, MAP1_INDEX, MAP1_NORMAL, MAP1_TEXTURE_COORD_1, MAP1_TEXTURE_COORD_2, MAP1_TEXTURE_COORD_3, MAP1_TEXTURE_COORD_4, MAP1_VERTEX_3, MAP1_VERTEX_4, MAP2_COLOR_4, MAP2_GRID_DOMAIN, MAP2_GRID_SEGMENTS, MAP2_INDEX, MAP2_NORMAL, MAP2_TEXTURE_COORD_1, MAP2_TEXTURE_COORD_2, MAP2_TEXTURE_COORD_3, MAP2_TEXTURE_COORD_4, MAP2_VERTEX_3, MAP2_VERTEX_4, MAP_COLOR, MAP_STENCIL, MATRIX_MODE, MAX_ATTRIB_STACK_DEPTH, MAX_CLIENT_ATTRIB_STACK_DEPTH, MAX_CLIP_PLANES, MAX_EVAL_ORDER, MAX_EXT, MAX_LIGHTS, MAX_LIST_NESTING, MAX_MODELVIEW_STACK_DEPTH, MAX_NAME_STACK_DEPTH, MAX_PIXEL_MAP_TABLE, MAX_PROJECTION_STACK_DEPTH, MAX_TEXTURE_SIZE, MAX_TEXTURE_STACK_DEPTH, MAX_VIEWPORT_DIMS, MIN_EXT, MODELVIEW, MODELVIEW_MATRIX, MODELVIEW_STACK_DEPTH, MODULATE, MULT, N3F_V3F, NAME_STACK_DEPTH, NAND, NEAREST, NEAREST_MIPMAP_LINEAR, NEAREST_MIPMAP_NEAREST, NEVER, NICEST, NONE, NOOP, NOR, NORMALIZE, NORMAL_ARRAY, NORMAL_ARRAY_COUNT, NORMAL_ARRAY_COUNT_EXT, NORMAL_ARRAY_EXT, NORMAL_ARRAY_POINTER, NORMAL_ARRAY_POINTER_EXT, NORMAL_ARRAY_STRIDE, NORMAL_ARRAY_STRIDE_EXT, NORMAL_ARRAY_TYPE, NORMAL_ARRAY_TYPE_EXT, NOTEQUAL, OBJECT_LINEAR, OBJECT_PLANE, ONE, ONE_MINUS_CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA_EXT, ONE_MINUS_CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR_EXT, ONE_MINUS_DST_ALPHA, ONE_MINUS_DST_COLOR, ONE_MINUS_SRC_ALPHA, ONE_MINUS_SRC_COLOR, OR, ORDER, OR_INVERTED, OR_REVERSE, OUT_OF_MEMORY, PACK_ALIGNMENT, PACK_LSB_FIRST, PACK_ROW_LENGTH, PACK_SKIP_PIXELS, PACK_SKIP_ROWS, PACK_SWAP_BYTES, PASS_THROUGH_TOKEN, PERSPECTIVE_CORRECTION_HINT, PIXEL_MAP_A_TO_A, PIXEL_MAP_A_TO_A_SIZE, PIXEL_MAP_B_TO_B, PIXEL_MAP_B_TO_B_SIZE, PIXEL_MAP_G_TO_G, PIXEL_MAP_G_TO_G_SIZE, PIXEL_MAP_I_TO_A, PIXEL_MAP_I_TO_A_SIZE, PIXEL_MAP_I_TO_B, PIXEL_MAP_I_TO_B_SIZE, PIXEL_MAP_I_TO_G, PIXEL_MAP_I_TO_G_SIZE, PIXEL_MAP_I_TO_I, PIXEL_MAP_I_TO_I_SIZE, PIXEL_MAP_I_TO_R, PIXEL_MAP_I_TO_R_SIZE, PIXEL_MAP_R_TO_R, PIXEL_MAP_R_TO_R_SIZE, PIXEL_MAP_S_TO_S, PIXEL_MAP_S_TO_S_SIZE, PIXEL_MODE_BIT, POINT, POINTS, POINT_BIT, POINT_SIZE, POINT_SIZE_GRANULARITY, POINT_SIZE_RANGE, POINT_SMOOTH, POINT_SMOOTH_HINT, POINT_TOKEN, POLYGON, POLYGON_BIT, POLYGON_MODE, POLYGON_OFFSET_BIAS_EXT, POLYGON_OFFSET_EXT, POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_FACTOR_EXT, POLYGON_OFFSET_FILL, POLYGON_OFFSET_LINE, POLYGON_OFFSET_POINT, POLYGON_OFFSET_UNITS, POLYGON_SMOOTH, POLYGON_SMOOTH_HINT, POLYGON_STIPPLE, POLYGON_STIPPLE_BIT, POLYGON_TOKEN, POSITION, PROJECTION, PROJECTION_MATRIX, PROJECTION_STACK_DEPTH, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D, Q, QUADRATIC_ATTENUATION, QUADS, QUAD_STRIP, QUERY_COUNTER_BITS, QUERY_RESULT, QUERY_RESULT_AVAILABLE, R, R3_G3_B2, READ_BUFFER, RED, RED_BIAS, RED_BITS, RED_SCALE, RENDER, RENDERER, RENDER_MODE, REPEAT, REPLACE, RETURN, RGB, RGB4, RGB5, RGB5_A1, RGB8, RGB10, RGB10_A2, RGB12, RGB16, RGBA, RGBA2, RGBA4, RGBA8, RGBA12, RGBA16, RGBA_MODE, RIGHT, S, SAMPLES_PASSED, SCISSOR_BIT, SCISSOR_BOX, SCISSOR_TEST, SELECT, SET, SHADE_MODEL, SHININESS, SHORT, SMOOTH, SPECULAR, SPHERE_MAP, SPOT_CUTOFF, SPOT_DIRECTION, SPOT_EXPONENT, SRC_ALPHA, SRC_ALPHA_SATURATE, SRC_COLOR, STACK_OVERFLOW, STACK_UNDERFLOW, STENCIL, STENCIL_BITS, STENCIL_BUFFER_BIT, STENCIL_CLEAR_VALUE, STENCIL_FAIL, STENCIL_FUNC, STENCIL_INDEX, STENCIL_PASS_DEPTH_FAIL, STENCIL_PASS_DEPTH_PASS, STENCIL_REF, STENCIL_TEST, STENCIL_VALUE_MASK, STENCIL_WRITEMASK, STEREO, SUBPIXEL_BITS, T, T2F_C3F_V3F, T2F_C4F_N3F_V3F, T2F_C4UB_V3F, T2F_N3F_V3F, T2F_V3F, T4F_C4F_N3F_V4F, T4F_V4F, TEXTURE, TEXTURE_1D, TEXTURE_1D_BINDING, TEXTURE_2D, TEXTURE_2D_BINDING, TEXTURE_BIT, TEXTURE_BORDER, TEXTURE_BORDER_COLOR, TEXTURE_COMPONENTS, TEXTURE_COORD_ARRAY, TEXTURE_COORD_ARRAY_COUNT, TEXTURE_COORD_ARRAY_COUNT_EXT, TEXTURE_COORD_ARRAY_EXT, TEXTURE_COORD_ARRAY_POINTER, TEXTURE_COORD_ARRAY_POINTER_EXT, TEXTURE_COORD_ARRAY_SIZE, TEXTURE_COORD_ARRAY_SIZE_EXT, TEXTURE_COORD_ARRAY_STRIDE, TEXTURE_COORD_ARRAY_STRIDE_EXT, TEXTURE_COORD_ARRAY_TYPE, TEXTURE_COORD_ARRAY_TYPE_EXT, TEXTURE_ENV, TEXTURE_ENV_COLOR, TEXTURE_ENV_MODE, TEXTURE_GEN_MODE, TEXTURE_GEN_Q, TEXTURE_GEN_R, TEXTURE_GEN_S, TEXTURE_GEN_T, TEXTURE_HEIGHT, TEXTURE_MAG_FILTER, TEXTURE_MATRIX, TEXTURE_MIN_FILTER, TEXTURE_PRIORITY, TEXTURE_RESIDENT, TEXTURE_STACK_DEPTH, TEXTURE_WIDTH, TEXTURE_WRAP_S, TEXTURE_WRAP_T, TRANSFORM_BIT, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, TRUE, UNPACK_ALIGNMENT, UNPACK_FLIP_Y_TINYGL, UNPACK_LSB_FIRST, UNPACK_ROW_LENGTH, UNPACK_SKIP_PIXELS, UNPACK_SKIP_ROWS, UNPACK_SWAP_BYTES, UNSIGNED_BYTE, UNSIGNED_INT, UNSIGNED_SHORT, V2F, V3F, VENDOR, VERSION, VERTEX_ARRAY, VERTEX_ARRAY_COUNT, VERTEX_ARRAY_COUNT_EXT, VERTEX_ARRAY_EXT, VERTEX_ARRAY_POINTER, VERTEX_ARRAY_POINTER_EXT, VERTEX_ARRAY_SIZE, VERTEX_ARRAY_SIZE_EXT, VERTEX_ARRAY_STRIDE, VERTEX_ARRAY_STRIDE_EXT, VERTEX_ARRAY_TYPE, VERTEX_ARRAY_TYPE_EXT, VIEWPORT, VIEWPORT_BIT, XOR, ZERO, ZOOM_X, ZOOM_Y
And following Functions
arrayElement(i), begin(type), beginQuery(target, query), bindTexture(target, texture), callList(list), clear(mask), clearColor(r, g, b, a), clearDepth(depth), color3d(r, g, b), color3dv(v), color3f(r, g, b), color3fv(v), color4d(r, g, b, a), color4dv(v), color4f(r, g, b, a), color4fv(v), colorMaterial(mode, type), colorPointer(size, type, stride, data), cullFace(mode), debug(mode), deleteLists(list, range), deleteQueries(num, ids), deleteTextures(num, ids), disable(code), disableClientState(array), drawArrays(mode, first, count), drawElements(mode, count, type, indices), edgeFlag(flag), enable(code), enableClientState(array), end(), endList(), endQuery(target), flush(), frontFace(mode), frustum(left, right, bottom, top, near, far), genLists(range), genQueries(num, ids), genTextures(num, ids), getFloatv(pname, v), getIntegerv(pname, v), getQueryObjectuiv(query, pname, v), hint(target, mode), initNames(), isList(list), isQuery(query), lightModelfv(pname, v), lightModeli(pname, v), lightf(light, type, v), lightfv(light, type, v), loadIdentity(), loadMatrixf(m), loadName(name), materialf(mode, type, v), materialfv(mode, type, v), matrixMode(mode), multMatrixf(m), newList(list, mode), normal3d(x, y, z), normal3dv(v), normal3f(x, y, z), normal3fv(v), normalPointer(type, stride, data), ortho(left, right, bottom, top, near, far), pixelStorei(pname, param), polygonMode(face, mode), polygonOffset(factor, units), popMatrix(), popName(), pushMatrix(), pushName(name), renderMode(mode), rotatef(angle, x, y, z), scalef(x, y, z), selectBuffer(size, buf), shadeModel(mode), swapBuffers(), texCoord1d(s), texCoord1dv(v), texCoord1f(s), texCoord1fv(v), texCoord2d(s, t), texCoord2dv(v), texCoord2f(s, t), texCoord2fv(v), texCoord3d(v), texCoord3f(), texCoord3fv(v), texCoord4d(s, t, r, q), texCoord4dv(v), texCoord4f(s, t, r, q), texCoord4fv(v), texCoordPointer(size, type, stride, data), texEnvi(target, pname, param), texImage2D(target, level, components, width, height, border, format, type, pixels), texParameteri(target, pname, param), translatef(x, y, z), vertex2d(x, y), vertex2dv(v), vertex2f(x, y), vertex2fv(v), vertex3d(x, y, z), vertex3dv(v), vertex3f(x, y, z), vertex3fv(v), vertex4d(x, y, z, w), vertex4dv(v), vertex4f(x, y, z, w), vertex4fv(v), vertexPointer(size, type, stride, data), viewport(x, y, width, height)
These should be enough to render ImGui, From what I understand ImGui has DrawLists which in turn have DrawCommands that are used by opengl. But the only examples I found where using the shader program and tinygl is missing the shader program compiler. It would be great if I'm pointed in the right direction with this. Thank you.