So my question is exactly like the title states. I'm not looking for a concrete code example, just some thoughts/guidelines on any preferred methods of doing this.
In my 2D game engine, I like to have a grid that represents a certain amount of pixels (e.g 32x32 pixels). I specifically want to be able to define, the width and height of each grid in world space, have a consistent stroke width on all the lines, and be able to adjust the tile size according to camera zoom.
I've tried several different methods in the past to draw this grid:
The first thing I tried was using a custom shader to draw a grid. I found some code online that used some concepts I didn't understand to just draw the grid on a 2D plane. The problems with this approach are that I didn't know how to control the exact size in my game world, and didn't understand how it worked in general.
My second approach was to use my debug drawing facilities. I coded a suite of functions that allows me to add lines of different stroke widths in world space, and I implemented that by just dynamically generating quads for each line every frame. I can then draw a bunch of lines which gives me a grid.
My third approach was to draw a bunch of quads, and use a custom shader to give them an outline. Then I just draw a bunch of white quads with black outlines, giving the appearance of a grid.
Does anybody have a better solution? In all my approaches I have never tried to adjust the grid dynamically according to the camera's zoom level either. So any thoughts on whether these approaches are the typical solutions, or if there is a better one would be much appreciated. Also, if you have any thoughts on how to extend these methods to 3D space that would also be nice, I can't seem to find a good way to get a uniform stroke width on lines drawn in world space.
My engine is currently being coded using Opengl and C++ too, so I'm primarily concerned on how to implement this using modern opengl, not immediate mode.
Here's an image of what I'm trying to achieve:
Edit: I am primarily concerned with rendering techniques. Do you use several quads? One plane and a complex shader? Or do you use a quad for each line? Or something else entirely?
This is one of my attempts, for another reference of the look and feel I'm trying to achieve. I just can't help but think there has to be a better method then the ones I've tried.