[英]Is there a way to split one texture into an array of them using SOIL in C++?
我在項目中使用SOIL,我需要使用單個紋理,然后使用第一個紋理的不同部分將其轉換為紋理陣列。 (使用精靈表)。
順便說一下,我正在使用SDL和OpenGL。
在現代3D api(如OpenGL)中使用Sprite Sheet的典型方法是使用紋理坐標來處理單個紋理的不同部分。 雖然可以將其拆分,但是使用紋理坐標更加節省資源。
例如,如果您有一個水平3幀,每個32像素乘32像素(總大小為96x32)的簡單Sprite工作表,則可以使用以下代碼繪制第3幀:
// 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.