SuperVGA said:
Dear ImGui is complicated stuff.
SuperVGA said:
then look into OpenGL
I agree with you. Topic starter should to write calculator in pure OpenGL. The most difficult thing in OpenGL is to making “picking of objects”. But it is no such difficult as it seams. I found the solution in the book: WebGL Programming Guide
Playground: https://plnkr.co/edit/hGGHKCo4UidasNirSPJF?p=preview
// If pressed position is inside <canvas>, check if it is above object
let x_in_canvas = x - rect.left, y_in_canvas = rect.bottom - y;
gl.uniform1i(uClickedLocation, 1); // Pass true to u_Clicked
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Clear buffers
gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0); // Draw
// Read pixel at the clicked position
let pixels = new Uint8Array(4); // Array for storing the pixel value
gl.readPixels(x_in_canvas, y_in_canvas, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
if (pixels[0] == 255) // The mouse in on cube if R(pixels[0]) is 255
{
Output.Instance.Print("Picked");
}
else
{
Output.Instance.Print("No");
}
gl.uniform1i(uClickedLocation, 0); // Pass false to u_Clicked(rewrite the cube)
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); // Clear buffers
gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0); // Draw