<p>The OBJ file itself doesn't contain the texture, only the texture co-ordinates (which describe how to map a texture onto the surface of the mesh.) The texture is an image file (such as a PNG) whose path is given by the accompanying .mtl file. You need to parse the .mtl file to get the path to the image file, then use an image-loading library (such as DevIL) to load the image into memory. Once you have the pixels of the image, you can use <code>glTexImage2D</code> to load that image into a texture, which can be accessed from your fragment shader using a <code>sampler2D</code>.</p>

CC BY-SA 4.0
2019-02-14T13:42:31.297Z
2019-02-14T13:42:31.297Z
Dan Hulme
<p>If you are using vertex arrays and shaders, your vertices (v) can be indexed and stored in an element array buffer and your texture coordinates should be pass to the vertex shader to be send and used by the fragment shader. I recommend you to visit the site <a href="https://learnopengl.com/" rel="nofollow noreferrer">https://learnopengl.com/</a>.</p>

CC BY-SA 4.0
2019-02-14T04:19:59.877Z
2019-02-14T04:19:59.877Z
user2309000
<p>I have an obj file, with texture coordinates (indicated by vt). How would I use this to load textures in OpenGL?</p>

CC BY-SA 4.0
2019-02-13T19:26:41.357Z
What's vt? Also uv coordinates just tell you how to map the texture on the triangle, not hold to load textures. You can use any texture.
lightxbulb
CC BY-SA 4.0
2019-02-14T02:15:56.953Z
What part are you having trouble with? Have you done texture mapping in OpenGL before? Do you have code loading the geometry already?
user1118321
CC BY-SA 4.0
2019-02-14T06:32:18.327Z
@user1118321 I have not done texture mapping in OpenGL before.
Trial
CC BY-SA 4.0
2019-02-14T06:45:53.247Z
@lightxbulb an obj file contains vt - which apparently are the texture coordinates.
Trial
CC BY-SA 4.0
2019-02-14T09:48:55.720Z
@Trial Have you successfully loaded the vertex co-ordinates from your file? What code do you have working now?
Dan Hulme
CC BY-SA 4.0
2019-02-14T12:26:31.463Z
@DanHulme I have successfully loaded the vertex coordinates from the obj file, so I am able to load the model and render it, but not it's texture, so it comes only of a uniform color. I don't know how to get the texture.
Trial
<opengl>
How do I use texture coordinates of a .obj file in OpenGL?
Trial
# How do I use texture coordinates of a .obj file in OpenGL?

(Asked by: username_0 on 2019-02-13)

I have an obj file, with texture coordinates (indicated by vt). How would I use this to load textures in OpenGL?

**Tags:** opengl

> **Comments:**
> **username_1**: What's vt? Also uv coordinates just tell you how to map the texture on the triangle, not hold to load textures. You can use any texture.  
> **username_2**: What part are you having trouble with? Have you done texture mapping in OpenGL before? Do you have code loading the geometry already?  
> **username_0**: @username_2 I have not done texture mapping in OpenGL before.  
> **username_0**: @username_1 an obj file contains vt - which apparently are the texture coordinates.  
> **username_3**: @username_0 Have you successfully loaded the vertex co-ordinates from your file? What code do you have working now?  
> **username_0**: @username_3 I have successfully loaded the vertex coordinates from the obj file, so I am able to load the model and render it, but not it's texture, so it comes only of a uniform color. I don't know how to get the texture.  

---

## 2 answers

### Answer by username_3 on 2019-02-14. Score: 3 | Accepted answer

The OBJ file itself doesn't contain the texture, only the texture co-ordinates (which describe how to map a texture onto the surface of the mesh.) The texture is an image file (such as a PNG) whose path is given by the accompanying .mtl file. You need to parse the .mtl file to get the path to the image file, then use an image-loading library (such as DevIL) to load the image into memory. Once you have the pixels of the image, you can use `glTexImage2D` to load that image into a texture, which can be accessed from your fragment shader using a `sampler2D`.


---

### Answer by username_4 on 2019-02-14. Score: 1

If you are using vertex arrays and shaders, your vertices (v) can be indexed and stored in an element array buffer and your texture coordinates should be pass to the vertex shader to be send and used by the fragment shader. I recommend you to visit the site <https://learnopengl.com/>.


---

