Hey Community,
I am trying to draw an area of a texture.
Drawing a texture on the normal way works fine with:
glTexCoord2f(0.0, 1.0); glVertex2f(_at.x, _at.y + dim.h);
glTexCoord2f(0.0, 0.0); glVertex2f(_at.x, _at.y);
glTexCoord2f(1.0, 0.0); glVertex2f(_at.x + dim.w, _at.y);
glTexCoord2f(1.0, 1.0); glVertex2f(_at.x + dim.w, _at.y + dim.h);
Now the area drawing code which fails: (width should not change, only the height orientation within the parent texture)
int n = dim.h / _odim.h;
int t = 3;
float topborder = (1 / n) * (t - 1);
float bottomborder = 1 - ((1 / n) * (n - t));
glTexCoord2f(0.0, bottomborder); glVertex2f(_at.x, _at.y + _odim.h); // bottom left
glTexCoord2f(0.0, topborder); glVertex2f(_at.x, _at.y); // top left
glTexCoord2f(1.0, topborder); glVertex2f(_at.x + _odim.w, _at.y); // top right
glTexCoord2f(1.0, bottomborder); glVertex2f(_at.x + _odim.w, _at.y + _odim.h); // bottom right
dim is the parent texture, means the "big" one, _odim is the area.
I divided the height of the original by the height of the region to get the number n which represents the ammount of the squares inside the main
texture. (important to understand : http://imgur.com/Ln1Blzh )
Then I randomly chose 3 as the the 3'rd square inside of the texture I want see. (Numerated first 7 in the picture for debug purpose)
Based on the glTexCoord2f which reaches from 0.0f to 1.0f I tought that I need to divide 1 by the ammount of squares possible for selection.
-> Topborder results out of the selected square - 1 times 1/n
-> Bottomborder is 1 minus 1/n times the ammount of squares minus the chosen one
And the glVertex2f are by common sized on the _odim.
Well then, what am I doing wrong to get this result:
http://img.prntscr.com/img?url=http://i.imgur.com/JgNC7e5.png
I realy expected something like this:
http://img.prntscr.com/img?url=http://i.imgur.com/KFYG3br.png
I hope to find an answer here, since I realy dont know.
,greetings