PDA

View Full Version : Image pattern hatch - scale problem ?



AllForum
12-23-2014, 08:08 AM
Hello,

I have image patterns (8x8, 16x16 or 32x32) like this : pattern (http://asymptote.sourceforge.net/doc/hatch.png)
It is to hatch polygon like this : hatched polygon (http://www.aplicit.com/wp-content/uploads/hachures-poignees_resultat.jpg)
The result is on the joined image. The pattern seems too small : I have to zoom to see it.

My question is how to manage the size of the pattern ?

I join some code if something is wrong.
I load the image and create a mipmap. Then setting the texture to the polygon is done in its display list.
Create the mipmap :

glBindTexture(GL_TEXTURE_2D, TextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glEnable(GL_TEXTURE_2D);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, lWidthPixels, lHeightPixels, 0, GL_RGBA, GL_UNSIGNED_BYTE, pBits);
glGenerateMipmap(GL_TEXTURE_2D);
Fill the polygon :

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, s_vector);

glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, t_vector);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);


Thanks in advance for your help.

GClements
12-23-2014, 11:47 AM
The result is on the joined image. The pattern seems too small : I have to zoom to see it.

My question is how to manage the size of the pattern ?

The size in eye space will be affected by the magnitude of the plane coefficients (s_vector, t_vector), the model-view matrix at the time that glTexGen is invoked, and the texture matrix.

The size in clip space will additionally be affected by the projection matrix at rendering time.

If the texture matrix and model-view matrix have unit scale (i.e. consist only of rotations and translations), and the vector portion of the plane coefficients has unit magnitude, then the spacing between adjacent copies of the texture will be one unit in model space.

If you want to make the spacing larger by some factor K, make the plane coefficients smaller by that factor (i.e. divide by K), or add a scaling of 1/K to the texture matrix.

AllForum
12-24-2014, 03:12 AM
Thank you for your explanation : I now know what I have to look (or change) in the code (not mine).
Thanks.