drawing an onscreen grid

P

Peted

hi

im doing some stuff in visula c++ 2008

Im hoping someone can direct me to an algorithm to draw an onscreen
grid that has equal squares like a testpattern regardless of the
current resolution

I can get the curren screen res
I can draw a grid ok to

but i cant work out how to draw a neat grid with all the squares equal
size, all fitting neatly onscreen with no cut offs. the squares dont
have to be any specific size (other than i want to have 2
testpatterns, on with "large" squares and one with "small squares")
but they all need to be equal with no cutoffs

and it has to be calculated in any screen resolution a user may
select.

any advice appreciated

thanks

Peted
 
B

Ben Voigt [C++ MVP]

hi

im doing some stuff in visula c++ 2008

Im hoping someone can direct me to an algorithm to draw an onscreen
grid that has equal squares like a testpattern regardless of the
current resolution

I can get the curren screen res
I can draw a grid ok to

but i cant work out how to draw a neat grid with all the squares equal
size, all fitting neatly onscreen with no cut offs. the squares dont
have to be any specific size (other than i want to have 2
testpatterns, on with "large" squares and one with "small squares")
but they all need to be equal with no cutoffs

and it has to be calculated in any screen resolution a user may
select.

Take the screen resolution, divide by the number of squares you want?

Just about all screen resolutions are either 4:3 or 16:9 aspect ratio.

You might also use the modulo operator (%) to help you find a number that
the screen resolution components are evenly divisible by.

example:

for( squaresize = screenxres / 16; (screenxres % squaresize) || (screenyres
% squaresize); squaresize-- )
;

should give you
16x12 squares of 64 pixels each on 1024x768
16x12 squares of 50 pixels each on 800x600
16x12 squares of 100 pixels each on 1600x1200
20x16 squares of 64 pixels each on 1280x1024
18x12 squares of 80 pixels each on 1440x960
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top