I am trying to draw a border around an image that is rendered using OpenGL on an Android and iOS app. The way I do it now is that I specify the 3 vertices around each corner of the image as shown in the diagram and fill them up by drawing triangles.
The way I compute these vertices is by adding/subtracting an absolute value called BORDER_WIDTH that is set to a float. For example, the 3 vertices around the left corner of the rendered image (marked as 0,1,2 in the image linked above) are computed as follows.
[bottom_left_viewport_vertex[0] - BORDER_WIDTH, bottom_left_viewport_vertex[1], 0.0f,
bottom_left_viewport_vertex[0] - BORDER_WIDTH, bottom_left_viewport_vertex[1] - BORDER_WIDTH, 0.0f,
bottom_left_viewport_vertex[0], bottom_left_viewport_vertex[1] - BORDER_WIDTH, 0.0f]
This method causes 2 problems:
- The border is way thicker on iOS devices compared to Android devices probably because of the Retina display.
- The width of the border on the top and the bottom of the image is different from that on the sides of the image.
What is the right way to solve such a problem? Thank you.