Hello friends.
I have a problem with texture mapping VBO.
did the mapping with blender and exported the information to a txt file then loaded into the software
[attachment=11263:mapeamento.png]
texture mapping
[attachment=11264:render.png]
blender render
[attachment=11265:resultado.png]
my render
Code of load texture
[source lang="cpp"]image = SDL_LoadBMP(filename);
if (image != NULL)
{
unsigned int size = sizeof(image->pixels);
colorFormat = TEXTURE_RGB;
dimension = TEXTURE_2D;
glGenTextures(1,&name);
glBindTexture (GL_TEXTURE_2D,name);
// set pixel unpacking mode
glPixelStorei (GL_UNPACK_SWAP_BYTES, 0);
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
data = malloc(size);
memcpy(&data,&image->pixels,size);
glTexImage2D (GL_TEXTURE_2D, 0, 3, image->w, image->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, data);
gluBuild2DMipmaps (GL_TEXTURE_2D, 3, image->w, image->h,
GL_RGB, GL_UNSIGNED_BYTE, data);
SDL_FreeSurface(image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glGenerateMipmap(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
}
void TexturePCX::bind ()
{
glBindTexture(GL_TEXTURE_2D,name);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV, GL_DECAL);
}
TexturePCX::~TexturePCX()
{
free(data);
//TODO : Liberar textura (OpenGL)
}
void TexturePCX::begin()
{
glEnable(GL_TEXTURE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,name);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV, GL_DECAL);
}
void TexturePCX::end()
{
glDisable(GL_TEXTURE);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);
}
[/source]
Vertex Buffer Objects draw
[source lang="cpp"]void VertexBufferObject::setVertices(vec3d *data,unsigned int size)
{
glGenBuffers( 1, &vertexBuffId);
glBindBuffer( GL_ARRAY_BUFFER, vertexBuffId );
vertices = data;
glBufferDataARB( GL_ARRAY_BUFFER, size * 3 * sizeof(float), data, GL_STATIC_DRAW_ARB );
}
void VertexBufferObject::setIndexs(unsigned int *data,unsigned int size)
{
glGenBuffers( 1, &indexBuffId );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffId );
indexs = data;
numIndices = size;
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER, size * sizeof(unsigned int), data, GL_STATIC_DRAW );
}
void VertexBufferObject::setNormals(float *data,unsigned int size)
{
glGenBuffers( 1, &normalBuffId );
glBindBuffer( GL_ARRAY_BUFFER, normalBuffId );
normals = data;
glBufferDataARB( GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW_ARB );
}
void VertexBufferObject::setTexCoords(TexCoord2 *data,unsigned int size)
{
glGenBuffers( 1, &texBuffId );
glBindBuffer( GL_ARRAY_BUFFER, texBuffId );
texCoord = data;
glBufferDataARB( GL_ARRAY_BUFFER, size * 2 * sizeof(float), data, GL_STATIC_DRAW_ARB );
}
void VertexBufferObject::draw()
{
if (vertexBuffId != 0 )
{
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffId);
glVertexPointer(3,GL_FLOAT,0,0);
}
if (indexBuffId != 0 )
{
glEnableClientState(GL_INDEX_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffId);
glIndexPointer(GL_UNSIGNED_INT,0,0);
// glBufferData()
}
if (normalBuffId != 0)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,0,normals);
}
if (texBuffId != 0)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_TEXTURE_COORD_ARRAY, texBuffId);
glTexCoordPointer(3,GL_FLOAT,0,0);
}
glDrawElements(glMode,numIndices,GL_UNSIGNED_INT,0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
VertexBufferObject::~VertexBufferObject()
{
}
[/source]
Cube information
Mesh: Cube.001
v: 1.000000 0.999999 1.000000
v: 1.000000 1.000000 -1.000000
v: -1.000000 1.000000 -1.000000
v: 1.000000 0.999999 1.000000
v: -1.000000 1.000000 -1.000000
v: -1.000000 1.000000 1.000000
v: -1.000000 -1.000000 -1.000000
v: -1.000000 -1.000000 1.000000
v: -1.000000 1.000000 1.000000
v: -1.000000 -1.000000 -1.000000
v: -1.000000 1.000000 1.000000
v: -1.000000 1.000000 -1.000000
v: 1.000000 -1.000000 -1.000000
v: 0.999999 -1.000001 1.000000
v: -1.000000 -1.000000 -1.000000
v: 0.999999 -1.000001 1.000000
v: -1.000000 -1.000000 1.000000
v: -1.000000 -1.000000 -1.000000
v: 1.000000 1.000000 -1.000000
v: 1.000000 0.999999 1.000000
v: 1.000000 -1.000000 -1.000000
v: 1.000000 0.999999 1.000000
v: 0.999999 -1.000001 1.000000
v: 1.000000 -1.000000 -1.000000
v: 1.000000 0.999999 1.000000
v: -1.000000 1.000000 1.000000
v: 0.999999 -1.000001 1.000000
v: -1.000000 1.000000 1.000000
v: -1.000000 -1.000000 1.000000
v: 0.999999 -1.000001 1.000000
v: 1.000000 1.000000 -1.000000
v: 1.000000 -1.000000 -1.000000
v: -1.000000 -1.000000 -1.000000
v: 1.000000 1.000000 -1.000000
v: -1.000000 -1.000000 -1.000000
v: -1.000000 1.000000 -1.000000
tex: h.bmp
t: 0.332314 0.000000
t: 0.333333 0.332314
t: 0.001020 0.333333
t: 0.332314 0.000000
t: 0.001020 0.333333
t: 0.000000 0.001020
t: 0.332314 0.333333
t: 0.333333 0.665647
t: 0.001020 0.666667
t: 0.332314 0.333333
t: 0.001020 0.666667
t: 0.000000 0.334353
t: 0.334353 0.333333
t: 0.333333 0.001020
t: 0.666667 0.332314
t: 0.333333 0.001020
t: 0.665647 0.000000
t: 0.666667 0.332314
t: 0.998981 0.000000
t: 1.000000 0.332314
t: 0.666667 0.001019
t: 1.000000 0.332314
t: 0.667686 0.333333
t: 0.666667 0.001019
t: 1.000000 0.334353
t: 0.998980 0.666667
t: 0.667686 0.333333
t: 0.998980 0.666667
t: 0.666667 0.665647
t: 0.667686 0.333333
t: 0.665647 0.333333
t: 0.666667 0.665647
t: 0.334353 0.666667
t: 0.665647 0.333333
t: 0.334353 0.666667
t: 0.333333 0.334353
End:
thanks for help.
Texture maping problem with vertex buffer object
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement