我在我的项目中使用土壤,我需要获取一个纹理,然后使用第一个纹理的不同部分将其转换为一个纹理数组。(使用精灵工作表)。
顺便说一下,我使用的是SDL和OpenGL。
发布于 2009-03-01 04:59:51
在像OpenGL这样的现代3DAPI中使用sprite sheeting的典型方法是使用纹理坐标来处理单个纹理的不同部分。虽然你可以拆分它,但使用纹理坐标对资源更友好。
例如,如果您有一个简单的精灵工作表,其中水平方向有3个帧,每个帧都是32像素x 32像素(总大小为96x32),则可以使用以下代码绘制第三个帧:
// I assume you have bound your source texture
// This is the U coordinate's origin in texture space
float xStart = 64.0f / 96.0f;
// This is one frame width in texture space
float xIncrement = 32.0f / 96.0f;
glBegin(GL_QUADS);
glTexCoord2f(xStart, 0);
glVertex2f(-16.0f, 16.0f);
glTexCoord2f(xStart, 1.0f);
glVertex2f(-16.0f, -16.0f);
glTexCoord2f(xStart + xIncrement, 0);
glVertex2f(16.0f, 16.0f);
glTexCoord2f(xStart + xIncrement, 1.0f);
glVertex2f(16.0f, -16.0f);
glEnd();https://stackoverflow.com/questions/599264
复制相似问题