mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
13
src/Makefile
13
src/Makefile
@ -69,12 +69,13 @@ else
|
||||
endif
|
||||
|
||||
# define compiler flags:
|
||||
# -O1 defines optimization level
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -fgnu89-inline declaring inline functions support (GCC optimized, faster)
|
||||
CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline
|
||||
# -O1 defines optimization level
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -fgnu89-inline declaring inline functions support (GCC optimized, faster)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces
|
||||
|
||||
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
|
||||
|
||||
16
src/audio.c
16
src/audio.c
@ -37,24 +37,24 @@
|
||||
|
||||
#include "AL/al.h" // OpenAL basic header
|
||||
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||
#include "AL/alext.h" // extensions for other format types
|
||||
#include "AL/alext.h" // OpenAL extensions for other format types
|
||||
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||
#include <string.h> // Required for strcmp()
|
||||
#include <stdio.h> // Used for .WAV loading
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp(), strncmp()
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||
|
||||
#if defined(AUDIO_STANDALONE)
|
||||
#include <stdarg.h> // Used for functions with variable number of parameters (TraceLog())
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
#else
|
||||
#include "utils.h" // rRES data decompression utility function
|
||||
// NOTE: Includes Android fopen function map
|
||||
#include "utils.h" // Required for: DecompressData()
|
||||
// NOTE: Includes Android fopen() function map
|
||||
#endif
|
||||
|
||||
//#define STB_VORBIS_HEADER_ONLY
|
||||
#include "stb_vorbis.h" // OGG loading functions
|
||||
|
||||
#define JAR_XM_IMPLEMENTATION
|
||||
#include "jar_xm.h" // For playing .xm files
|
||||
#include "jar_xm.h" // XM loading functions
|
||||
|
||||
#define JAR_MOD_IMPLEMENTATION
|
||||
#include "jar_mod.h" // For playing .mod files
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
#include "raylib.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <math.h> // Required for: sqrt(), sin(), cos()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
||||
18
src/core.c
18
src/core.c
@ -2078,10 +2078,10 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
||||
gestureEvent.position[0] = GetMousePosition();
|
||||
|
||||
// Normalize gestureEvent.position[0] for screenWidth and screenHeight
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||
|
||||
// Gesture data is sent to gestures system for processing
|
||||
|
||||
// Gesture data is sent to gestures system for processing
|
||||
ProcessGestureEvent(gestureEvent);
|
||||
#endif
|
||||
}
|
||||
@ -2223,10 +2223,10 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||
// Load default font for convenience
|
||||
// NOTE: External function (defined in module: text)
|
||||
LoadDefaultFont();
|
||||
|
||||
|
||||
// TODO: GPU assets reload in case of lost focus (lost context)
|
||||
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
||||
/*
|
||||
/*
|
||||
if (assetsReloadRequired)
|
||||
{
|
||||
for (int i = 0; i < assetsCount; i++)
|
||||
@ -2759,9 +2759,9 @@ static void *GamepadThread(void *arg)
|
||||
};
|
||||
|
||||
// Read gamepad event
|
||||
struct js_event gamepadEvent;
|
||||
struct js_event gamepadEvent;
|
||||
|
||||
while (1)
|
||||
while (1)
|
||||
{
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||
{
|
||||
@ -2792,8 +2792,8 @@ static void *GamepadThread(void *arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -28,19 +28,19 @@
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
#include "gestures.h"
|
||||
#else
|
||||
#include "raylib.h" // Required for typedef(s): Vector2, Gestures
|
||||
#include "raylib.h" // Required for: Vector2, Gestures
|
||||
#endif
|
||||
|
||||
#include <math.h> // Used for: atan2(), sqrt()
|
||||
#include <stdint.h> // Defines int32_t, int64_t
|
||||
#include <math.h> // Required for: atan2(), sqrt()
|
||||
#include <stdint.h> // Required for: uint64_t
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Functions required to query time on Windows
|
||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||
#elif defined(__linux)
|
||||
#include <sys/time.h> // Declares storage size of ‘now’
|
||||
#include <time.h> // Used for clock functions
|
||||
#include <sys/time.h> // Required for: timespec
|
||||
#include <time.h> // Required for: clock_gettime()
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
23
src/models.c
23
src/models.c
@ -26,16 +26,16 @@
|
||||
#include "raylib.h"
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#include "utils.h" // Android fopen function map
|
||||
#include "utils.h" // Android fopen function map
|
||||
#endif
|
||||
|
||||
#include <stdio.h> // Standard input/output functions, used to read model files data
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||
#include <string.h> // Required for strcmp()
|
||||
#include <math.h> // Used for sin, cos, tan
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp()
|
||||
#include <math.h> // Required for: sin(), cos()
|
||||
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
#include "raymath.h" // Required for data type Matrix and Matrix functions
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||
#include "raymath.h" // Matrix data type and Matrix functions
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
@ -605,7 +605,7 @@ Model LoadModel(const char *fileName)
|
||||
|
||||
// TODO: Initialize default data for model in case loading fails, maybe a cube?
|
||||
|
||||
if (strcmp(GetExtension(fileName),"obj") == 0) model.mesh = LoadOBJ(fileName);
|
||||
if (strcmp(GetExtension(fileName), "obj") == 0) model.mesh = LoadOBJ(fileName);
|
||||
else TraceLog(WARNING, "[%s] Model extension not recognized, it can't be loaded", fileName);
|
||||
|
||||
if (model.mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
|
||||
@ -764,7 +764,7 @@ Material LoadMaterial(const char *fileName)
|
||||
{
|
||||
Material material = { 0 };
|
||||
|
||||
if (strcmp(GetExtension(fileName),"mtl") == 0) material = LoadMTL(fileName);
|
||||
if (strcmp(GetExtension(fileName), "mtl") == 0) material = LoadMTL(fileName);
|
||||
else TraceLog(WARNING, "[%s] Material extension not recognized, it can't be loaded", fileName);
|
||||
|
||||
return material;
|
||||
@ -779,8 +779,7 @@ Material LoadDefaultMaterial(void)
|
||||
material.texDiffuse = GetDefaultTexture(); // White texture (1x1 pixel)
|
||||
//material.texNormal; // NOTE: By default, not set
|
||||
//material.texSpecular; // NOTE: By default, not set
|
||||
|
||||
material.colTint = WHITE; // Tint color
|
||||
|
||||
material.colDiffuse = WHITE; // Diffuse color
|
||||
material.colAmbient = WHITE; // Ambient color
|
||||
material.colSpecular = WHITE; // Specular color
|
||||
@ -1298,7 +1297,7 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
|
||||
//Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates
|
||||
|
||||
model.transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
||||
model.material.colTint = tint;
|
||||
model.material.colDiffuse = tint; // TODO: Multiply tint color by diffuse color?
|
||||
|
||||
rlglDrawMesh(model.mesh, model.material, model.transform);
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
#include "raylib.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||
#include <math.h> // Declares cos(), sin(), abs() and fminf() for math operations
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <math.h> // Required for: cos(), sin(), abs(), fminf()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
||||
117
src/raygui.c
117
src/raygui.c
@ -22,17 +22,30 @@
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
//#define RAYGUI_STANDALONE // To use the raygui module as standalone lib, just uncomment this line
|
||||
// NOTE: Some external funtions are required for drawing and input management
|
||||
|
||||
#if !defined(RAYGUI_STANDALONE)
|
||||
#include "raylib.h"
|
||||
#endif
|
||||
|
||||
#include "raygui.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // Required for malloc(), free()
|
||||
#include <string.h> // Required for strcmp()
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf()
|
||||
// NOTE: Those functions are only used in SaveGuiStyle() and LoadGuiStyle()
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp()
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
#if defined(RAYGUI_STANDALONE)
|
||||
#define KEY_LEFT 263
|
||||
#define KEY_RIGHT 262
|
||||
#define MOUSE_LEFT_BUTTON 0
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -50,7 +63,7 @@ typedef enum { SLIDER_DEFAULT, SLIDER_HOVER, SLIDER_ACTIVE } SliderState;
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
//Current GUI style (default light)
|
||||
// Current GUI style (default light)
|
||||
static int style[NUM_PROPERTIES] = {
|
||||
0xf5f5f5ff, // GLOBAL_BASE_COLOR,
|
||||
0xf5f5f5ff, // GLOBAL_BORDER_COLOR,
|
||||
@ -157,6 +170,30 @@ static int style[NUM_PROPERTIES] = {
|
||||
//----------------------------------------------------------------------------------
|
||||
static Color ColorMultiply(Color baseColor, float value);
|
||||
|
||||
#if defined RAYGUI_STANDALONE
|
||||
static Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
|
||||
static int GetHexValue(Color color); // Returns hexadecimal value for a Color
|
||||
static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
|
||||
static const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
|
||||
|
||||
// NOTE: raygui depend on some raylib input and drawing functions
|
||||
// TODO: Set your own functions
|
||||
static Vector2 GetMousePosition() { return (Vector2){ 0.0f, 0.0f }; }
|
||||
static int IsMouseButtonDown(int button) { return 0; }
|
||||
static int IsMouseButtonPressed(int button) { return 0; }
|
||||
static int IsMouseButtonReleased(int button) { return 0; }
|
||||
static int IsMouseButtonUp(int button) { return 0; }
|
||||
|
||||
static int GetKeyPressed(void) { return 0; } // NOTE: Only used by GuiTextBox()
|
||||
static int IsKeyDown(int key) { return 0; } // NOTE: Only used by GuiSpinner()
|
||||
|
||||
static int MeasureText(const char *text, int fontSize) { return 0; }
|
||||
static void DrawText(const char *text, int posX, int posY, int fontSize, Color color) { }
|
||||
static void DrawRectangleRec(Rectangle rec, Color color) { }
|
||||
static void DrawRectangle(int posX, int posY, int width, int height, Color color) { DrawRectangleRec((Rectangle){ posX, posY, width, height }, color); }
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -164,7 +201,9 @@ static Color ColorMultiply(Color baseColor, float value);
|
||||
// Label element, show text
|
||||
void GuiLabel(Rectangle bounds, const char *text)
|
||||
{
|
||||
GuiLabelEx(bounds,text, GetColor(style[LABEL_TEXT_COLOR]), BLANK, BLANK);
|
||||
#define BLANK (Color){ 0, 0, 0, 0 } // Blank (Transparent)
|
||||
|
||||
GuiLabelEx(bounds, text, GetColor(style[LABEL_TEXT_COLOR]), BLANK, BLANK);
|
||||
}
|
||||
|
||||
// Label element extended, configurable colors
|
||||
@ -173,7 +212,7 @@ void GuiLabelEx(Rectangle bounds, const char *text, Color textColor, Color borde
|
||||
// Update control
|
||||
//--------------------------------------------------------------------
|
||||
int textWidth = MeasureText(text, style[GLOBAL_TEXT_FONTSIZE]);
|
||||
int textHeight = GetDefaultFont().size;
|
||||
int textHeight = style[GLOBAL_TEXT_FONTSIZE];
|
||||
|
||||
if (bounds.width < textWidth) bounds.width = textWidth + style[LABEL_TEXT_PADDING];
|
||||
if (bounds.height < textHeight) bounds.height = textHeight + style[LABEL_TEXT_PADDING]/2;
|
||||
@ -194,7 +233,7 @@ bool GuiButton(Rectangle bounds, const char *text)
|
||||
Vector2 mousePoint = GetMousePosition();
|
||||
|
||||
int textWidth = MeasureText(text, style[GLOBAL_TEXT_FONTSIZE]);
|
||||
int textHeight = GetDefaultFont().size;
|
||||
int textHeight = style[GLOBAL_TEXT_FONTSIZE];
|
||||
|
||||
// Update control
|
||||
//--------------------------------------------------------------------
|
||||
@ -252,7 +291,7 @@ bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle)
|
||||
Vector2 mousePoint = GetMousePosition();
|
||||
|
||||
int textWidth = MeasureText(text, style[GLOBAL_TEXT_FONTSIZE]);
|
||||
int textHeight = GetDefaultFont().size;
|
||||
int textHeight = style[GLOBAL_TEXT_FONTSIZE];
|
||||
|
||||
// Update control
|
||||
//--------------------------------------------------------------------
|
||||
@ -337,7 +376,7 @@ int GuiComboBox(Rectangle bounds, int comboNum, char **comboText, int comboActiv
|
||||
Rectangle click = { bounds.x + bounds.width + style[COMBOBOX_PADDING], bounds.y, style[COMBOBOX_BUTTON_WIDTH], style[COMBOBOX_BUTTON_HEIGHT] };
|
||||
Vector2 mousePoint = GetMousePosition();
|
||||
|
||||
int textHeight = GetDefaultFont().size;
|
||||
int textHeight = style[GLOBAL_TEXT_FONTSIZE];
|
||||
|
||||
for (int i = 0; i < comboNum; i++)
|
||||
{
|
||||
@ -627,9 +666,8 @@ int GuiSpinner(Rectangle bounds, int value, int minValue, int maxValue)
|
||||
Rectangle rightButtonBound = { bounds.x + bounds.width - bounds.width/4 + 1, bounds.y, bounds.width/4, bounds.height };
|
||||
Vector2 mousePoint = GetMousePosition();
|
||||
|
||||
int textHeight = GetDefaultFont().size;
|
||||
|
||||
int textWidth = MeasureText(FormatText("%i", value), style[GLOBAL_TEXT_FONTSIZE]);
|
||||
int textHeight = style[GLOBAL_TEXT_FONTSIZE];
|
||||
|
||||
int buttonSide = 0;
|
||||
|
||||
@ -864,10 +902,11 @@ char *GuiTextBox(Rectangle bounds, char *text)
|
||||
|
||||
DrawText(FormatText("%c", text[i]), initPos, bounds.y + style[TEXTBOX_TEXT_FONTSIZE], style[TEXTBOX_TEXT_FONTSIZE], GetColor(style[TEXTBOX_TEXT_COLOR]));
|
||||
|
||||
initPos += ((GetDefaultFont().charRecs[(int)text[i] - 32].width + 2));
|
||||
initPos += (MeasureText(FormatText("%c", text[i]), style[GLOBAL_TEXT_FONTSIZE]) + 2);
|
||||
//initPos += ((GetDefaultFont().charRecs[(int)text[i] - 32].width + 2));
|
||||
}
|
||||
|
||||
if ((framesCounter/20)%2 && CheckCollisionPointRec(mousePoint, bounds)) DrawLine(initPos + 2, bounds.y + 5, initPos + 2, bounds.y + 10 + 15, GetColor(style[TEXTBOX_LINE_COLOR]));
|
||||
if ((framesCounter/20)%2 && CheckCollisionPointRec(mousePoint, bounds)) DrawRectangle(initPos + 2, bounds.y + 5, 1, 20, GetColor(style[TEXTBOX_LINE_COLOR]));
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
return text;
|
||||
@ -1051,4 +1090,50 @@ static Color ColorMultiply(Color baseColor, float value)
|
||||
multColor.b += (255 - multColor.b)*value;
|
||||
|
||||
return multColor;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (RAYGUI_STANDALONE)
|
||||
// Returns a Color struct from hexadecimal value
|
||||
static Color GetColor(int hexValue)
|
||||
{
|
||||
Color color;
|
||||
|
||||
color.r = (unsigned char)(hexValue >> 24) & 0xFF;
|
||||
color.g = (unsigned char)(hexValue >> 16) & 0xFF;
|
||||
color.b = (unsigned char)(hexValue >> 8) & 0xFF;
|
||||
color.a = (unsigned char)hexValue & 0xFF;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// Returns hexadecimal value for a Color
|
||||
static int GetHexValue(Color color)
|
||||
{
|
||||
return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a);
|
||||
}
|
||||
|
||||
// Check if point is inside rectangle
|
||||
static bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
if ((point.x >= rec.x) && (point.x <= (rec.x + rec.width)) && (point.y >= rec.y) && (point.y <= (rec.y + rec.height))) collision = true;
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
// Formatting of text with variables to 'embed'
|
||||
static const char *FormatText(const char *text, ...)
|
||||
{
|
||||
#define MAX_FORMATTEXT_LENGTH 64
|
||||
|
||||
static char buffer[MAX_FORMATTEXT_LENGTH];
|
||||
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsprintf(buffer, text, args);
|
||||
va_end(args);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
37
src/raygui.h
37
src/raygui.h
@ -23,16 +23,49 @@
|
||||
#ifndef RAYGUI_H
|
||||
#define RAYGUI_H
|
||||
|
||||
#include "raylib.h"
|
||||
//#include "raylib.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define NUM_PROPERTIES 98
|
||||
#define NUM_PROPERTIES 98
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
// NOTE: Some types are required for RAYGUI_STANDALONE usage
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(RAYGUI_STANDALONE)
|
||||
#ifndef __cplusplus
|
||||
// Boolean type
|
||||
#ifndef true
|
||||
typedef enum { false, true } bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
|
||||
// Color type, RGBA (32bit)
|
||||
typedef struct Color {
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
} Color;
|
||||
|
||||
// Rectangle type
|
||||
typedef struct Rectangle {
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
} Rectangle;
|
||||
#endif
|
||||
|
||||
// Gui properties enumeration
|
||||
typedef enum GuiProperty {
|
||||
GLOBAL_BASE_COLOR = 0,
|
||||
GLOBAL_BORDER_COLOR,
|
||||
|
||||
103
src/raylib.h
103
src/raylib.h
@ -350,7 +350,7 @@ typedef struct Camera {
|
||||
Vector3 position; // Camera position
|
||||
Vector3 target; // Camera target it looks-at
|
||||
Vector3 up; // Camera up vector (rotation over its axis)
|
||||
float fovy; // Field-Of-View apperture in Y (degrees)
|
||||
float fovy; // Camera field-of-view apperture in Y (degrees)
|
||||
} Camera;
|
||||
|
||||
// Camera2D type, defines a 2d camera
|
||||
@ -363,87 +363,84 @@ typedef struct Camera2D {
|
||||
|
||||
// Bounding box type
|
||||
typedef struct BoundingBox {
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
Vector3 min; // minimum vertex box-corner
|
||||
Vector3 max; // maximum vertex box-corner
|
||||
} BoundingBox;
|
||||
|
||||
// Vertex data definning a mesh
|
||||
typedef struct Mesh {
|
||||
int vertexCount; // number of vertices stored in arrays
|
||||
int triangleCount; // number of triangles stored (indexed or not)
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
unsigned short *indices; // vertex indices (in case vertex data comes indexed)
|
||||
int vertexCount; // number of vertices stored in arrays
|
||||
int triangleCount; // number of triangles stored (indexed or not)
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
unsigned short *indices;// vertex indices (in case vertex data comes indexed)
|
||||
|
||||
BoundingBox bounds; // mesh limits defined by min and max points
|
||||
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
||||
} Mesh;
|
||||
|
||||
// Shader type (generic shader)
|
||||
typedef struct Shader {
|
||||
unsigned int id; // Shader program id
|
||||
unsigned int id; // Shader program id
|
||||
|
||||
// Vertex attributes locations (default locations)
|
||||
int vertexLoc; // Vertex attribute location point (default-location = 0)
|
||||
int texcoordLoc; // Texcoord attribute location point (default-location = 1)
|
||||
int texcoord2Loc; // Texcoord2 attribute location point (default-location = 5)
|
||||
int normalLoc; // Normal attribute location point (default-location = 2)
|
||||
int tangentLoc; // Tangent attribute location point (default-location = 4)
|
||||
int colorLoc; // Color attibute location point (default-location = 3)
|
||||
int vertexLoc; // Vertex attribute location point (default-location = 0)
|
||||
int texcoordLoc; // Texcoord attribute location point (default-location = 1)
|
||||
int texcoord2Loc; // Texcoord2 attribute location point (default-location = 5)
|
||||
int normalLoc; // Normal attribute location point (default-location = 2)
|
||||
int tangentLoc; // Tangent attribute location point (default-location = 4)
|
||||
int colorLoc; // Color attibute location point (default-location = 3)
|
||||
|
||||
// Uniform locations
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
int tintColorLoc; // Diffuse color uniform location point (fragment shader)
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
int tintColorLoc; // Diffuse color uniform location point (fragment shader)
|
||||
|
||||
// Texture map locations (generic for any kind of map)
|
||||
int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0)
|
||||
int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1)
|
||||
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||
int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0)
|
||||
int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1)
|
||||
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||
} Shader;
|
||||
|
||||
// Material type
|
||||
typedef struct Material {
|
||||
Shader shader; // Standard shader (supports 3 map textures)
|
||||
Shader shader; // Standard shader (supports 3 map textures)
|
||||
|
||||
Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc)
|
||||
Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc)
|
||||
Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc)
|
||||
Texture2D texDiffuse; // Diffuse texture (binded to shader mapTexture0Loc)
|
||||
Texture2D texNormal; // Normal texture (binded to shader mapTexture1Loc)
|
||||
Texture2D texSpecular; // Specular texture (binded to shader mapTexture2Loc)
|
||||
|
||||
Color colTint; // Tint color
|
||||
Color colDiffuse; // Diffuse color
|
||||
Color colAmbient; // Ambient color
|
||||
Color colSpecular; // Specular color
|
||||
Color colDiffuse; // Diffuse color
|
||||
Color colAmbient; // Ambient color
|
||||
Color colSpecular; // Specular color
|
||||
|
||||
float glossiness; // Glossiness level (Ranges from 0 to 1000)
|
||||
float glossiness; // Glossiness level (Ranges from 0 to 1000)
|
||||
} Material;
|
||||
|
||||
// Model type
|
||||
typedef struct Model {
|
||||
Mesh mesh; // Vertex data buffers (RAM and VRAM)
|
||||
Matrix transform; // Local transform matrix
|
||||
Material material; // Shader and textures data
|
||||
Mesh mesh; // Vertex data buffers (RAM and VRAM)
|
||||
Matrix transform; // Local transform matrix
|
||||
Material material; // Shader and textures data
|
||||
} Model;
|
||||
|
||||
// Light type
|
||||
typedef struct LightData {
|
||||
unsigned int id; // Light id
|
||||
int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
|
||||
bool enabled; // Light enabled
|
||||
unsigned int id; // Light unique id
|
||||
int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
|
||||
bool enabled; // Light enabled
|
||||
|
||||
Vector3 position; // Light position
|
||||
Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float radius; // Light attenuation radius light intensity reduced with distance (world distance)
|
||||
Vector3 position; // Light position
|
||||
Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float radius; // Light attenuation radius light intensity reduced with distance (world distance)
|
||||
|
||||
Color diffuse; // Light diffuse color
|
||||
float intensity; // Light intensity level
|
||||
Color diffuse; // Light diffuse color
|
||||
float intensity; // Light intensity level
|
||||
|
||||
float coneAngle; // Light cone max angle: LIGHT_SPOT
|
||||
float coneAngle; // Light cone max angle: LIGHT_SPOT
|
||||
} LightData, *Light;
|
||||
|
||||
// Light types
|
||||
@ -861,8 +858,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||
//------------------------------------------------------------------------------------
|
||||
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||
|
||||
Shader GetDefaultShader(void); // Get default shader
|
||||
Shader GetStandardShader(void); // Get default shader
|
||||
Texture2D GetDefaultTexture(void); // Get default texture
|
||||
@ -872,7 +868,10 @@ void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // S
|
||||
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
|
||||
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
||||
|
||||
void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
|
||||
void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
||||
void EndShaderMode(void); // End custom shader drawing (use default shader)
|
||||
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
||||
void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
||||
|
||||
Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool
|
||||
void DestroyLight(Light light); // Destroy a light and take it out of the list
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#if defined(RAYMATH_STANDALONE)
|
||||
// Vector2 type
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
|
||||
74
src/rlgl.c
74
src/rlgl.c
@ -28,41 +28,41 @@
|
||||
|
||||
#include "rlgl.h"
|
||||
|
||||
#include <stdio.h> // Standard input / output lib
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management, rand()
|
||||
#include <string.h> // Declares strcmp(), strlen(), strtok()
|
||||
#include <stdio.h> // Standard input / output lib
|
||||
#include <stdlib.h> // Required for: malloc(), free(), rand()
|
||||
#include <string.h> // Required for: strcmp(), strlen(), strtok()
|
||||
|
||||
#ifndef RLGL_STANDALONE
|
||||
#include "raymath.h" // Required for Vector3 and Matrix functions
|
||||
#include "raymath.h" // Required for Vector3 and Matrix functions
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#ifdef __APPLE__ // OpenGL include for OSX
|
||||
#include <OpenGL/gl.h>
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
||||
#else
|
||||
#include <GL/gl.h> // Basic OpenGL include
|
||||
#include <GL/gl.h> // OpenGL 1.1 library
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
#ifdef __APPLE__ // OpenGL include for OSX
|
||||
#include <OpenGL/gl3.h>
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
|
||||
#else
|
||||
//#define GLEW_STATIC
|
||||
//#include <GL/glew.h> // GLEW header, includes OpenGL headers
|
||||
#include "glad.h" // glad header, includes OpenGL headers
|
||||
#include "glad.h" // GLAD library, includes OpenGL headers
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#include <EGL/egl.h> // EGL library
|
||||
#include <GLES2/gl2.h> // OpenGL ES 2.0 library
|
||||
#include <GLES2/gl2ext.h> // OpenGL ES 2.0 extensions library
|
||||
#endif
|
||||
|
||||
#if defined(RLGL_STANDALONE)
|
||||
#include <stdarg.h> // Used for functions with variable number of parameters (TraceLog())
|
||||
#endif
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
#endif // NOTE: Used on TraceLog()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
@ -237,7 +237,7 @@ static Shader LoadDefaultShader(void); // Load default shader (just vertex
|
||||
static Shader LoadStandardShader(void); // Load standard shader (support materials and lighting)
|
||||
static void LoadDefaultShaderLocations(Shader *shader); // Bind default shader locations (attributes and uniforms)
|
||||
static void UnloadDefaultShader(void); // Unload default shader
|
||||
static void UnloadStandardShader(void); // Unload standard shader
|
||||
static void UnloadStandardShader(void); // Unload standard shader
|
||||
|
||||
static void LoadDefaultBuffers(void); // Load default internal buffers (lines, triangles, quads)
|
||||
static void UpdateDefaultBuffers(void); // Update default internal buffers (VAOs/VBOs) with vertex data
|
||||
@ -256,7 +256,7 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
|
||||
|
||||
#if defined(RLGL_STANDALONE)
|
||||
static void TraceLog(int msgType, const char *text, ...);
|
||||
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
|
||||
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -1545,10 +1545,10 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
|
||||
mesh->vboId[5] = 0; // Vertex texcoords2 VBO
|
||||
mesh->vboId[6] = 0; // Vertex indices VBO
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
int drawHint = GL_STATIC_DRAW;
|
||||
if (dynamic) drawHint = GL_DYNAMIC_DRAW;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
GLuint vaoId = 0; // Vertex Array Objects (VAO)
|
||||
GLuint vboId[7]; // Vertex Buffer Objects (VBOs)
|
||||
|
||||
@ -1674,6 +1674,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
|
||||
// Update vertex data on GPU (upload new data to one buffer)
|
||||
void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Activate mesh VAO
|
||||
if (vaoSupported) glBindVertexArray(mesh.vaoId);
|
||||
|
||||
@ -1729,6 +1730,7 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
|
||||
//mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
||||
// Now we can modify vertices
|
||||
//glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw a 3d mesh with material and transform
|
||||
@ -1800,9 +1802,6 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
|
||||
// Setup shader uniforms for lights
|
||||
SetShaderLights(material.shader);
|
||||
|
||||
// Upload to shader material.colSpecular
|
||||
glUniform4f(glGetUniformLocation(material.shader.id, "colTint"), (float)material.colTint.r/255, (float)material.colTint.g/255, (float)material.colTint.b/255, (float)material.colTint.a/255);
|
||||
|
||||
// Upload to shader material.colAmbient
|
||||
glUniform4f(glGetUniformLocation(material.shader.id, "colAmbient"), (float)material.colAmbient.r/255, (float)material.colAmbient.g/255, (float)material.colAmbient.b/255, (float)material.colAmbient.a/255);
|
||||
|
||||
@ -2157,7 +2156,7 @@ void UnloadShader(Shader shader)
|
||||
}
|
||||
|
||||
// Set custom shader to be used on batch draw
|
||||
void SetCustomShader(Shader shader)
|
||||
void BeginShaderMode(Shader shader)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
if (currentShader.id != shader.id)
|
||||
@ -2169,10 +2168,10 @@ void SetCustomShader(Shader shader)
|
||||
}
|
||||
|
||||
// Set default shader to be used in batch draw
|
||||
void SetDefaultShader(void)
|
||||
void EndShaderMode(void)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
SetCustomShader(defaultShader);
|
||||
BeginShaderMode(defaultShader);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2254,9 +2253,9 @@ void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set blending mode (alpha, additive, multiplied)
|
||||
// NOTE: Only 3 blending modes predefined
|
||||
void SetBlendMode(int mode)
|
||||
// Begin blending mode (alpha, additive, multiplied)
|
||||
// NOTE: Only 3 blending modes supported, default blend mode is alpha
|
||||
void BeginBlendMode(int mode)
|
||||
{
|
||||
if ((blendMode != mode) && (mode < 3))
|
||||
{
|
||||
@ -2274,11 +2273,20 @@ void SetBlendMode(int mode)
|
||||
}
|
||||
}
|
||||
|
||||
// End blending mode (reset to default: alpha blending)
|
||||
void EndBlendMode(void)
|
||||
{
|
||||
BeginBlendMode(BLEND_ALPHA);
|
||||
}
|
||||
|
||||
// Create a new light, initialize it and add to pool
|
||||
Light CreateLight(int type, Vector3 position, Color diffuse)
|
||||
{
|
||||
Light light = NULL;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Allocate dynamic memory
|
||||
Light light = (Light)malloc(sizeof(LightData));
|
||||
light = (Light)malloc(sizeof(LightData));
|
||||
|
||||
// Initialize light values with generic values
|
||||
light->id = lightsCount;
|
||||
@ -2295,13 +2303,18 @@ Light CreateLight(int type, Vector3 position, Color diffuse)
|
||||
|
||||
// Increase enabled lights count
|
||||
lightsCount++;
|
||||
|
||||
#else
|
||||
// TODO: Support OpenGL 1.1 lighting system
|
||||
TraceLog(WARNING, "Lighting currently not supported on OpenGL 1.1");
|
||||
#endif
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
// Destroy a light and take it out of the list
|
||||
void DestroyLight(Light light)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// Free dynamic memory allocation
|
||||
free(lights[light->id]);
|
||||
|
||||
@ -2319,6 +2332,7 @@ void DestroyLight(Light light)
|
||||
|
||||
// Decrease enabled physic objects count
|
||||
lightsCount--;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -2366,7 +2380,7 @@ static void LoadCompressedTexture(unsigned char *data, int width, int height, in
|
||||
static unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr)
|
||||
{
|
||||
unsigned int program = 0;
|
||||
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
GLuint vertexShader;
|
||||
GLuint fragmentShader;
|
||||
|
||||
121
src/rlgl.h
121
src/rlgl.h
@ -32,15 +32,15 @@
|
||||
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
||||
|
||||
#ifndef RLGL_STANDALONE
|
||||
#include "raylib.h" // Required for typedef(s): Model, Shader, Texture2D
|
||||
#include "utils.h" // Required for function TraceLog()
|
||||
#include "raylib.h" // Required for: Model, Shader, Texture2D
|
||||
#include "utils.h" // Required for: TraceLog()
|
||||
#endif
|
||||
|
||||
#ifdef RLGL_STANDALONE
|
||||
#define RAYMATH_STANDALONE
|
||||
#endif
|
||||
|
||||
#include "raymath.h" // Required for types: Vector3, Matrix
|
||||
#include "raymath.h" // Required for: Vector3, Matrix
|
||||
|
||||
// Select desired OpenGL version
|
||||
// NOTE: Those preprocessor defines are only used on rlgl module,
|
||||
@ -130,51 +130,43 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||
COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
|
||||
COMPRESSED_ASTC_8x8_RGBA // 2 bpp
|
||||
} TextureFormat;
|
||||
|
||||
// Bounding box type
|
||||
typedef struct BoundingBox {
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
} BoundingBox;
|
||||
|
||||
// Vertex data definning a mesh
|
||||
typedef struct Mesh {
|
||||
int vertexCount; // number of vertices stored in arrays
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
unsigned short *indices; // vertex indices (in case vertex data comes indexed)
|
||||
int triangleCount; // number of triangles stored (indexed or not)
|
||||
|
||||
BoundingBox bounds; // mesh limits defined by min and max points
|
||||
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
||||
int vertexCount; // number of vertices stored in arrays
|
||||
int triangleCount; // number of triangles stored (indexed or not)
|
||||
float *vertices; // vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||
float *texcoords; // vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||
float *texcoords2; // vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
||||
float *normals; // vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
||||
float *tangents; // vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
||||
unsigned char *colors; // vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
unsigned short *indices;// vertex indices (in case vertex data comes indexed)
|
||||
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
unsigned int vboId[7]; // OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
||||
} Mesh;
|
||||
|
||||
// Shader type (generic shader)
|
||||
typedef struct Shader {
|
||||
unsigned int id; // Shader program id
|
||||
unsigned int id; // Shader program id
|
||||
|
||||
// Vertex attributes locations (default locations)
|
||||
int vertexLoc; // Vertex attribute location point (default-location = 0)
|
||||
int texcoordLoc; // Texcoord attribute location point (default-location = 1)
|
||||
int normalLoc; // Normal attribute location point (default-location = 2)
|
||||
int colorLoc; // Color attibute location point (default-location = 3)
|
||||
int tangentLoc; // Tangent attribute location point (default-location = 4)
|
||||
int texcoord2Loc; // Texcoord2 attribute location point (default-location = 5)
|
||||
int vertexLoc; // Vertex attribute location point (default-location = 0)
|
||||
int texcoordLoc; // Texcoord attribute location point (default-location = 1)
|
||||
int normalLoc; // Normal attribute location point (default-location = 2)
|
||||
int colorLoc; // Color attibute location point (default-location = 3)
|
||||
int tangentLoc; // Tangent attribute location point (default-location = 4)
|
||||
int texcoord2Loc; // Texcoord2 attribute location point (default-location = 5)
|
||||
|
||||
// Uniform locations
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
int tintColorLoc; // Color uniform location point (fragment shader)
|
||||
int mvpLoc; // ModelView-Projection matrix uniform location point (vertex shader)
|
||||
int tintColorLoc; // Color uniform location point (fragment shader)
|
||||
|
||||
// Texture map locations (generic for any kind of map)
|
||||
int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0)
|
||||
int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1)
|
||||
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||
int mapTexture0Loc; // Map texture uniform location point (default-texture-unit = 0)
|
||||
int mapTexture1Loc; // Map texture uniform location point (default-texture-unit = 1)
|
||||
int mapTexture2Loc; // Map texture uniform location point (default-texture-unit = 2)
|
||||
} Shader;
|
||||
|
||||
// Texture2D type
|
||||
@ -196,36 +188,46 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||
|
||||
// Material type
|
||||
typedef struct Material {
|
||||
Shader shader; // Standard shader (supports 3 map types: diffuse, normal, specular)
|
||||
Shader shader; // Standard shader (supports 3 map types: diffuse, normal, specular)
|
||||
|
||||
Texture2D texDiffuse; // Diffuse texture
|
||||
Texture2D texNormal; // Normal texture
|
||||
Texture2D texSpecular; // Specular texture
|
||||
Texture2D texDiffuse; // Diffuse texture
|
||||
Texture2D texNormal; // Normal texture
|
||||
Texture2D texSpecular; // Specular texture
|
||||
|
||||
Color colDiffuse; // Diffuse color
|
||||
Color colAmbient; // Ambient color
|
||||
Color colSpecular; // Specular color
|
||||
|
||||
Color colTint; // Tint color
|
||||
Color colDiffuse; // Diffuse color
|
||||
Color colAmbient; // Ambient color
|
||||
Color colSpecular; // Specular color
|
||||
|
||||
float glossiness; // Glossiness level (Ranges from 0 to 1000)
|
||||
float glossiness; // Glossiness level (Ranges from 0 to 1000)
|
||||
} Material;
|
||||
|
||||
// Camera type, defines a camera position/orientation in 3d space
|
||||
typedef struct Camera {
|
||||
Vector3 position; // Camera position
|
||||
Vector3 target; // Camera target it looks-at
|
||||
Vector3 up; // Camera up vector (rotation over its axis)
|
||||
float fovy; // Camera field-of-view apperture in Y (degrees)
|
||||
} Camera;
|
||||
|
||||
// Light type
|
||||
typedef struct LightData {
|
||||
int id;
|
||||
int type; // LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
|
||||
bool enabled;
|
||||
unsigned int id; // Light unique id
|
||||
int type; // Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
|
||||
bool enabled; // Light enabled
|
||||
|
||||
Vector3 position;
|
||||
Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float radius; // Lost of light intensity with distance (world distance)
|
||||
Vector3 position; // Light position
|
||||
Vector3 target; // Light target: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float radius; // Light attenuation radius light intensity reduced with distance (world distance)
|
||||
|
||||
Color diffuse; // Use Vector3 diffuse
|
||||
float intensity;
|
||||
Color diffuse; // Light diffuse color
|
||||
float intensity; // Light intensity level
|
||||
|
||||
float coneAngle; // Spot light max angle
|
||||
float coneAngle; // Light cone max angle: LIGHT_SPOT
|
||||
} LightData, *Light;
|
||||
|
||||
|
||||
// Light types
|
||||
typedef enum { LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT } LightType;
|
||||
|
||||
// Color blending modes (pre-defined)
|
||||
typedef enum { BLEND_ALPHA = 0, BLEND_ADDITIVE, BLEND_MULTIPLIED } BlendMode;
|
||||
#endif
|
||||
@ -317,9 +319,9 @@ void *rlglReadTexturePixels(Texture2D texture); // Read text
|
||||
//------------------------------------------------------------------------------------
|
||||
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
|
||||
void UnloadShader(Shader shader); // Unload a custom shader from memory
|
||||
void SetCustomShader(Shader shader); // Set custom shader to be used in batch draw
|
||||
void SetDefaultShader(void); // Set default shader to be used in batch draw
|
||||
|
||||
Shader GetDefaultShader(void); // Get default shader
|
||||
Shader GetStandardShader(void); // Get default shader
|
||||
Texture2D GetDefaultTexture(void); // Get default texture
|
||||
|
||||
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
|
||||
@ -327,7 +329,10 @@ void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // S
|
||||
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
|
||||
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
|
||||
|
||||
void SetBlendMode(int mode); // Set blending mode (alpha, additive, multiplied)
|
||||
void BeginShaderMode(Shader shader); // Begin custom shader drawing
|
||||
void EndShaderMode(void); // End custom shader drawing (use default shader)
|
||||
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
|
||||
void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
|
||||
|
||||
Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool
|
||||
void DestroyLight(Light light); // Destroy a light and take it out of the list
|
||||
|
||||
@ -489,7 +489,7 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
|
||||
retRec.height = rec2.height - dyy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (rec1.width > rec2.width)
|
||||
{
|
||||
if (retRec.width >= rec2.width) retRec.width = rec2.width;
|
||||
|
||||
12
src/text.c
12
src/text.c
@ -25,16 +25,16 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||
#include <string.h> // String management functions (just strlen() is used)
|
||||
#include <stdarg.h> // Used for functions with variable number of parameters (FormatText())
|
||||
#include <stdio.h> // Standard input / output lib
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strlen()
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
|
||||
|
||||
#include "utils.h" // Required for function GetExtension()
|
||||
#include "utils.h" // Required for: GetExtension()
|
||||
|
||||
// Following libs are used on LoadTTF()
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include "stb_truetype.h"
|
||||
#include "stb_truetype.h" // Required for: stbtt_BakeFontBitmap()
|
||||
|
||||
// Rectangle packing functions (not used at the moment)
|
||||
//#define STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <stdlib.h> // Declares malloc() and free() for memory management
|
||||
#include <string.h> // Required for strcmp(), strrchr(), strncmp()
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <string.h> // Required for: strcmp(), strrchr(), strncmp()
|
||||
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
|
||||
// Required: rlglLoadTexture() rlDeleteTextures(),
|
||||
@ -40,10 +40,12 @@
|
||||
// NOTE: Includes Android fopen function map
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h" // Used to read image data (multiple formats support)
|
||||
#include "stb_image.h" // Required for: stbi_load()
|
||||
// NOTE: Used to read image data (multiple formats support)
|
||||
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include "stb_image_resize.h" // Used on image scaling function: ImageResize()
|
||||
#include "stb_image_resize.h" // Required for: stbir_resize_uint8()
|
||||
// NOTE: Used for image scaling on ImageResize()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
@ -1394,39 +1396,43 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Co
|
||||
// NOTE: origin is relative to destination rectangle size
|
||||
void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint)
|
||||
{
|
||||
if (sourceRec.width < 0) sourceRec.x -= sourceRec.width;
|
||||
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||
|
||||
rlEnableTexture(texture.id);
|
||||
// Check if texture is valid
|
||||
if (texture.id != 0)
|
||||
{
|
||||
if (sourceRec.width < 0) sourceRec.x -= sourceRec.width;
|
||||
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||
|
||||
rlEnableTexture(texture.id);
|
||||
|
||||
rlPushMatrix();
|
||||
rlTranslatef(destRec.x, destRec.y, 0);
|
||||
rlRotatef(rotation, 0, 0, 1);
|
||||
rlTranslatef(-origin.x, -origin.y, 0);
|
||||
rlPushMatrix();
|
||||
rlTranslatef(destRec.x, destRec.y, 0);
|
||||
rlRotatef(rotation, 0, 0, 1);
|
||||
rlTranslatef(-origin.x, -origin.y, 0);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
||||
|
||||
// Bottom-left corner for texture and quad
|
||||
rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height);
|
||||
rlVertex2f(0.0f, 0.0f);
|
||||
// Bottom-left corner for texture and quad
|
||||
rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height);
|
||||
rlVertex2f(0.0f, 0.0f);
|
||||
|
||||
// Bottom-right corner for texture and quad
|
||||
rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
|
||||
rlVertex2f(0.0f, destRec.height);
|
||||
// Bottom-right corner for texture and quad
|
||||
rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
|
||||
rlVertex2f(0.0f, destRec.height);
|
||||
|
||||
// Top-right corner for texture and quad
|
||||
rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
|
||||
rlVertex2f(destRec.width, destRec.height);
|
||||
// Top-right corner for texture and quad
|
||||
rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height);
|
||||
rlVertex2f(destRec.width, destRec.height);
|
||||
|
||||
// Top-left corner for texture and quad
|
||||
rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height);
|
||||
rlVertex2f(destRec.width, 0.0f);
|
||||
rlEnd();
|
||||
rlPopMatrix();
|
||||
// Top-left corner for texture and quad
|
||||
rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height);
|
||||
rlVertex2f(destRec.width, 0.0f);
|
||||
rlEnd();
|
||||
rlPopMatrix();
|
||||
|
||||
rlDisableTexture();
|
||||
rlDisableTexture();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
10
src/utils.c
10
src/utils.c
@ -35,14 +35,14 @@
|
||||
#include <android/asset_manager.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> // malloc(), free()
|
||||
#include <stdio.h> // printf(), fprintf()
|
||||
#include <stdarg.h> // Used for functions with variable number of parameters (TraceLog())
|
||||
//#include <string.h> // String management functions: strlen(), strrchr(), strcmp()
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <stdio.h> // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen()
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
//#include <string.h> // Required for: strlen(), strrchr(), strcmp()
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h" // Create PNG file
|
||||
#include "stb_image_write.h" // Required for: stbi_write_png()
|
||||
#endif
|
||||
|
||||
#include "tinfl.c"
|
||||
|
||||
@ -27,8 +27,8 @@
|
||||
#define UTILS_H
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#include <stdio.h> // Defines FILE struct
|
||||
#include <android/asset_manager.h> // defines AAssetManager struct
|
||||
#include <stdio.h> // Required for: FILE
|
||||
#include <android/asset_manager.h> // Required for: AAssetManager
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user