How to draw on an image in openGL?

944 views Asked by At

I load an image (biological image scans) and want to a) display it and b) draw markers on it. How would I program the shaders? I guess the vertex shaders are simple enough, since it is an 2D image. On idea I had was to overwrite the image data in the buffer, the pixels with the markers set to a specific values. My markers are boxes (so lines), is this the right way to go? I read that there are different primitives, lines too, so is there a way to draw my lines on my image without manipulating the data in the buffer, simply an overlay, so to speak? My framework is vispy, but pseudocode would also help.

1

There are 1 answers

0
lisyarus On BEST ANSWER

Draw a rectangle/square with your image as a texture on it. Then, draw the markers (probably as monotone quads/rectangles).

If you want the lines to be over the image, but under the markers, simply put the rendering code in between.

No shaders are required, if older OpenGL is suitable for you (since OpenGL 3.3 most old stuff was moved to compatibility profile, while modern features are core profile; the latter requires self-written shaders, but they should be pretty simple for your case).

To sum up, the things that you need understanding of are primitives (lines, triangles) and basic texturing.