View Full Version : Texture correction :O
04-24-2012, 10:34 AM
Please can someone help me understand glTexCoord4f(s,t,r,q)? Ive posted this before but couldnt find a answer for my problem. I want to know how to get the right values for s,t,r,q in texture coordinate. What I am trying to do is get a perspective correction for my texture when i map it into a trapezoid .
Here is a link to my last post about this topic. Btw,thanks everybody who read this!
04-24-2012, 01:59 PM
I've answered your question already in your earlier post.
The problem is that your Z and W coordinates for the vertices are 0.f and 1.f respectively thus the GPU thinks that the points rely in the same plane parallel to the near plane thus it thinks that it does not require any perspective correction.
You need to set your Z and W coordinates (together with your X and Y coordinates) using a proper projective transformation that transforms a square/rectangle into your trapezoid.
Please don't open a new thread for the same question, especially if your question was already answered.
04-26-2012, 07:04 PM
Thanks for your help in both post. Sorry you are right I shouldnt have post this again.!
Like I said before I dont know how to do that which you are specifying me to do. Any sample you can give me would be great... or i.e. how should i get the right values for this:
glTexCoord2f(0.0f,1.0f); glVertex3f(2.5f,1.0f, 0.0f); // Top Left Of The Texture and Quad
glTexCoord2f(1.0f,1.0f);glVertex3f(-1.0f,1.4f, 0.0f); // Top Right Of The Texture and Quad
glTexCoord2f(1.0f,0.0f);glVertex3f(1.2f,0.0f 0.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(0.0f,0.0f);glVertex3f(-0.4f,-0.5f 0.0f); // Bottom Left Of The Texture and Quad
I know I have to use glTexCoord4f to get the right perspective but i dont know how to set the q coordinate :$.... Do you know how to do this?
Ive seen this article: http://www.xyzw.us/~cass/qcoord/
I kinda understand how it works but not totally sure. Another thing is the example provided works only if the top has the same values, you can see that when running the sample.
Again thanks so much for your help and I will aprreciate any advice you can give me :D
04-26-2012, 09:02 PM
Umer, you're mishearing. You do not want to use glTexCoord. You have drawn a flat quad, on one plane, and you want it to act like it's in a 3D space. Adjust the vertices - not the texture coordinates - to take a square and tilt it in the 3D space until it looks like a trapezoid from your camera position. Now the trivial texture coordinates will just work.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.