0
$\begingroup$

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

$\endgroup$
6
  • 2
    $\begingroup$ 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. $\endgroup$
    – lightxbulb
    Feb 13, 2019 at 19:26
  • 1
    $\begingroup$ What part are you having trouble with? Have you done texture mapping in OpenGL before? Do you have code loading the geometry already? $\endgroup$ Feb 14, 2019 at 2:15
  • $\begingroup$ @user1118321 I have not done texture mapping in OpenGL before. $\endgroup$
    – Trial
    Feb 14, 2019 at 6:32
  • $\begingroup$ @lightxbulb an obj file contains vt - which apparently are the texture coordinates. $\endgroup$
    – Trial
    Feb 14, 2019 at 6:45
  • 2
    $\begingroup$ @Trial Have you successfully loaded the vertex co-ordinates from your file? What code do you have working now? $\endgroup$
    – Dan Hulme
    Feb 14, 2019 at 9:48

2 Answers 2

3
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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/.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.