temp raylib fixes

isolation_bkp/dynres
Dominik Madarász 2021-11-01 19:00:35 +01:00
parent e18ff55518
commit 028cdb34b2
1 changed files with 377 additions and 368 deletions

View File

@ -1,368 +1,377 @@
#pragma once #pragma once
#include "system.h" #include "system.h"
#include "raylib.h" #include "raylib.h"
#include "world/blocks.h" #include "world/blocks.h"
#include "assets.h" #include "assets.h"
#define RAYLIB_NEW_RLGL #define RAYLIB_NEW_RLGL
#include "rlgl.h" #include "rlgl.h"
static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b * t; } static inline float lerp(float a, float b, float t) { return a * (1.0f - t) + b * t; }
static inline static inline
void DrawTextEco(const char *text, float posX, float posY, int fontSize, Color color, float spacing) { void DrawTextEco(const char *text, float posX, float posY, int fontSize, Color color, float spacing) {
#if 1 #if 1
// Check if default font has been loaded // Check if default font has been loaded
if (GetFontDefault().texture.id != 0) { if (GetFontDefault().texture.id != 0) {
Vector2 position = { (float)posX , (float)posY }; Vector2 position = { (float)posX , (float)posY };
int defaultFontSize = 10; // Default Font chars height in pixel int defaultFontSize = 10; // Default Font chars height in pixel
int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing; int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing;
DrawTextEx(GetFontDefault(), text, position, (float)fontSize , (float)new_spacing , color); DrawTextEx(GetFontDefault(), text, position, (float)fontSize , (float)new_spacing , color);
} }
#endif #endif
} }
static inline static inline
int MeasureTextEco(const char *text, int fontSize, float spacing) { int MeasureTextEco(const char *text, int fontSize, float spacing) {
#if 1 #if 1
Vector2 vec = { 0.0f, 0.0f }; Vector2 vec = { 0.0f, 0.0f };
// Check if default font has been loaded // Check if default font has been loaded
if (GetFontDefault().texture.id != 0) { if (GetFontDefault().texture.id != 0) {
int defaultFontSize = 10; // Default Font chars height in pixel int defaultFontSize = 10; // Default Font chars height in pixel
int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing; int new_spacing = spacing == 0.0f ? fontSize/defaultFontSize : spacing;
vec = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)new_spacing); vec = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)new_spacing);
} }
return (int)vec.x; return (int)vec.x;
#else #else
return 0; return 0;
#endif #endif
} }
static inline static inline
void DrawCircleEco(float centerX, float centerY, float radius, Color color) void DrawCircleEco(float centerX, float centerY, float radius, Color color)
{ {
DrawCircleV((Vector2){ (float)centerX , (float)centerY }, radius , color); DrawCircleV((Vector2){ (float)centerX , (float)centerY }, radius , color);
} }
static inline static inline
void DrawRectangleEco(float posX, float posY, float width, float height, Color color) void DrawRectangleEco(float posX, float posY, float width, float height, Color color)
{ {
DrawRectangleV((Vector2){ (float)posX , (float)posY }, (Vector2){ width , height }, color); DrawRectangleV((Vector2){ (float)posX , (float)posY }, (Vector2){ width , height }, color);
} }
static inline static inline
Texture2D GetBlockImage(uint8_t id) { Texture2D GetBlockImage(uint8_t id) {
return *(Texture2D*)blocks_get_img(id); return *(Texture2D*)blocks_get_img(id);
} }
static inline static inline
RenderTexture2D GetChunkTexture(uint64_t id) { RenderTexture2D GetChunkTexture(uint64_t id) {
RenderTexture2D *tex = (RenderTexture2D*)blocks_get_chunk_tex(id); RenderTexture2D *tex = (RenderTexture2D*)blocks_get_chunk_tex(id);
if (!tex) return (RenderTexture2D){0}; if (!tex) return (RenderTexture2D){0};
return *tex; return *tex;
} }
static inline static inline
Texture2D GetSpriteTexture2D(uint16_t id) { Texture2D GetSpriteTexture2D(uint16_t id) {
return *(Texture2D*)assets_get_tex(id); return *(Texture2D*)assets_get_tex(id);
} }
static inline static inline
Sound GetSound(uint16_t id) { Sound GetSound(uint16_t id) {
return *(Sound*)assets_get_snd(id); return *(Sound*)assets_get_snd(id);
} }
// Draw cube // Draw cube
// NOTE: Cube position is the center position // NOTE: Cube position is the center position
static inline static inline
void EcoDrawCube(Vector3 position, float width, float height, float length, float heading, Color color) void EcoDrawCube(Vector3 position, float width, float height, float length, float heading, Color color)
{ {
float x = 0.0f; float x = 0.0f;
float y = 0.0f; float y = 0.0f;
float z = 0.0f; float z = 0.0f;
rlCheckRenderBatchLimit(36); rlCheckRenderBatchLimit(36);
rlPushMatrix(); rlPushMatrix();
// NOTE: Transformation is applied in inverse order (scale -> rotate -> translate) // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
rlRotatef(heading, 0, 1, 0); rlRotatef(heading, 0, 1, 0);
//rlScalef(1.0f, 1.0f, 1.0f); // NOTE: Vertices are directly scaled on definition //rlScalef(1.0f, 1.0f, 1.0f); // NOTE: Vertices are directly scaled on definition
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
// Front face // Front face
rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
// Back face // Back face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
// Top face // Top face
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right
// Bottom face // Bottom face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Right
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left
// Right face // Right face
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right
rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left
// Left face // Left face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right
rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right
rlEnd(); rlEnd();
rlPopMatrix(); rlPopMatrix();
} }
// Draw codepoint at specified position in 3D space // Draw codepoint at specified position in 3D space
void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint) void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint)
{ {
// Character index position in sprite font #if 0
// NOTE: In case a codepoint is not available in the font, index returned points to '?' // Character index position in sprite font
int index = GetGlyphIndex(font, codepoint); // NOTE: In case a codepoint is not available in the font, index returned points to '?'
float scale = fontSize/(float)font.baseSize; int index = GetGlyphIndex(font, codepoint);
float scale = fontSize/(float)font.baseSize;
// Character destination rectangle on screen
// NOTE: We consider charsPadding on drawing // Character destination rectangle on screen
position.x += (float)(font.chars[index].offsetX - font.charsPadding)/(float)font.baseSize*scale; // NOTE: We consider charsPadding on drawing
position.z += (float)(font.chars[index].offsetY - font.charsPadding)/(float)font.baseSize*scale; position.x += (float)(font.chars[index].offsetX - font.charsPadding)/(float)font.baseSize*scale;
position.z += (float)(font.chars[index].offsetY - font.charsPadding)/(float)font.baseSize*scale;
// Character source rectangle from font texture atlas
// NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects // Character source rectangle from font texture atlas
Rectangle srcRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding, // NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects
font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding }; Rectangle srcRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding,
font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding };
float width = (float)(font.recs[index].width + 2.0f*font.charsPadding)/(float)font.baseSize*scale;
float height = (float)(font.recs[index].height + 2.0f*font.charsPadding)/(float)font.baseSize*scale; float width = (float)(font.recs[index].width + 2.0f*font.charsPadding)/(float)font.baseSize*scale;
float height = (float)(font.recs[index].height + 2.0f*font.charsPadding)/(float)font.baseSize*scale;
if (font.texture.id > 0)
{ if (font.texture.id > 0)
const float x = 0.0f; {
const float y = 0.0f; const float x = 0.0f;
const float z = 0.0f; const float y = 0.0f;
const float z = 0.0f;
// normalized texture coordinates of the glyph inside the font texture (0.0f -> 1.0f)
const float tx = srcRec.x/font.texture.width; // normalized texture coordinates of the glyph inside the font texture (0.0f -> 1.0f)
const float ty = srcRec.y/font.texture.height; const float tx = srcRec.x/font.texture.width;
const float tw = (srcRec.x+srcRec.width)/font.texture.width; const float ty = srcRec.y/font.texture.height;
const float th = (srcRec.y+srcRec.height)/font.texture.height; const float tw = (srcRec.x+srcRec.width)/font.texture.width;
const float th = (srcRec.y+srcRec.height)/font.texture.height;
{
#if defined(RAYLIB_NEW_RLGL) {
} #if defined(RAYLIB_NEW_RLGL)
rlCheckRenderBatchLimit(4 + 4*backface); }
rlSetTexture(font.texture.id); rlCheckRenderBatchLimit(4 + 4*backface);
#else rlSetTexture(font.texture.id);
if (rlCheckBufferLimit(4 + 4*backface)) rlglDraw(); #else
rlEnableTexture(font.texture.id); if (rlCheckBufferLimit(4 + 4*backface)) rlglDraw();
#endif rlEnableTexture(font.texture.id);
rlPushMatrix(); #endif
rlTranslatef(position.x, position.y, position.z); rlPushMatrix();
rlTranslatef(position.x, position.y, position.z);
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
// Front Face
rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up // Front Face
rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Left Of The Texture and Quad rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Left Of The Texture and Quad rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Left Of The Texture and Quad
rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Right Of The Texture and Quad rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Left Of The Texture and Quad
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Right Of The Texture and Quad rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Right Of The Texture and Quad
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Right Of The Texture and Quad
if (backface)
{ if (backface)
// Back Face {
rlNormal3f(0.0f, -1.0f, 0.0f); // Normal Pointing Down // Back Face
rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Right Of The Texture and Quad rlNormal3f(0.0f, -1.0f, 0.0f); // Normal Pointing Down
rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Left Of The Texture and Quad rlTexCoord2f(tx, ty); rlVertex3f(x, y, z); // Top Right Of The Texture and Quad
rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Left Of The Texture and Quad rlTexCoord2f(tw, ty); rlVertex3f(x + width, y, z); // Top Left Of The Texture and Quad
rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Right Of The Texture and Quad rlTexCoord2f(tw, th); rlVertex3f(x + width, y, z + height); // Bottom Left Of The Texture and Quad
} rlTexCoord2f(tx, th); rlVertex3f(x, y, z + height); // Bottom Right Of The Texture and Quad
rlEnd(); }
rlPopMatrix(); rlEnd();
rlPopMatrix();
#if defined(RAYLIB_NEW_RLGL)
rlSetTexture(0); #if defined(RAYLIB_NEW_RLGL)
#else rlSetTexture(0);
rlDisableTexture(); #else
#endif rlDisableTexture();
} #endif
} }
#endif
void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, Color tint) { }
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, Color tint) {
float textOffsetY = 0.0f; // Offset between lines (on line break '\n') #if 0
float textOffsetX = 0.0f; // Offset X to next character to draw int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
float scale = fontSize/(float)font.baseSize; float textOffsetY = 0.0f; // Offset between lines (on line break '\n')
float textOffsetX = 0.0f; // Offset X to next character to draw
for (int i = 0; i < length;)
{ float scale = fontSize/(float)font.baseSize;
// Get next codepoint from byte string and glyph index in font
int codepointByteCount = 0; for (int i = 0; i < length;)
int codepoint = GetCodepoint(&text[i], &codepointByteCount); {
int index = GetGlyphIndex(font, codepoint); // Get next codepoint from byte string and glyph index in font
int codepointByteCount = 0;
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) int codepoint = GetCodepoint(&text[i], &codepointByteCount);
// but we need to draw all of the bad bytes using the '?' symbol moving one byte int index = GetGlyphIndex(font, codepoint);
if (codepoint == 0x3f) codepointByteCount = 1;
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
if (codepoint == '\n') // but we need to draw all of the bad bytes using the '?' symbol moving one byte
{ if (codepoint == 0x3f) codepointByteCount = 1;
// NOTE: Fixed line spacing of 1.5 line-height
// TODO: Support custom line spacing defined by user if (codepoint == '\n')
textOffsetY += scale + lineSpacing/(float)font.baseSize*scale; {
textOffsetX = 0.0f; // NOTE: Fixed line spacing of 1.5 line-height
} // TODO: Support custom line spacing defined by user
else textOffsetY += scale + lineSpacing/(float)font.baseSize*scale;
{ textOffsetX = 0.0f;
if ((codepoint != ' ') && (codepoint != '\t')) }
{ else
DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint); {
} if ((codepoint != ' ') && (codepoint != '\t'))
{
if (font.chars[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint);
else textOffsetX += (float)(font.chars[index].advanceX + fontSpacing)/(float)font.baseSize*scale; }
}
if (font.chars[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale;
i += codepointByteCount; // Move text bytes counter to next codepoint else textOffsetX += (float)(font.chars[index].advanceX + fontSpacing)/(float)font.baseSize*scale;
} }
}
i += codepointByteCount; // Move text bytes counter to next codepoint
Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing) {
int len = TextLength(text); }
int tempLen = 0; // Used to count longer text line num chars #endif
int lenCounter = 0; }
float tempTextWidth = 0.0f; // Used to count longer text line width Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing) {
float scale = fontSize/(float)font.baseSize; #if 0
float textHeight = scale; int len = TextLength(text);
float textWidth = 0.0f; int tempLen = 0; // Used to count longer text line num chars
int lenCounter = 0;
int letter = 0; // Current character
int index = 0; // Index position in sprite font float tempTextWidth = 0.0f; // Used to count longer text line width
for (int i = 0; i < len; i++) float scale = fontSize/(float)font.baseSize;
{ float textHeight = scale;
lenCounter++; float textWidth = 0.0f;
int next = 0; int letter = 0; // Current character
letter = GetCodepoint(&text[i], &next); int index = 0; // Index position in sprite font
index = GetGlyphIndex(font, letter);
for (int i = 0; i < len; i++)
// NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) {
// but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1 lenCounter++;
if (letter == 0x3f) next = 1;
i += next - 1; int next = 0;
letter = GetCodepoint(&text[i], &next);
if (letter != '\n') index = GetGlyphIndex(font, letter);
{
if (font.chars[index].advanceX != 0) textWidth += (font.chars[index].advanceX+fontSpacing)/(float)font.baseSize*scale; // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
else textWidth += (font.recs[index].width + font.chars[index].offsetX)/(float)font.baseSize*scale; // but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1
} if (letter == 0x3f) next = 1;
else i += next - 1;
{
if (tempTextWidth < textWidth) tempTextWidth = textWidth; if (letter != '\n')
lenCounter = 0; {
textWidth = 0.0f; if (font.chars[index].advanceX != 0) textWidth += (font.chars[index].advanceX+fontSpacing)/(float)font.baseSize*scale;
textHeight += scale + lineSpacing/(float)font.baseSize*scale; else textWidth += (font.recs[index].width + font.chars[index].offsetX)/(float)font.baseSize*scale;
} }
else
if (tempLen < lenCounter) tempLen = lenCounter; {
} if (tempTextWidth < textWidth) tempTextWidth = textWidth;
lenCounter = 0;
if (tempTextWidth < textWidth) tempTextWidth = textWidth; textWidth = 0.0f;
textHeight += scale + lineSpacing/(float)font.baseSize*scale;
Vector3 vec = { 0 }; }
vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing/(float)font.baseSize*scale); // Adds chars spacing to measure
vec.y = 0.25f; if (tempLen < lenCounter) tempLen = lenCounter;
vec.z = textHeight; }
return vec; if (tempTextWidth < textWidth) tempTextWidth = textWidth;
}
Vector3 vec = { 0 };
vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing/(float)font.baseSize*scale); // Adds chars spacing to measure
Color GenerateRandomColor(float s, float v) { vec.y = 0.25f;
const float Phi = 0.618033988749895f; // Golden ratio conjugate vec.z = textHeight;
float h = GetRandomValue(0, 360);
h = fmodf((h + h*Phi), 360.0f); return vec;
return ColorFromHSV(h, s, v); #endif
}
}
// Draw circle outline
void DrawCircleLinesEco(float centerX, float centerY, float radius, Color color) Color GenerateRandomColor(float s, float v) {
{ const float Phi = 0.618033988749895f; // Golden ratio conjugate
rlCheckRenderBatchLimit(2*36); float h = GetRandomValue(0, 360);
h = fmodf((h + h*Phi), 360.0f);
rlBegin(RL_LINES); return ColorFromHSV(h, s, v);
rlColor4ub(color.r, color.g, color.b, color.a); }
// NOTE: Circle outline is drawn pixel by pixel every degree (0 to 360)
for (int i = 0; i < 360; i += 10) // Draw circle outline
{ void DrawCircleLinesEco(float centerX, float centerY, float radius, Color color)
rlVertex2f(centerX + sinf(DEG2RAD*i)*radius, centerY + cosf(DEG2RAD*i)*radius); {
rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radius, centerY + cosf(DEG2RAD*(i + 10))*radius); rlCheckRenderBatchLimit(2*36);
}
rlEnd(); rlBegin(RL_LINES);
} rlColor4ub(color.r, color.g, color.b, color.a);
void DrawRectangleLinesEco(float posX, float posY, float width, float height, Color color) // NOTE: Circle outline is drawn pixel by pixel every degree (0 to 360)
{ for (int i = 0; i < 360; i += 10)
rlBegin(RL_LINES); {
rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(centerX + sinf(DEG2RAD*i)*radius, centerY + cosf(DEG2RAD*i)*radius);
rlVertex2f(posX + 1, posY + 1); rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radius, centerY + cosf(DEG2RAD*(i + 10))*radius);
rlVertex2f(posX + width, posY + 1); }
rlEnd();
rlVertex2f(posX + width, posY + 1); }
rlVertex2f(posX + width, posY + height);
void DrawRectangleLinesEco(float posX, float posY, float width, float height, Color color)
rlVertex2f(posX + width, posY + height); {
rlVertex2f(posX + 1, posY + height); rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(posX + 1, posY + height); rlVertex2f(posX + 1, posY + 1);
rlVertex2f(posX + 1, posY + 1); rlVertex2f(posX + width, posY + 1);
rlEnd();
} rlVertex2f(posX + width, posY + 1);
rlVertex2f(posX + width, posY + height);
rlVertex2f(posX + width, posY + height);
rlVertex2f(posX + 1, posY + height);
rlVertex2f(posX + 1, posY + height);
rlVertex2f(posX + 1, posY + 1);
rlEnd();
}