Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
This commit is contained in:
commit
6ad8323860
13 changed files with 165 additions and 6481 deletions
BIN
examples/resources/model/dwarf_normal.png
Normal file
BIN
examples/resources/model/dwarf_normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 MiB |
BIN
examples/resources/model/dwarf_specular.png
Normal file
BIN
examples/resources/model/dwarf_specular.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 MiB |
File diff suppressed because it is too large
Load diff
|
@ -8,12 +8,18 @@ in vec3 fragNormal;
|
|||
out vec4 finalColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
uniform vec4 colTint;
|
||||
uniform vec4 colAmbient;
|
||||
uniform vec4 colDiffuse;
|
||||
uniform vec4 colSpecular;
|
||||
uniform float glossiness;
|
||||
|
||||
uniform int useNormal;
|
||||
uniform int useSpecular;
|
||||
|
||||
uniform mat4 modelMatrix;
|
||||
uniform vec3 viewDir;
|
||||
|
||||
|
@ -24,7 +30,7 @@ struct Light {
|
|||
vec3 direction;
|
||||
vec4 diffuse;
|
||||
float intensity;
|
||||
float attenuation;
|
||||
float radius;
|
||||
float coneAngle;
|
||||
};
|
||||
|
||||
|
@ -32,27 +38,27 @@ const int maxLights = 8;
|
|||
uniform int lightsCount;
|
||||
uniform Light lights[maxLights];
|
||||
|
||||
vec3 CalcPointLight(Light l, vec3 n, vec3 v)
|
||||
vec3 CalcPointLight(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||
vec3 surfaceToLight = l.position - surfacePos;
|
||||
|
||||
// Diffuse shading
|
||||
float brightness = clamp(dot(n, surfaceToLight)/(length(surfaceToLight)*length(n)), 0, 1);
|
||||
float diff = 1.0/dot(surfaceToLight/l.attenuation, surfaceToLight/l.attenuation)*brightness*l.intensity;
|
||||
float diff = 1.0/dot(surfaceToLight/l.radius, surfaceToLight/l.radius)*brightness*l.intensity;
|
||||
|
||||
// Specular shading
|
||||
float spec = 0.0;
|
||||
if (diff > 0.0)
|
||||
{
|
||||
vec3 h = normalize(-l.direction + v);
|
||||
spec = pow(dot(n, h), 3 + glossiness);
|
||||
spec = pow(dot(n, h), 3 + glossiness)*s;
|
||||
}
|
||||
|
||||
return (diff*l.diffuse.rgb*colDiffuse.rgb + spec*colSpecular.rgb);
|
||||
}
|
||||
|
||||
vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v)
|
||||
vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 lightDir = normalize(-l.direction);
|
||||
|
||||
|
@ -64,14 +70,14 @@ vec3 CalcDirectionalLight(Light l, vec3 n, vec3 v)
|
|||
if (diff > 0.0)
|
||||
{
|
||||
vec3 h = normalize(lightDir + v);
|
||||
spec = pow(dot(n, h), 3 + glossiness);
|
||||
spec = pow(dot(n, h), 3 + glossiness)*s;
|
||||
}
|
||||
|
||||
// Combine results
|
||||
return (diff*l.intensity*l.diffuse.rgb*colDiffuse.rgb + spec*colSpecular.rgb);
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(Light l, vec3 n, vec3 v)
|
||||
vec3 CalcSpotLight(Light l, vec3 n, vec3 v, float s)
|
||||
{
|
||||
vec3 surfacePos = vec3(modelMatrix*vec4(fragPosition, 1));
|
||||
vec3 lightToSurface = normalize(surfacePos - l.position);
|
||||
|
@ -95,7 +101,7 @@ vec3 CalcSpotLight(Light l, vec3 n, vec3 v)
|
|||
if (diffAttenuation > 0.0)
|
||||
{
|
||||
vec3 h = normalize(lightDir + v);
|
||||
spec = pow(dot(n, h), 3 + glossiness);
|
||||
spec = pow(dot(n, h), 3 + glossiness)*s;
|
||||
}
|
||||
|
||||
return falloff*(diffAttenuation*l.diffuse.rgb + spec*colSpecular.rgb);
|
||||
|
@ -104,9 +110,10 @@ vec3 CalcSpotLight(Light l, vec3 n, vec3 v)
|
|||
void main()
|
||||
{
|
||||
// Calculate fragment normal in screen space
|
||||
// NOTE: important to multiply model matrix by fragment normal to apply model transformation (rotation and scale)
|
||||
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
|
||||
vec3 normal = normalize(normalMatrix*fragNormal);
|
||||
|
||||
|
||||
// Normalize normal and view direction vectors
|
||||
vec3 n = normalize(normal);
|
||||
vec3 v = normalize(viewDir);
|
||||
|
@ -115,6 +122,17 @@ void main()
|
|||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
vec3 lighting = colAmbient.rgb;
|
||||
|
||||
// Calculate normal texture color fetching or set to maximum normal value by default
|
||||
if(useNormal == 1)
|
||||
{
|
||||
n *= texture(texture1, fragTexCoord).rgb;
|
||||
n = normalize(n);
|
||||
}
|
||||
|
||||
// Calculate specular texture color fetching or set to maximum specular value by default
|
||||
float spec = 1.0;
|
||||
if(useSpecular == 1) spec *= normalize(texture(texture2, fragTexCoord).r);
|
||||
|
||||
for (int i = 0; i < lightsCount; i++)
|
||||
{
|
||||
// Check if light is enabled
|
||||
|
@ -123,14 +141,14 @@ void main()
|
|||
// Calculate lighting based on light type
|
||||
switch (lights[i].type)
|
||||
{
|
||||
case 0: lighting += CalcPointLight(lights[i], n, v); break;
|
||||
case 1: lighting += CalcDirectionalLight(lights[i], n, v); break;
|
||||
case 2: lighting += CalcSpotLight(lights[i], n, v); break;
|
||||
case 0: lighting += CalcPointLight(lights[i], n, v, spec); break;
|
||||
case 1: lighting += CalcDirectionalLight(lights[i], n, v, spec); break;
|
||||
case 2: lighting += CalcSpotLight(lights[i], n, v, spec); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate final fragment color
|
||||
finalColor = vec4(texelColor.rgb*lighting, texelColor.a);
|
||||
finalColor = vec4(texelColor.rgb*lighting*colTint.rgb, texelColor.a*colTint.a);
|
||||
}
|
||||
|
|
|
@ -89,6 +89,8 @@ int main()
|
|||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
End3dMode();
|
||||
|
||||
DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED);
|
||||
|
||||
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ int main()
|
|||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 720;
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
|
||||
|
@ -36,13 +36,18 @@ int main()
|
|||
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||
|
||||
Material material = LoadStandardMaterial();
|
||||
|
||||
material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model diffuse texture
|
||||
material.texNormal = LoadTexture("resources/model/dwarf_normal.png"); // Load model normal texture
|
||||
material.texSpecular = LoadTexture("resources/model/dwarf_specular.png"); // Load model specular texture
|
||||
material.colDiffuse = (Color){255, 255, 255, 255};
|
||||
material.colAmbient = (Color){0, 0, 10, 255};
|
||||
material.colSpecular = (Color){255, 255, 255, 255};
|
||||
material.glossiness = 50.0f;
|
||||
|
||||
dwarf.material = material; // Apply material to model
|
||||
|
||||
Model dwarf2 = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||
|
||||
Light spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255});
|
||||
spotLight->target = (Vector3){0.0f, 0.0f, 0.0f};
|
||||
|
@ -58,10 +63,10 @@ int main()
|
|||
Light pointLight = CreateLight(LIGHT_POINT, (Vector3){0.0f, 4.0f, 5.0f}, (Color){255, 255, 255, 255});
|
||||
pointLight->intensity = 2.0f;
|
||||
pointLight->diffuse = (Color){100, 100, 255, 255};
|
||||
pointLight->attenuation = 3.0f;
|
||||
pointLight->radius = 3.0f;
|
||||
|
||||
// Setup orbital camera
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set a orbital camera mode
|
||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
||||
|
||||
|
@ -83,7 +88,7 @@ int main()
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
Begin3dMode(camera);
|
||||
|
||||
|
||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawLights(); // Draw all created lights in 3D world
|
||||
|
@ -93,7 +98,7 @@ int main()
|
|||
End3dMode();
|
||||
|
||||
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
|
64
src/core.c
64
src/core.c
|
@ -147,6 +147,7 @@ static bool windowMinimized = false;
|
|||
static struct android_app *app; // Android activity
|
||||
static struct android_poll_source *source; // Android events polling source
|
||||
static int ident, events; // Android ALooper_pollAll() variables
|
||||
static const char *internalDataPath; // Android internal data path to write data (/data/data/<package>/files)
|
||||
|
||||
static bool windowReady = false; // Used to detect display initialization
|
||||
static bool appEnabled = true; // Used to detec if app is active
|
||||
|
@ -363,6 +364,7 @@ void InitWindow(int width, int height, struct android_app *state)
|
|||
screenHeight = height;
|
||||
|
||||
app = state;
|
||||
internalDataPath = app->activity->internalDataPath;
|
||||
|
||||
// Set desired windows flags before initializing anything
|
||||
ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
|
||||
|
@ -562,9 +564,8 @@ void Begin2dMode(Camera2D camera)
|
|||
Matrix matOrigin = MatrixTranslate(-camera.target.x, -camera.target.y, 0.0f);
|
||||
Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD);
|
||||
Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f);
|
||||
|
||||
Matrix matTranslation = MatrixTranslate(camera.offset.x + camera.target.x, camera.offset.y + camera.target.y, 0.0f);
|
||||
|
||||
|
||||
Matrix matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation);
|
||||
|
||||
rlMultMatrixf(MatrixToFloat(matTransform));
|
||||
|
@ -627,11 +628,24 @@ void BeginTextureMode(RenderTexture2D target)
|
|||
{
|
||||
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
|
||||
|
||||
rlEnableRenderTexture(target.id);
|
||||
|
||||
rlClearScreenBuffers(); // Clear render texture buffers
|
||||
rlEnableRenderTexture(target.id); // Enable render target
|
||||
|
||||
rlClearScreenBuffers(); // Clear render texture buffers
|
||||
|
||||
// Set viewport to framebuffer size
|
||||
rlViewport(0, 0, target.texture.width, target.texture.height);
|
||||
|
||||
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
||||
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
||||
|
||||
// Set orthographic projection to current framebuffer size
|
||||
// NOTE: Configured top-left corner as (0, 0)
|
||||
rlOrtho(0, target.texture.width, target.texture.height, 0, 0.0f, 1.0f);
|
||||
|
||||
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
|
||||
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
||||
|
||||
//rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?)
|
||||
}
|
||||
|
||||
// Ends drawing to render texture
|
||||
|
@ -639,7 +653,21 @@ void EndTextureMode(void)
|
|||
{
|
||||
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
|
||||
|
||||
rlDisableRenderTexture();
|
||||
rlDisableRenderTexture(); // Disable render target
|
||||
|
||||
// Set viewport to default framebuffer size (screen size)
|
||||
// TODO: consider possible viewport offsets
|
||||
rlViewport(0, 0, GetScreenWidth(), GetScreenHeight());
|
||||
|
||||
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
||||
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
||||
|
||||
// Set orthographic projection to current framebuffer size
|
||||
// NOTE: Configured top-left corner as (0, 0)
|
||||
rlOrtho(0, GetScreenWidth(), GetScreenHeight(), 0, 0.0f, 1.0f);
|
||||
|
||||
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
|
||||
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
||||
}
|
||||
|
||||
// Set target FPS for the game
|
||||
|
@ -812,12 +840,21 @@ void ClearDroppedFiles(void)
|
|||
void StorageSaveValue(int position, int value)
|
||||
{
|
||||
FILE *storageFile = NULL;
|
||||
|
||||
char path[128];
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
strcpy(path, internalDataPath);
|
||||
strcat(path, "/");
|
||||
strcat(path, STORAGE_FILENAME);
|
||||
#else
|
||||
strcpy(path, STORAGE_FILENAME);
|
||||
#endif
|
||||
|
||||
// Try open existing file to append data
|
||||
storageFile = fopen(STORAGE_FILENAME, "rb+");
|
||||
storageFile = fopen(path, "rb+");
|
||||
|
||||
// If file doesn't exist, create a new storage data file
|
||||
if (!storageFile) storageFile = fopen(STORAGE_FILENAME, "wb");
|
||||
if (!storageFile) storageFile = fopen(path, "wb");
|
||||
|
||||
if (!storageFile) TraceLog(WARNING, "Storage data file could not be created");
|
||||
else
|
||||
|
@ -844,8 +881,17 @@ int StorageLoadValue(int position)
|
|||
{
|
||||
int value = 0;
|
||||
|
||||
char path[128];
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
strcpy(path, internalDataPath);
|
||||
strcat(path, "/");
|
||||
strcat(path, STORAGE_FILENAME);
|
||||
#else
|
||||
strcpy(path, STORAGE_FILENAME);
|
||||
#endif
|
||||
|
||||
// Try open existing file to append data
|
||||
FILE *storageFile = fopen(STORAGE_FILENAME, "rb");
|
||||
FILE *storageFile = fopen(path, "rb");
|
||||
|
||||
if (!storageFile) TraceLog(WARNING, "Storage data file could not be found");
|
||||
else
|
||||
|
|
23
src/models.c
23
src/models.c
|
@ -75,6 +75,25 @@ void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color)
|
|||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw a circle in 3D world space
|
||||
void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color)
|
||||
{
|
||||
rlPushMatrix();
|
||||
rlTranslatef(center.x, center.y, center.z);
|
||||
rlRotatef(rotationAngle, rotation.x, rotation.y, rotation.z);
|
||||
|
||||
rlBegin(RL_LINES);
|
||||
for (int i = 0; i < 360; i += 10)
|
||||
{
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlVertex3f(sin(DEG2RAD*i)*radius, cos(DEG2RAD*i)*radius, 0.0f);
|
||||
rlVertex3f(sin(DEG2RAD*(i + 10)) * radius, cos(DEG2RAD*(i + 10)) * radius, 0.0f);
|
||||
}
|
||||
rlEnd();
|
||||
rlPopMatrix();
|
||||
}
|
||||
|
||||
// Draw cube
|
||||
// NOTE: Cube position is the center position
|
||||
void DrawCube(Vector3 position, float width, float height, float length, Color color)
|
||||
|
@ -732,12 +751,12 @@ Material LoadDefaultMaterial(void)
|
|||
//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
|
||||
|
||||
material.glossiness = 100.0f; // Glossiness level
|
||||
material.normalDepth = 1.0f; // Normal map depth
|
||||
|
||||
return material;
|
||||
}
|
||||
|
@ -1250,7 +1269,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.colDiffuse = tint;
|
||||
model.material.colTint = tint;
|
||||
|
||||
rlglDrawMesh(model.mesh, model.material, model.transform);
|
||||
}
|
||||
|
|
|
@ -414,12 +414,12 @@ typedef struct Material {
|
|||
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
|
||||
|
||||
float glossiness; // Glossiness level (Ranges from 0 to 1000)
|
||||
float normalDepth; // Normal map depth
|
||||
} Material;
|
||||
|
||||
// Model type
|
||||
|
@ -437,7 +437,7 @@ typedef struct LightData {
|
|||
|
||||
Vector3 position;
|
||||
Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float attenuation; // Lost of light intensity with distance (world distance)
|
||||
float radius; // Lost of light intensity with distance (world distance)
|
||||
|
||||
Color diffuse; // Light color
|
||||
float intensity; // Light intensity level
|
||||
|
@ -803,6 +803,7 @@ const char *SubText(const char *text, int position, int length);
|
|||
// Basic 3d Shapes Drawing Functions (Module: models)
|
||||
//------------------------------------------------------------------------------------
|
||||
void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space
|
||||
void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space
|
||||
void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube
|
||||
void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version)
|
||||
void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires
|
||||
|
|
44
src/rlgl.c
44
src/rlgl.c
|
@ -204,8 +204,8 @@ static bool texCompPVRTSupported = false; // PVR texture compression support
|
|||
static bool texCompASTCSupported = false; // ASTC texture compression support
|
||||
|
||||
// Lighting data
|
||||
static Light lights[MAX_LIGHTS]; // Lights pool
|
||||
static int lightsCount; // Counts current enabled physic objects
|
||||
static Light lights[MAX_LIGHTS]; // Lights pool
|
||||
static int lightsCount; // Counts current enabled physic objects
|
||||
#endif
|
||||
|
||||
// Compressed textures support flags
|
||||
|
@ -404,6 +404,12 @@ void rlOrtho(double left, double right, double bottom, double top, double near,
|
|||
|
||||
#endif
|
||||
|
||||
// Set the viewport area (trasnformation from normalized device coordinates to window coordinates)
|
||||
void rlViewport(int x, int y, int width, int height)
|
||||
{
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vertex level operations
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -725,17 +731,25 @@ void rlDisableTexture(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Enable rendering to texture (fbo)
|
||||
void rlEnableRenderTexture(unsigned int id)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
||||
|
||||
//glDisable(GL_CULL_FACE); // Allow double side drawing for texture flipping
|
||||
//glCullFace(GL_FRONT);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Disable rendering to texture
|
||||
void rlDisableRenderTexture(void)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//glEnable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1779,6 +1793,9 @@ 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);
|
||||
|
||||
|
@ -1796,16 +1813,19 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
|
||||
if ((material.texNormal.id != 0) && (material.shader.mapTexture1Loc != -1))
|
||||
{
|
||||
// Upload to shader specular map flag
|
||||
glUniform1i(glGetUniformLocation(material.shader.id, "useNormal"), 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, material.texNormal.id);
|
||||
glUniform1i(material.shader.mapTexture1Loc, 1); // Normal texture fits in active texture unit 1
|
||||
|
||||
// TODO: Upload to shader normalDepth
|
||||
//glUniform1f(???, material.normalDepth);
|
||||
}
|
||||
|
||||
if ((material.texSpecular.id != 0) && (material.shader.mapTexture2Loc != -1))
|
||||
{
|
||||
// Upload to shader specular map flag
|
||||
glUniform1i(glGetUniformLocation(material.shader.id, "useSpecular"), 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, material.texSpecular.id);
|
||||
glUniform1i(material.shader.mapTexture2Loc, 2); // Specular texture fits in active texture unit 2
|
||||
|
@ -2279,7 +2299,13 @@ void DrawLights(void)
|
|||
{
|
||||
switch (lights[i]->type)
|
||||
{
|
||||
case LIGHT_POINT: DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK)); break;
|
||||
case LIGHT_POINT:
|
||||
{
|
||||
DrawSphereWires(lights[i]->position, 0.3f*lights[i]->intensity, 4, 8, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||
Draw3DCircle(lights[i]->position, lights[i]->radius, 0.0f, (Vector3){ 0, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||
Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 1, 0, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||
Draw3DCircle(lights[i]->position, lights[i]->radius, 90.0f, (Vector3){ 0, 1, 0 }, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||
} break;
|
||||
case LIGHT_DIRECTIONAL:
|
||||
{
|
||||
Draw3DLine(lights[i]->position, lights[i]->target, (lights[i]->enabled ? lights[i]->diffuse : BLACK));
|
||||
|
@ -2539,7 +2565,7 @@ static Shader LoadDefaultShader(void)
|
|||
// Load standard shader
|
||||
// NOTE: This shader supports:
|
||||
// - Up to 3 different maps: diffuse, normal, specular
|
||||
// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness, normalDepth
|
||||
// - Material properties: colAmbient, colDiffuse, colSpecular, glossiness
|
||||
// - Up to 8 lights: Point, Directional or Spot
|
||||
static Shader LoadStandardShader(void)
|
||||
{
|
||||
|
@ -3091,9 +3117,9 @@ static void SetShaderLights(Shader shader)
|
|||
locPoint = GetShaderLocation(shader, locName);
|
||||
glUniform3f(locPoint, lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
|
||||
|
||||
memcpy(&locName[10], "attenuation\0", strlen("attenuation\0"));
|
||||
memcpy(&locName[10], "radius\0", strlen("radius\0") + 2);
|
||||
locPoint = GetShaderLocation(shader, locName);
|
||||
glUniform1f(locPoint, lights[i]->attenuation);
|
||||
glUniform1f(locPoint, lights[i]->radius);
|
||||
} break;
|
||||
case LIGHT_DIRECTIONAL:
|
||||
{
|
||||
|
|
|
@ -202,12 +202,12 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
|||
Texture2D texNormal; // Normal texture
|
||||
Texture2D texSpecular; // Specular texture
|
||||
|
||||
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 normalDepth; // Normal map depth
|
||||
} Material;
|
||||
|
||||
// Light type
|
||||
|
@ -218,7 +218,7 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
|||
|
||||
Vector3 position;
|
||||
Vector3 target; // Used on LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
|
||||
float attenuation; // Lost of light intensity with distance (world distance)
|
||||
float radius; // Lost of light intensity with distance (world distance)
|
||||
|
||||
Color diffuse; // Use Vector3 diffuse
|
||||
float intensity;
|
||||
|
@ -247,6 +247,7 @@ void rlScalef(float x, float y, float z); // Multiply the current matrix b
|
|||
void rlMultMatrixf(float *mat); // Multiply the current matrix by another matrix
|
||||
void rlFrustum(double left, double right, double bottom, double top, double near, double far);
|
||||
void rlOrtho(double left, double right, double bottom, double top, double near, double far);
|
||||
void rlViewport(int x, int y, int width, int height); // Set the viewport area
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Functions Declaration - Vertex level operations
|
||||
|
|
|
@ -1385,10 +1385,6 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
|
|||
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
|
||||
{
|
||||
Rectangle destRec = { (int)position.x, (int)position.y, abs(sourceRec.width), abs(sourceRec.height) };
|
||||
|
||||
if (sourceRec.width < 0) sourceRec.x -= sourceRec.width;
|
||||
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||
|
||||
Vector2 origin = { 0, 0 };
|
||||
|
||||
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
|
||||
|
@ -1398,6 +1394,9 @@ 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);
|
||||
|
||||
rlPushMatrix();
|
||||
|
|
|
@ -247,7 +247,7 @@ FILE *android_fopen(const char *fileName, const char *mode)
|
|||
|
||||
AAsset *asset = AAssetManager_open(assetManager, fileName, 0);
|
||||
|
||||
if(!asset) return NULL;
|
||||
if (!asset) return NULL;
|
||||
|
||||
return funopen(asset, android_read, android_write, android_seek, android_close);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue