2

我必须创建将射击加特林枪的动画(它不必很复杂,因为它只是一种练习)。我画了我的枪的基本版本,如下所示:

加特林机枪

Don't bother colors - i made them like that to be able to see where are egdes of particular parts of gun. Now i would like to make it look better by using some texture - moro or something like metalic color - example 1 or example2. I know how to load texture and how to use it for 2d objects, but i have no idea if there is a possiblity to use this texture for my whole drawing or do i have to use texture for every part separately? This is my code which corresponds to load texture from bmp file and make it able to use:

void initTexture(string fileName)
{
    loadBmp(fileName.c_str());
    textureId = 13;
    glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    //Map the image to the texture
    glTexImage2D(GL_TEXTURE_2D,                //Always GL_TEXTURE_2D
                 0,                            //0 for now
                 GL_RGB,                       //Format OpenGL uses for image
                 tex.info.biWidth, tex.info.biHeight,  //Width and height
                 0,                            //The border of the image
                 GL_RGB, //GL_RGB, because pixels are stored in RGB format
                 GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
                                   //as unsigned numbers
                 tex.px);               //The actual pixel data

}

loadBmp() is function to load bitmap file. I tried to search something in the Internet and stackoverflow, but all exmaples where about cubes or spheres, which doesn't help me. How can i put texture on this drawing?

4

1 回答 1

2

纹理映射需要(手动)为每个顶点分配纹理坐标。有一些方法可以自动生成纹理坐标,或者在没有纹理坐标的情况下逃脱,方法是给每个面一个单独的像素(迪士尼动画公司在他们的计算机动画电影中率先采用了后一种方法)。

由于您没有指定用于建模的程序,我将向您推荐一些有关 Blender 纹理 UV 映射的教程

http://wiki.blender.org/index.php/Doc:2.6/Manual/Textures/Mapping/UV/Unwrapping

请不要告诉我你确实“编码”了你的枪,因为这是错误的,错误的,错误的!

一旦获得纹理坐标,您就可以将它们作为另一个顶点属性传递给 OpenGL。

于 2013-04-16T22:55:58.407 回答