Followers 0

# How to keep straight line straight while mapping to non rectangular area

## 4 posts in this topic

Hi, everyone.  I tried to map a rectangular image to a non-rectangular area(considerring perspective). But the straght line in the image became bent in the result. I have tried change the filter from linear to nearest, neight of them worked.

Here is my drawing code

void vedioMap(){
//delete
float* t;
float a,b;
//vedioTexIds[0]
glDisable(GL_CULL_FACE);
glPolygonOffset(-1.f,-1.f);
glEnable(GL_POLYGON_OFFSET_FILL);

glBindTexture(GL_TEXTURE_2D, vedioTexIds[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

//GL_POLYGON, GL_TRIANGLES
FOR(i,4) {
glTexCoord2f(screenCoord[i][0], screenCoord[i][1]);
glVertex3fv(worldCoord[0][i].data());
}
glEnd();

glDisable(GL_POLYGON_OFFSET_FILL);
}


The origin image is east1 and the result is another  in the  attach files.

So my question is how to keep the straight line straight?

Thanks!

0

##### Share on other sites

If you need to add perspective on top of something that doesn't have perspective itself, you need to add that additional perspective information to the texture coordinates instead. See this.

2

##### Share on other sites

If you need to add perspective on top of something that doesn't have perspective itself, you need to add that additional perspective information to the texture coordinates instead. See this.

I changed the code to

	glBegin(GL_QUADS);
glTexCoord2f(0.f, 0.f);
glVertex3fv(worldCoord[0][0].data());

glTexCoord4f(texWidth[0], 0.f, 0.f, texWidth[0]);
glVertex3fv(worldCoord[0][1].data());

glTexCoord2f(1.f, 1.f);
glVertex3fv(worldCoord[0][2].data());

glTexCoord4f(0.f, texHeight[0], 0.f, texHeight[0]);
glVertex3fv(worldCoord[0][3].data());
glEnd();


the texWidth and the texHeight is defined as (maxX/maxY - minX/minY) of vertex.

the result is this:

the up left triangle is black.

the example I seen is all about trapezoidal. but is it possible for a irregular quad like mine?

0

##### Share on other sites

Can someone give an example. Taking the four vetex coord as input, how to use glTexCoord4f?

0

##### Share on other sites

Can someone give an example. Taking the four vetex coord as input, how to use glTexCoord4f?

I found this post . It mentioned about perspective-correct interpolation and the method to calculate q (texQ[0]).

My final code is

	glBegin(GL_QUADS);
glTexCoord4f(0.f, 0.f, 0.f, texQ[0][0]);
glVertex3fv(worldCoord[0][0].data());

glTexCoord4f(texQ[0][1], 0.f, 0.f, texQ[0][1]);
glVertex3fv(worldCoord[0][1].data());

glTexCoord4f(texQ[0][2], texQ[0][2], 0.f, texQ[0][2]);
glVertex3fv(worldCoord[0][2].data());

glTexCoord4f(0.f, texQ[0][3], 0.f, texQ[0][3]);
glVertex3fv(worldCoord[0][3].data());
glEnd();

Edited by tonemgub
0

## Create an account

Register a new account