Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

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

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 / slalrbalr   Banned   

2008
Like
0Likes
Like

Posted 18 July 2014 - 02:41 AM

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!

Attached Thumbnails

  • east1.rmvb_20140707_103835.440.jpg
  • 图像 8.png


#2 Brother Bob   Moderators   

10277
Like
2Likes
Like

Posted 18 July 2014 - 02:47 AM

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.



#3 / slalrbalr   Banned   

2008
Like
0Likes
Like

Posted 21 July 2014 - 02:50 AM

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?



#4 / slalrbalr   Banned   

2008
Like
0Likes
Like

Posted 21 July 2014 - 03:41 AM

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



#5 / slalrbalr   Banned   

2008
Like
0Likes
Like

Posted 21 July 2014 - 08:41 PM

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, 21 July 2014 - 08:42 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.