Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 基于土壤的opengl纹理图谱区域提取_C++_Opengl_Mapping_Textures_Soil - Fatal编程技术网

C++ 基于土壤的opengl纹理图谱区域提取

C++ 基于土壤的opengl纹理图谱区域提取,c++,opengl,mapping,textures,soil,C++,Opengl,Mapping,Textures,Soil,我想用opengl使用土壤将纹理图集的不同区域映射到立方体的不同侧面。到目前为止,我成功地将单个图像映射到立方体的一侧: int LoadTexture(const char*); int texID; void DrawCube(float width) { float wd2 = width / 2; glColor3f(0, 0, 1); glBegin(GL_QUADS); //front glTexCoord2f(0, 1); gl

我想用opengl使用土壤将纹理图集的不同区域映射到立方体的不同侧面。到目前为止,我成功地将单个图像映射到立方体的一侧:

int LoadTexture(const char*);

int texID;

void DrawCube(float width)
{
    float wd2 = width / 2;
    glColor3f(0, 0, 1);
    glBegin(GL_QUADS);

    //front
    glTexCoord2f(0, 1);
    glVertex3f(-wd2, -wd2, wd2);
    glTexCoord2f(1, 1);
    glVertex3f(wd2, -wd2, wd2);
    glTexCoord2f(1, 0);

    glVertex3f(wd2, wd2, wd2);
    glTexCoord2f(0, 0);

    glVertex3f(-wd2, wd2, wd2);

    //left side..
    //right side..
    //back..
    //top..
    //bottom..

    glEnd();
}

int LoadTexture(const char* tex) {
    texID = SOIL_load_OGL_texture(tex, 4, 0, 0);
    if (!texID) {
        cout << "Texture not loaded!\n";

    }
    return texID;
}
但我的问题是,我怎么才能只得到整个纹理中的一个精灵呢

图为:

纹理坐标将几何体的顶点(点)映射到纹理图像中的一个点。因此,它指定了纹理的哪一部分放置在几何体的特定部分上,并与纹理参数一起指定了纹理如何包裹几何体。
通常,纹理的左下点由纹理坐标(0,0)寻址,纹理的右上点由(1,1)寻址

纹理由8列4行的瓷砖组成。若要将纹理的单个平铺放置在四边形上,必须以相同的方式分割纹理坐标。单个磁贴的角的地址如下所示:

float tiles_U = 8.0f;
float tiles_V = 4.0f;
float index_U = .... ; // index of the column in [0, tiles_U-1];
float index_V = .... ; // index of the row in [0, tiles_V-1];

float left_U  = index_U        / tiles_U;
float right_U = (index_U+1.0f) / tiles_U;

float top_V    = (tiles_V - index_V)        / tiles_V;
float bottom_V = (tiles_V - index_V - 1.0f) / tiles_V;
float wd2 = width / 2;
glColor3f(0, 0, 1);
glBegin(GL_QUADS);

glTexCoord2f( left_U, top_V );
glVertex3f(-wd2, -wd2, wd2);

glTexCoord2f( right_U, top_V );
glVertex3f(wd2, -wd2, wd2);

glTexCoord2f( right_U, bottom_V );
glVertex3f(wd2, wd2, wd2);

glTexCoord2f( left_U, bottom_V );
glVertex3f(-wd2, wd2, wd2);

glEnd();
将其应用于代码,如下所示:

float tiles_U = 8.0f;
float tiles_V = 4.0f;
float index_U = .... ; // index of the column in [0, tiles_U-1];
float index_V = .... ; // index of the row in [0, tiles_V-1];

float left_U  = index_U        / tiles_U;
float right_U = (index_U+1.0f) / tiles_U;

float top_V    = (tiles_V - index_V)        / tiles_V;
float bottom_V = (tiles_V - index_V - 1.0f) / tiles_V;
float wd2 = width / 2;
glColor3f(0, 0, 1);
glBegin(GL_QUADS);

glTexCoord2f( left_U, top_V );
glVertex3f(-wd2, -wd2, wd2);

glTexCoord2f( right_U, top_V );
glVertex3f(wd2, -wd2, wd2);

glTexCoord2f( right_U, bottom_V );
glVertex3f(wd2, wd2, wd2);

glTexCoord2f( left_U, bottom_V );
glVertex3f(-wd2, wd2, wd2);

glEnd();

纹理坐标将几何体的顶点(点)映射到纹理图像中的点。因此,它指定了纹理的哪一部分放置在几何体的特定部分上,并与纹理参数一起指定了纹理如何包裹几何体。
通常,纹理的左下点由纹理坐标(0,0)寻址,纹理的右上点由(1,1)寻址

纹理由8列4行的瓷砖组成。若要将纹理的单个平铺放置在四边形上,必须以相同的方式分割纹理坐标。单个磁贴的角的地址如下所示:

float tiles_U = 8.0f;
float tiles_V = 4.0f;
float index_U = .... ; // index of the column in [0, tiles_U-1];
float index_V = .... ; // index of the row in [0, tiles_V-1];

float left_U  = index_U        / tiles_U;
float right_U = (index_U+1.0f) / tiles_U;

float top_V    = (tiles_V - index_V)        / tiles_V;
float bottom_V = (tiles_V - index_V - 1.0f) / tiles_V;
float wd2 = width / 2;
glColor3f(0, 0, 1);
glBegin(GL_QUADS);

glTexCoord2f( left_U, top_V );
glVertex3f(-wd2, -wd2, wd2);

glTexCoord2f( right_U, top_V );
glVertex3f(wd2, -wd2, wd2);

glTexCoord2f( right_U, bottom_V );
glVertex3f(wd2, wd2, wd2);

glTexCoord2f( left_U, bottom_V );
glVertex3f(-wd2, wd2, wd2);

glEnd();
将其应用于代码,如下所示:

float tiles_U = 8.0f;
float tiles_V = 4.0f;
float index_U = .... ; // index of the column in [0, tiles_U-1];
float index_V = .... ; // index of the row in [0, tiles_V-1];

float left_U  = index_U        / tiles_U;
float right_U = (index_U+1.0f) / tiles_U;

float top_V    = (tiles_V - index_V)        / tiles_V;
float bottom_V = (tiles_V - index_V - 1.0f) / tiles_V;
float wd2 = width / 2;
glColor3f(0, 0, 1);
glBegin(GL_QUADS);

glTexCoord2f( left_U, top_V );
glVertex3f(-wd2, -wd2, wd2);

glTexCoord2f( right_U, top_V );
glVertex3f(wd2, -wd2, wd2);

glTexCoord2f( right_U, bottom_V );
glVertex3f(wd2, wd2, wd2);

glTexCoord2f( left_U, bottom_V );
glVertex3f(-wd2, wd2, wd2);

glEnd();

但是你怎么计算分数呢?我的意思是,如果我想要例如第一行的第二个tile,我怎么知道glTexCoord2f的参数呢?但是你怎么计算分数呢?我的意思是,如果我想要例如第一行中的第二个tile,我如何知道glTexCoord2f的参数?