Dynamically create complementary triangles of regular grid in OpenGL


close call

I created a regular grid derived from a 2D image, i.e. one vertex per pixel. There are two triangles every four pixels, so I have a triangle on the top right and bottom left. I use vertex and index buffers for this.

current state

Now, depending on my application, the triangles/faces at the boundaries of the two different types of vertices are dynamically deleted because otherwise there would be deformations. I wrote a geometry shader that takes a triangle and outputs that or nothing (see first picture). The shader recognizes if a triangle is "defective" (has an orange edge) and ignores it.

This works fine now, but I may be missing some details due to my vertex geometry. I can add complementary triangles to the mesh (see second picture, new triangles with orange dotted lines).

target state

How can this be done in OpenGL?

My first thought was to create a quad instead of two triangles, check the four possible triangle cases, and create those triangles dynamically in the geometry shader. But this can be slow; GL_QUAD is deprecated, and alternatives can be slow. What are you thinking about?

Ripi2

Here is my idea:

Put the entire mesh in a buffer/texture.
Build four triangles for each four pixels . They cross each other, yes.
In the geometry shader you can tell if the triangle is "defective" because it connects two wrong areas. Alternatively, sample from a texture, and since the intersecting triangle is valid, this new triangle can be discarded.

EDIT : Another approach

Use textures. Drawing instantiated with GL_POINTS. With some ordering and the help of instanceID, the shader knows where the point is.
To do this, test four possible triangles. If you instantiate top-to-bottom, left-to-right, the four triangles use only one point on the right and two below. And you avoid duplicating tests.
Only launch those you choose.

Related


OpenGL: Create colored triangles

and I'm learning OpenGL recently and I want to draw a triangle with red, green, blue at each point. However, when I use the following code, it just shows a blank white window. I can't find where the error is. I follow the site and the redbook. #include <GL/gle

OpenGL - Create cube grid

David Dunn I want to implement a grid with glut using OpenGL in C++ using a cube that is already done. The grid should be 15x15. Tried for loops, but can't seem to find an efficient way to use loops to write as little code as possible. Here is the code: #inclu

OpenGL - Create cube grid

David Dunn I want to implement a grid with glut using OpenGL in C++ using a cube that is already done. The grid should be 15x15. Tried for loops, but can't seem to find an efficient way to use loops to write as little code as possible. Here is the code: #inclu

OpenGL - Create cube grid

David Dunn I want to implement a grid with glut using OpenGL in C++ using a cube that is already done. The grid should be 15x15. Tried for loops, but can't seem to find an efficient way to use loops to write as little code as possible. Here is the code: #inclu

OpenGL - Create cube grid

David Dunn I want to implement a grid with glut using OpenGL in C++ using a cube that is already done. The grid should be 15x15. Tried for loops, but can't seem to find an efficient way to use loops to write as little code as possible. Here is the code: #inclu

OpenGL - Create cube grid

David Dunn I want to implement a grid with glut using OpenGL in C++ using a cube that is already done. The grid should be 15x15. Tried for loops, but can't seem to find an efficient way to use loops to write as little code as possible. Here is the code: #inclu

Dynamically create Bootstrap grid

Swopnilnep I'm trying to dynamically generate bootstrap columns using a javascript function. The purpose is to make them appear as different columns in the same row. It currently looks like this: I call this function on window.onload() with the div id: // Upda

Dynamically create Bootstrap grid

Swopnilnep I'm trying to dynamically generate bootstrap columns using a javascript function. The purpose is to make them appear as different columns in the same row. It currently looks like this: I call this function on window.onload() with the div id: // Upda

Dynamically create Bootstrap grid

Swopnilnep I'm trying to dynamically generate bootstrap columns using a javascript function. The purpose is to make them appear as different columns in the same row. It currently looks like this: I call this function on window.onload() with the div id: // Upda

Dynamically create Bootstrap grid

Swopnilnep I'm trying to dynamically generate bootstrap columns using a javascript function. The purpose is to make them appear as different columns in the same row. It currently looks like this: I call this function on window.onload() with the div id: // Upda

Regular Expressions: Dynamically create strings

Igor Streha Regular expression is required to check password policy I have a model: "password_settings": { "enable_password_max_length": false, "enable_password_min_length": false, "enable_min_number_of_upper": false, "enable_min_number_of_lowe

How to create a grid dynamically in unity

Samsung My vertices have color values. I want to make a mesh using vertices with the same color value. This photo is an example. I took a picture with an android phone and did an image segmentation of the object So I get a color value corresponding to the coor

How to create a dynamically changing grid?

Uncle Bear What I'm trying to say at the beginning is that I'm just starting my adventures with Xaml, so please understand if the question is trivial. I'm going to design a user control with variable layout, which is controlled by radio buttons in a UWP - C++C

Java dynamically create button in grid

Hassett I am creating a desktop application in Java in which I want to create buttons dynamically. Dynamically created buttons should be placed in a grid-like structure. Now, my concern is, if I want to access these buttons, what should I do since I don't have

Java dynamically create button in grid

Hassett I am creating a desktop application in Java in which I want to create buttons dynamically. Dynamically created buttons should be placed in a grid-like structure. Now, my concern is, if I want to access these buttons, what should I do since I don't have

Drawing multiple triangles in OpenGL

Alexandru Ica I'm just starting with OpenGL, I've made my own "OOP" version that draws triangles in c++. I'm using glfw, please wait if you have any questions. I don't understand why I can't draw more than 1 triangle. Here is the main function: int main() {

OpenGL refuses to draw triangles

Elliot Nelson I am trying to draw a large triangle in a window in OpenGL. My program compiles and runs, but there is only a black screen in the window. I checked and double checked multiple tutorials and it seems my steps are correct... Am I missing something

OpenGL GLFW, triangles not rendering

Theelf111 I've been trying to render a triangle on macOS, but it doesn't work. Here is my code: #include <iostream> #include <glm/glm.hpp> #include <GL/glew.h> #include <GLFW/glfw3.h> void OnError(int errorCode, const char* msg){ throw std::runtime_error(

OpenGL program not showing triangles

Martin Chekurov I'm using the OpenGL tutorial in C++ and for some reason the exact same code doesn't work for me. It should show a triangle but nothing. Just a blank screen. Here is the code: #include<iostream> #define GLEW_STATIC #include"GL/glew.h" #includ

OpenGL draws triangles

tak_se_paczam I'm very new to OpenGL, I've followed some tutorials and now I'm trying to use it myself. So I have this structure: struct Vertex { vec3 position; vec3 color; }; If I do all of this: glGenVertexArrays(1, &vaoID); glGenBuffers(1, &vboVert

OpenGL program not showing triangles

Martin Chekurov I'm using the OpenGL tutorial in C++ and for some reason the exact same code doesn't work for me. It should show a triangle but nothing. Just a blank screen. Here is the code: #include<iostream> #define GLEW_STATIC #include"GL/glew.h" #includ

Drawing multiple triangles in OpenGL

Alexandru Ica I'm just starting with OpenGL, I've made my own "OOP" version that draws triangles in c++. I'm using glfw, please wait if you have any questions. I don't understand why I can't draw more than 1 triangle. Here is the main function: int main() {

OpenGL GLFW, triangles not rendering

Theelf111 I've been trying to render a triangle on macOS, but it doesn't work. Here is my code: #include <iostream> #include <glm/glm.hpp> #include <GL/glew.h> #include <GLFW/glfw3.h> void OnError(int errorCode, const char* msg){ throw std::runtime_error(

OpenGL program not showing triangles

Martin Chekurov I'm using the OpenGL tutorial in C++ and for some reason the exact same code doesn't work for me. It should show a triangle but nothing. Just a blank screen. Here is the code: #include<iostream> #define GLEW_STATIC #include"GL/glew.h" #includ

OpenGL refuses to draw triangles

Elliot Nelson I am trying to draw a large triangle in a window in OpenGL. My program compiles and runs, but there is only a black screen in the window. I checked and double checked multiple tutorials and it seems my steps are correct... Am I missing something