简体   繁体   中英

Opengl ES how to import a 3D model and map textures to it on runtime

it's a bit cheating, because there is actually two questions in the title.

on the account of how to import a 3D model i think i can get through that bit.

however, my question is: can i map a texture to the imported model at runtime ?

isn't this called UV-Mapping ?

the 3D model is basically a sphere, is it better to generate the sphere using OpenGL ES ?

but then how do i map a texture to it ?

Sorry for being ignorant about most of the basics.

Are you using straight OpenGL or an engine? In case you're using an engine, some of this might already be solved for you.

If you're using straight OpenGL, you have to keep in mind that it is "merely" a rendering API. So you'll still have to do a lot of the leg work yourself.

To import a 3D model you'll have to

  • Create some sort of mesh data structure
  • Write a loader (the OBJ file format is a nice place to start) which takes a file and loads it into your data structure
  • Write the rendering code which will take the data you have loaded and renders it out.

And yes, you can texture map your mesh. What you will need to have are texture (UV) coordinates. These basically map the vertices in your mesh to a location on your 2D texture. Imagining a sphere models the earth, the UV coordinates map the vertices to a specific location on the 2D map of the earth.

You can perhaps generate those in code for a 3D sphere, but modeling packages can help you there as well, especially for more complex 3D objects. For somewhat of a visual introduction, have a look at this tutorial on UV mapping related to Blender.

An OpenGL ES tutorial on textures and texture mapping can be found here .

You can load 3d models using two ways

1. Write a loader to parse all vertices and texture coordinates.
2. Use blender to export your model as header files.

  1. Convert 3d model to wavefront object format. Use/Write a library to parse obj files to vertices and texture coordinates.

  2. Use following library to generate C header files and import to your project

Then load the model and apply texture..

Try to learn some basics

Read these tutorials ..

I'm not maintaining these links and I can't guarantee existence of these links in future. At the time of updating these answers, these links are valid. If you find these links are broken, be a sensible editor rather than complainer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM