So I am trying to draw hexagons with [SDL_RenderDrawLines
][]. It looks to be working fairly well, however, it fails to draw some of the lines.
So each of the hexagons in the screenshot is a hex object. They each have a center x/y , and an array of SDL_Points for the six corners of the hex.
Here is the hex object draw call:
SDL_RenderDrawLines(
TheGame::Instance()->getRenderer(),
corners,
HEX_NUMBER_OF_CORNERS);
There is some reoccurring condition that causes a vertical line to not be rendered, and I can't seem to figure out why.
The two obvious things that stand out don't explain why there is no line:
- The draw order of the objects shouldn't matter since all of the borders for each hex are being drawn.
- The horizontal distance between adjacent hexes' centers can be +-1 because of rounding would lead to a double thick border and not a missing border.
If anyone has any insight, I welcome the input.
EDIT:
I have been over suggestions you have mentioned prior to this question, increasing the array of points to 7 is correct, I tested it on a triangle before I tried with hexagons. When you don't close of the shape, you typically get drawn lines that shoot off the edge of the screen.
The part on three lines is also something else I discovered while messing around. I included some of my code to show the two ways that I preformed the very thing you mentioned:
// render the hexagon to on screen
void Hex::draw()
{/*
draw order of points
rotate ccw 90 degrees for actual postion
[2] ____ [3]
/ \
[1] / \
\ / [4]
\____/
[0] [5]
*/
// draw the hex with a fill color
// 0XAABBGGRR is the bit order for the color param
filledPolygonColor(
TheGame::Instance()->getRenderer(),
vx, vy,
HEX_NUMBER_OF_CORNERS, r_order(CLEAR));
// set outline color to black
SDL_SetRenderDrawColor(
TheGame::Instance()->getRenderer(),
0, 0, 0, 255);
// draw the hex outline
//SDL_RenderDrawLines(
// TheGame::Instance()->getRenderer(),
// corners + 2,
// HEX_NUMBER_OF_CORNERS - 2);
// or
SDL_RenderDrawLine(
TheGame::Instance()->getRenderer(),
corners[2].x, corners[2].y,
corners[3].x, corners[3].y);
SDL_RenderDrawLine(
TheGame::Instance()->getRenderer(),
corners[3].x, corners[3].y,
corners[4].x, corners[4].y);
SDL_RenderDrawLine(
TheGame::Instance()->getRenderer(),
corners[4].x, corners[4].y,
corners[5].x, corners[5].y);
}
Just for clarity, it still occurs in spots where there should be a drawn line. This is a shot with the above code: