ADDED: LoadTextureCubemap()
Probably uncomplete, not tested yet...
This commit is contained in:
parent
5755c5e310
commit
fce48e85f4
1 changed files with 207 additions and 28 deletions
|
|
@ -398,7 +398,92 @@ Texture2D LoadTextureFromImage(Image image)
|
|||
return texture;
|
||||
}
|
||||
|
||||
// Load cubemap from image, multiple image cubemap layouts supported
|
||||
TextureCubemap LoadTextureCubemap(Image image, int layoutType)
|
||||
{
|
||||
TextureCubemap cubemap = { 0 };
|
||||
|
||||
if (layoutType == CUBEMAP_AUTO_DETECT) // Try to automatically guess layout type
|
||||
{
|
||||
// Check image width/height to determine the type of cubemap provided
|
||||
if (image.width > image.height)
|
||||
{
|
||||
if ((image.width/6) == image.height) { layoutType = CUBEMAP_LINE_HORIZONTAL; cubemap.width = image.width/6; }
|
||||
else if ((image.width/4) == (image.height/3)) { layoutType = CUBEMAP_CROSS_FOUR_BY_THREE; cubemap.width = image.width/4; }
|
||||
else if (image.width >= (int)((float)image.height*1.85f)) { layoutType = CUBEMAP_PANORAMA; cubemap.width = image.width/4; }
|
||||
}
|
||||
else if (image.height > image.width)
|
||||
{
|
||||
if ((image.height/6) == image.width) { layoutType = CUBEMAP_LINE_VERTICAL; cubemap.width = image.height/6; }
|
||||
else if ((image.width/3) == (image.height/4)) { layoutType = CUBEMAP_CROSS_THREE_BY_FOUR; cubemap.width = image.width/3; }
|
||||
}
|
||||
|
||||
cubemap.height = cubemap.width;
|
||||
}
|
||||
|
||||
int size = cubemap.width;
|
||||
|
||||
if (layoutType != CUBEMAP_AUTO_DETECT)
|
||||
{
|
||||
//unsigned int dataSize = GetPixelDataSize(size, size, format);
|
||||
//void *facesData = malloc(size*size*dataSize*6); // Get memory for 6 faces in a column
|
||||
|
||||
Image faces = { 0 }; // Vertical column image
|
||||
Rectangle faceRecs[6] = { 0 }; // Face source rectangles
|
||||
for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, size, size };
|
||||
|
||||
if (layoutType == CUBEMAP_LINE_VERTICAL)
|
||||
{
|
||||
faces = image;
|
||||
for (int i = 0; i < 6; i++) faceRecs[i].y = size*i;
|
||||
}
|
||||
else if (layoutType == CUBEMAP_PANORAMA)
|
||||
{
|
||||
// TODO: Convert panorama image to square faces...
|
||||
}
|
||||
else
|
||||
{
|
||||
if (layoutType == CUBEMAP_LINE_HORIZONTAL) for (int i = 0; i < 6; i++) faceRecs[i].x = size*i;
|
||||
else if (layoutType == CUBEMAP_CROSS_THREE_BY_FOUR)
|
||||
{
|
||||
faceRecs[0].x = size; faceRecs[0].y = size;
|
||||
faceRecs[1].x = size; faceRecs[1].y = 3*size;
|
||||
faceRecs[2].x = size; faceRecs[2].y = 0;
|
||||
faceRecs[3].x = size; faceRecs[3].y = 2*size;
|
||||
faceRecs[4].x = 0; faceRecs[4].y = size;
|
||||
faceRecs[5].x = 2*size; faceRecs[5].y = size;
|
||||
}
|
||||
else if (layoutType == CUBEMAP_CROSS_FOUR_BY_THREE)
|
||||
{
|
||||
faceRecs[0].x = 2*size; faceRecs[0].y = size;
|
||||
faceRecs[1].x = 0; faceRecs[1].y = size;
|
||||
faceRecs[2].x = size; faceRecs[2].y = 0;
|
||||
faceRecs[3].x = size; faceRecs[3].y = 2*size;
|
||||
faceRecs[4].x = size; faceRecs[4].y = size;
|
||||
faceRecs[5].x = 3*size; faceRecs[5].y = size;
|
||||
}
|
||||
|
||||
// Convert image data to 6 faces in a vertical column, that's the optimum layout for loading
|
||||
faces = GenImageColor(size, size*6, MAGENTA);
|
||||
ImageFormat(&faces, image.format);
|
||||
|
||||
// TODO: Image formating does not work with compressed textures!
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, size*i, size, size });
|
||||
|
||||
cubemap.id = rlLoadTextureCubemap(faces.data, size, faces.format);
|
||||
if (cubemap.id == 0) TraceLog(LOG_WARNING, "Cubemap image could not be loaded.");
|
||||
|
||||
UnloadImage(faces);
|
||||
}
|
||||
else TraceLog(LOG_WARNING, "Cubemap image layout can not be detected.");
|
||||
|
||||
return cubemap;
|
||||
}
|
||||
|
||||
// Load texture for rendering (framebuffer)
|
||||
// NOTE: Render texture is loaded by default with RGBA color attachment and depth RenderBuffer
|
||||
RenderTexture2D LoadRenderTexture(int width, int height)
|
||||
{
|
||||
RenderTexture2D target = rlLoadRenderTexture(width, height);
|
||||
|
|
@ -1666,7 +1751,6 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
|||
int index; // Index position in sprite font
|
||||
unsigned char character; // Current character
|
||||
|
||||
// TODO: ISSUE: Measured text size does not seem to be correct... issue on ImageDraw()
|
||||
Vector2 imSize = MeasureTextEx(font, text, (float)font.baseSize, spacing);
|
||||
|
||||
TraceLog(LOG_DEBUG, "Text Image size: %f, %f", imSize.x, imSize.y);
|
||||
|
|
|
|||
Loading…
Reference in a new issue