Domanda

I used Blender for create 3D modal. I created .obj file and converted to .h file but .h file having only glVertexPointer, glDrawArrays. I used .png image file. But when image is tracking the 3D modal doesn't displays proper. It's some what black color. How to create texture coordinates using blender or if i import .obj file any other software will create texture coordinates

/*

created with obj2opengl.pl

source file    : .\Sample.obj

vertices       : 8428

faces          : 14040

normals        : 0

texture coords : 0

// include generated arrays

#import ".\Sample.h"

// set input data to arrays

glVertexPointer(3, GL_FLOAT, 0, SampleVerts);

// draw data

glDrawArrays(GL_TRIANGLES, 0, SampleNumVerts);

*/

unsigned int SampleNumVerts = 42120;

float SampleVerts [] = {

  // f 2 1 3 4

  -0.233114614641671, 0.446055325439014, 0.223483335097295,

  0.266885385358329, 0.446055325439014, 0.223483335097295,

  0.266885385358329, 0.446055325439014, -0.276516664902705,

  // f 2 1 3 4

  -0.233114614641671, 0.446055325439014, 0.223483335097295,

  -0.233114614641671, 0.446055325439014, -0.276516664902705,

  0.266885385358329, 0.446055325439014, -0.276516664902705,

  // f 6 5 7 8



...........



}
È stato utile?

Soluzione

You need to export your model with texture coordinates from Blender (not a topic thats relevant here. Blenders tutorials should answer that for you). When converting to a .h (not sure what you used to do that) make sure you aren't skipping UV's/Texture Coordinates. Put them in an array too which I'll call SampleUVs.

You should add this just before you call glDrawArrays, after glVertexPointer:

glTexCoordPointer(3, GL_FLOAT, 0, SampleUVs);

That enables texture coordinates from the array SampleUVs. The 3 represents x,y,z texture coordinates (change to 2 for x,y only).

You also need to import the texture and bind it to a texture. I would suggest you properly read some tutorials on basic model loading and texturing. There are many around, although this is my favourite:

http://nehe.gamedev.net/tutorial/texture_mapping/12038/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top