I am rather new to (Modern) OpenGL, only taking my first steps with shaders. I was given the task to make it possible to use a mesh warp to warp the OpenGL window content. So, for example, given the simple Hello Triangle program from the LearnOpenGL website, what I want to do is the following:
Given a rectangular 32x32 mesh of gridpoints that is originally nicely fitting our main window, we move all the meshpoints to another location so that we have some kind of ‘displacement field’, and then the new mesh point locations determine the ‘main window warp’. Something like the following:
However, ‘Original image’ should not just be a static image, it should be my ‘dynamic OpenGL window content’. So for example if I’ve created a simple application that allows me to move with my mouse in a 3D space within that window, after the warping I should be moving in the ‘warped 3D space’, where the warp is defined by the warping mesh.
Clearly, only the warped locations of all 32x32=1024 mesh points are exactly defined. For all pixels in between, I assume some kind of interpolation method will be necessary or so.
I have read about the vertex shader and the fragment shader. Is this something that can be done completely in one of these shaders? Having some hints on how to approach this would be welcome.
My intuition tells me, that you should scrutinize the learnGL shaderstuff. Interpolating vertex-colors is typically an automated process in the shaders.
Your wording sticks out in a couple of ways:
Just to be sure: there is no ‘contents’ unless you’ve created it there.
It sounds and looks conspicuously like a landskape setup.
Well … the cursor comes in windows-coordinates (upper left corner 0,0) and measures in pixels. You can compare it’s coordinates with your grid (rooted in lower left gl-coords). Before your say landscape lands on the screen, it has been through some transformations that may spoil the sync between your grid and the mouse.
If your setup IS a landscape, it will have say a fixed x,z grid and varying hight y. Setting up a perspectiv projection and possibly a camera-model consept you may get a screen-output looking somewhat like your warping mesh image. This is a standard opengl problem set that I believe has shaped the ‘design’ of opengl.
By ‘moving around’ or dynamic contents you may think in terms of having a mesh of say a car that you can control with key-input (like the camera) to move it in the landscape. If that’s the case, then, welcome in the club. That’s what we do. Be prepared to stick around for a while … it takes a lot of work.
You can compose triangles between naboring coordinates in the grid. It’s a bit advanced for a newbe to shade these triangles using a mathematical light consept, but a quick way of getting a feel of an undulating surface. Repetitive tasks as drawing ordered triangles in a grid lends itself well for aiming at draw_elements() type of drawing. You make an index-buffer of a pattern you need for a rectangle (two triangles), say 32,33,1,0,32 … pointing to the numbered points in the grid.
After the draw_elements() call, there is just one more thing to do: figure out why it doesn’t work as expected. You’ll spent most of your time here, or be extremely well prepared.
There are means of debugging the shader.
Check if the finally produced program-output is not 0.
Set up the glGetError(), place and check it after new gl_code you’ve added. You can line it out again when code works.
use cout<< to follow code-paths if need be
the way you express yourself makes me think that you are talking about something completely different. But, you are a newb and you’ll excuse me if this is not the case. I hope I’ve given you some adequate words/ways of expression and a sketch of the problem-set and what needs to be done.