Trapezoid uvs preservation
So what have you tried to to se the texture coordinates to? It looks like the texture coordinates you posted previously, but as I said, and as the link explained, you need to adjust the coordinates for the perspective effect.
I have tried to modified the coords as you suggested, but it did not help.
so then I decided to try the brute force, but did not make any progress on that way
so then I decided to try the brute force, but did not make any progress on that way
SetPoints( vec3<float>(-20.0f , -10.0f, 0.0f), // BottomLeft,
vec3<float>(-10.0f , 10.0f, 0.0f), // TopLeft,
vec3<float>( 10.0f , 10.0f, 0.0f), // TopRight,
vec3<float>( 20.0f , -10.0f, 0.0f) );// BottomRight
vTxCoords_.push_back(vec4<float>( 0.0f , 0.0f,0.0f,1.0f));
vTxCoords_.push_back(vec4<float>( 0.0f , 0.5f,0.0f,0.5f));
vTxCoords_.push_back(vec4<float>( 0.5f , 0.5f,0.0f,0.5f));
vTxCoords_.push_back(vec4<float>( 1.0f , 0.0f,0.0f,1.0f));
I changed the r component, to 0.
//Setup
SetPoints( vec3<float>(-20.0f , -10.0f, 0.0f), // BottomLeft,
vec3<float>(-10.0f , 10.0f, 0.0f), // TopLeft,
vec3<float>( 10.0f , 10.0f, 0.0f), // TopRight,
vec3<float>( 20.0f , -10.0f, 0.0f) );// BottomRight
vTxCoords_.push_back(vec4<float>( 0.0f , 0.0f,0.0f,1.0f));
vTxCoords_.push_back(vec4<float>( 0.0f , 0.5f,0.0f,0.5f));
vTxCoords_.push_back(vec4<float>( 0.5f , 0.5f,0.0f,0.5f));
vTxCoords_.push_back(vec4<float>( 1.0f , 0.0f,0.0f,1.0f));
Face s;
s.uIndex[0] = 0; s.uIndex[1] = 1; s.uIndex[2] = 3;
pGeo->vFaces.push_back(s);
s.uIndex[0] = 3; s.uIndex[1] = 2; s.uIndex[2] = 1;
pGeo->vFaces.push_back(s);
uiDrawFacesStartPos = 0;
uiDrawFacesEndPos = pGeo->vFaces.size();
//Draw
... Get/Set the attributes
unsigned int *ptr = &pGeo->vFaces[ uiDrawFacesStartPos ].uIndex[ 0 ];
unsigned int sz = (unsigned int)( uiDrawFacesEndPos - uiDrawFacesStartPos ) *3;
glDrawElements( GL_TRIANGLES, sz, GL_UNSIGNED_INT, ptr );
The shader is very basic, just use the varying textCoord in the function texture2D
diffuse = texture2D( DiffuseColor, vOutTxCoords.xy ).rgb;
if more information is needed, please update me.
tnx
Well, you haven't looked at the source code, or you haven't studied it in any depth.
The code clearly suggests (without reading the article) that the texture coordinates depend on the vertex coordinates. You just use independent values for the coordinates. I don't really understand why can't you just copy the coordinates and calculations from the source code (I know it's not a good way to learn, but et least you had something that you can experiment with).
The code clearly suggests (without reading the article) that the texture coordinates depend on the vertex coordinates. You just use independent values for the coordinates. I don't really understand why can't you just copy the coordinates and calculations from the source code (I know it's not a good way to learn, but et least you had something that you can experiment with).
Well I already tried that:
the above code does exactly the same as the tutorial.
you can see on the attachment the result I got.
I have noticed that GL_PERSPECTIVE_CORRECTION_HINT is not available at ES.
maybe its the way I'm drawing may tri's ?
// Setup
// Globals
float top = .3;
float scale_texcoord = 1.f;
vTxCoords_.push_back(vec4<float>( -1.0f , -1.0f ,0.0f,1.0f));
vTxCoords_.push_back(vec4<float>( -1.0f , 1.0f ,0.0f,1.0f));
vTxCoords_.push_back(vec4<float>( 1.0f , 1.0f ,0.0f,1.0f));
vTxCoords_.push_back(vec4<float>( 1.0f , -1.0f ,0.0f,1.0f));
SetPoints( vec3<float>( -1.0f , -1.0f, 0.0f), // BottomLeft,
vec3<float>( -1.0f , 1.0f, 0.0f), // TopLeft,
vec3<float>( 1.0f , 1.0f, 0.0f), // TopRight,
vec3<float>( 1.0f , -1.0f, 0.0f) );// BottomRight
Face s;
s.uIndex[0] = 0; s.uIndex[1] = 1; s.uIndex[2] = 3;
pGeo->vFaces.push_back(s);
s.uIndex[0] = 3; s.uIndex[1] = 2; s.uIndex[2] = 1;
pGeo->vFaces.push_back(s);
uiDrawFacesStartPos = 0;
uiDrawFacesEndPos = pGeo->vFaces.size();
//Draw
... Get/Set the attributes
unsigned int *ptr = &pGeo->vFaces[ uiDrawFacesStartPos ].uIndex[ 0 ];
unsigned int sz = (unsigned int)( uiDrawFacesEndPos - uiDrawFacesStartPos ) *3;
glDrawElements( GL_TRIANGLES, sz, GL_UNSIGNED_INT, ptr );
// Update Func
unsigned char keys[256];
GetKeyboardState( keys );
if( keys['1'] & 0x80 )
{
top += .05;
}
if( keys['2'] & 0x80 )
{
top -= .05;
}
float tx = scale_texcoord * top;
// Frist Triangle
pGeo->vGSVerts[0] = vec3<f32>(-1.0f , -1.0f, 0.0f);
pGeo->vGSVerts[1] = vec3<f32>(-top,1,0);
pGeo->vGSVerts[2] = vec3<f32>( top,1,0);
pGeo->vGSVerts[3] = vec3<f32>(1.0f , -1.0f, 0.0f);
vTxCoords_[1].x = -tx;
vTxCoords_[1].y = tx;
vTxCoords_[1].z = 0;
vTxCoords_[1].w = tx;
vTxCoords_[2].x = tx;
vTxCoords_[2].y = tx;
vTxCoords_[2].z = 0;
vTxCoords_[2].w = tx;
the above code does exactly the same as the tutorial.
you can see on the attachment the result I got.
I have noticed that GL_PERSPECTIVE_CORRECTION_HINT is not available at ES.
maybe its the way I'm drawing may tri's ?
Hmmmm. Is your texture a 8x8 checked texture?
If you, we should see a 16x16 checked texture stretched onto the trapezoid. But the texture is totally off, but the coordinates you specify look okay.
I don't see the problem but I don't think GL_PERSPECTIVE_CORRECTION_HINT has to do anything with that.
If you, we should see a 16x16 checked texture stretched onto the trapezoid. But the texture is totally off, but the coordinates you specify look okay.
I don't see the problem but I don't think GL_PERSPECTIVE_CORRECTION_HINT has to do anything with that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement