6 Replies - 1067 Views - Last Post: 14 April 2014 - 09:50 PM Rate Topic: -----

#1 pbivens85  Icon User is offline

  • D.I.C Regular

Reputation: -4
  • View blog
  • Posts: 410
  • Joined: 22-October 13

texture

Posted 13 April 2014 - 03:44 PM

I am trying to paint a space ship to the screen using texturing. I just want to know what the glTexCoord2f command does. I googled it but I am still a little confused.
Is This A Good Question/Topic? 0
  • +

Replies To: texture

#2 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: texture

Posted 13 April 2014 - 04:35 PM

Ok. So first of all, I have no idea. But it looks like it's deprecated.

But if you're going to use it anyway, I think it's just UV coordinates. UV coordinates are fairly simple.

Basically, what you're doing is drawing triangles. You could draw a color across the face of the triangle, but with UV coordinates you're going to map a photograph to the surface of the triangle.

In a triangle, you have 3 vertices. Each vertex gets a UV coordinate for that vertex. The UV coordinate maps to a "texel" in the image. Texels are like pixels except that pixels are screen elements and texels are image elements. They may or may not map 1 to 1 to a pixel depending on whether you enlarge or reduce the image on the screen.

Anyway, the UV coordinates map to positions in the square image. Those positions in the square image map to vertices of the triangle and it will draw the image across that triangle between those three points. So the triangle gets drawn with the image. Again, a UV coordinate is assigned to each vertex and it maps which point in the picture corresponds to that vertex. The rasterizer and sampler do the job of drawing everything between those 3 points and stretching the image across the triangle.

Generally one corner of the image will have UV coordinates 0,0 and the opposite corner will have the coordinates 1,1. Texels in between will have a fraction of those positions.

There's a whole process called UV Unwrapping when you are making models in a modeling program where you create a UV map that matches up with the vertices of all the triangles in the mesh. It's like flattening out an orange peel to be flat because the 3D surfaces have to be flattened out to match a 2D picture.

You can also use negative numbers which tend to draw the image "backwards". Or you can use numbers beyond 1 which will repeat the image a certain number of times depending on the settings.

Does that help?

You can google UV coordinates and probably get more info.

This post has been edited by BBeck: 13 April 2014 - 04:36 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbivens85  Icon User is offline

  • D.I.C Regular

Reputation: -4
  • View blog
  • Posts: 410
  • Joined: 22-October 13

Re: texture

Posted 13 April 2014 - 06:06 PM

I am trying to get a quad to move back and forth across the bottom of the screen, I have tried many things but I need a new set of eyes to look at my code.
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_QUADS);
	
//	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-1.0f+scroll, -10.0f, 0.0f);
//	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-1.0f+scroll, -8.0f, 0.0f);
//	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(1.0f+scroll, -8.0f, 0.0f);
//	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(1.0f+scroll, -10.0f, 0.0f);

	glEnd();

//	glDisable(GL_TEXTURE_2D);

	glutSwapBuffers();
}

void handleSpecialKeypress(int key, int x, int y) {
	switch (key) {
	case GLUT_KEY_LEFT: //Left key
	scroll -= 0.1f;
	break;
	case GLUT_KEY_RIGHT: //Right key
	scroll += 0.1f;
	break;
	}
}


Was This Post Helpful? 0
  • +
  • -

#4 pbivens85  Icon User is offline

  • D.I.C Regular

Reputation: -4
  • View blog
  • Posts: 410
  • Joined: 22-October 13

Re: texture

Posted 13 April 2014 - 07:06 PM

YEAH!! after much work I solved my problem, I just had to include the glutPostredisplay command.
Was This Post Helpful? 1
  • +
  • -

#5 pbivens85  Icon User is offline

  • D.I.C Regular

Reputation: -4
  • View blog
  • Posts: 410
  • Joined: 22-October 13

Re: texture

Posted 14 April 2014 - 03:28 PM

I know this is deprecated but I still want to know what this command does.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Was This Post Helpful? 0
  • +
  • -

#6 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: texture

Posted 14 April 2014 - 05:08 PM

So, I'm totally guessing here, but its an educated guess. I've done this sort of thing in XNA. It's amazing how much XNA prepares you for this stuff.

glTexParameteri sets a parameter for texturing a triangle. The I at the end stands for integer parameter. The first parameter of this function specifies whether this is a 2D texture or a cube map. It's going to be a texture.

The way you specified it, this is going to be about minification and the minification method is going to be "nearest".

When you map a texture to a triangle, or to a mesh/model, it's not going to be 1 to 1. Think about creating a quad for a mesh such as a square. You make this square mesh and you texture it with a square texture. Even if it maps exactly to the square, the camera can move closer to it or further away from it. As you move closer, this is called magnification and 1 texel in the image occupies more and more pixels on your computer monitor as you get closer. So, pixels have to be "generated" that were not there in the original image to make this magnification process work.

When you move further away, that's called minification and eventually you get to the point where one pixel on the screen may be several texels in the original image because it's so far away. You have to average out the pixels to come up with an average to display it as one pixel on the screen. Eventually, the entire image may be so far away that the whole image is only one pixel on the screen.

Mipmapping is related to this. But you have minification even without mipmaps.
Was This Post Helpful? 0
  • +
  • -

#7 laytonsdad  Icon User is offline

  • Let it rip!
  • member icon

Reputation: 466
  • View blog
  • Posts: 1,992
  • Joined: 30-April 10

Re: texture

Posted 14 April 2014 - 09:50 PM

This may also be of use.

glTexParameteri(GLenum target, GLenum pname, GLint param)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1