• Advertisement
Sign in to follow this  

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

This topic is 1281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
	glBegin(GL_QUADS);
	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!

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
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.

 

Thanks for the reply!

 

 

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:

13.png

 

the up left triangle is black.

 

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement