mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-08 07:09:18 -05:00
Compare commits
6 Commits
43c81d216c
...
37149082e8
| Author | SHA1 | Date | |
|---|---|---|---|
| 37149082e8 | |||
| 0e57a572b4 | |||
| beabb1300d | |||
| 218a806ec2 | |||
| 317c1eaeeb | |||
| 3da2fc1bf8 |
67
examples/shaders/resources/shaders/glsl100/ascii.fs
Normal file
67
examples/shaders/resources/shaders/glsl100/ascii.fs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
// Input from the vertex shader
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
|
// Output color for the screen
|
||||||
|
varying vec4 finalColor;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform float fontSize;
|
||||||
|
|
||||||
|
float greyScale(in vec3 col) {
|
||||||
|
return dot(col, vec3(0.2126, 0.7152, 0.0722));
|
||||||
|
}
|
||||||
|
|
||||||
|
float character(float n, vec2 p)
|
||||||
|
{
|
||||||
|
p = floor(p * vec2(4.0, -4.0) + 2.5);
|
||||||
|
|
||||||
|
// Check if the coordinate is inside the 5x5 grid (0 to 4).
|
||||||
|
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y) {
|
||||||
|
|
||||||
|
if (int(mod(n / exp2(p.x + 5.0 * p.y), 2.0)) == 1) {
|
||||||
|
return 1.0; // The bit is on, so draw this part of the character.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0; // The bit is off, or we are outside the grid.
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Main shader logic
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 charPixelSize = vec2(fontSize, fontSize * 1.8);
|
||||||
|
vec2 uvCellSize = charPixelSize / resolution;
|
||||||
|
|
||||||
|
vec2 cellUV = floor(fragTexCoord / uvCellSize) * uvCellSize;
|
||||||
|
|
||||||
|
vec3 cellColor = texture2D(texture0, cellUV).rgb;
|
||||||
|
float gray = greyScale(cellColor);
|
||||||
|
|
||||||
|
float n = 4096;
|
||||||
|
|
||||||
|
// limited character set
|
||||||
|
if (gray > 0.2) n = 65600.0; // :
|
||||||
|
if (gray > 0.3) n = 163153.0; // *
|
||||||
|
if (gray > 0.4) n = 15255086.0; // o
|
||||||
|
if (gray > 0.5) n = 13121101.0; // &
|
||||||
|
if (gray > 0.6) n = 15252014.0; // 8
|
||||||
|
if (gray > 0.7) n = 13195790.0; // @
|
||||||
|
if (gray > 0.8) n = 11512810.0; // #
|
||||||
|
|
||||||
|
vec2 localUV = (fragTexCoord - cellUV) / uvCellSize; // Range [0.0, 1.0]
|
||||||
|
|
||||||
|
vec2 p = localUV * 2.0 - 1.0;
|
||||||
|
|
||||||
|
float charShape = character(n, p);
|
||||||
|
|
||||||
|
vec3 final_col = cellColor * charShape;
|
||||||
|
|
||||||
|
gl_FragColor = vec4(final_col, 1.0);
|
||||||
|
}
|
||||||
65
examples/shaders/resources/shaders/glsl120/ascii.fs
Normal file
65
examples/shaders/resources/shaders/glsl120/ascii.fs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input from the vertex shader
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
|
// Output color for the screen
|
||||||
|
varying vec4 finalColor;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform float fontSize;
|
||||||
|
|
||||||
|
float greyScale(in vec3 col) {
|
||||||
|
return dot(col, vec3(0.2126, 0.7152, 0.0722));
|
||||||
|
}
|
||||||
|
|
||||||
|
float character(float n, vec2 p)
|
||||||
|
{
|
||||||
|
p = floor(p * vec2(4.0, -4.0) + 2.5);
|
||||||
|
|
||||||
|
// Check if the coordinate is inside the 5x5 grid (0 to 4).
|
||||||
|
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y) {
|
||||||
|
|
||||||
|
if (int(mod(n / exp2(p.x + 5.0 * p.y), 2.0)) == 1) {
|
||||||
|
return 1.0; // The bit is on, so draw this part of the character.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0; // The bit is off, or we are outside the grid.
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Main shader logic
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 charPixelSize = vec2(fontSize, fontSize * 1.8);
|
||||||
|
vec2 uvCellSize = charPixelSize / resolution;
|
||||||
|
|
||||||
|
vec2 cellUV = floor(fragTexCoord / uvCellSize) * uvCellSize;
|
||||||
|
|
||||||
|
vec3 cellColor = texture2D(texture0, cellUV).rgb;
|
||||||
|
float gray = greyScale(cellColor);
|
||||||
|
|
||||||
|
float n = 4096;
|
||||||
|
|
||||||
|
// limited character set
|
||||||
|
if (gray > 0.2) n = 65600.0; // :
|
||||||
|
if (gray > 0.3) n = 163153.0; // *
|
||||||
|
if (gray > 0.4) n = 15255086.0; // o
|
||||||
|
if (gray > 0.5) n = 13121101.0; // &
|
||||||
|
if (gray > 0.6) n = 15252014.0; // 8
|
||||||
|
if (gray > 0.7) n = 13195790.0; // @
|
||||||
|
if (gray > 0.8) n = 11512810.0; // #
|
||||||
|
|
||||||
|
vec2 localUV = (fragTexCoord - cellUV) / uvCellSize; // Range [0.0, 1.0]
|
||||||
|
|
||||||
|
vec2 p = localUV * 2.0 - 1.0;
|
||||||
|
|
||||||
|
float charShape = character(n, p);
|
||||||
|
|
||||||
|
vec3 final_col = cellColor * charShape;
|
||||||
|
|
||||||
|
gl_FragColor = vec4(final_col, 1.0);
|
||||||
|
}
|
||||||
63
examples/shaders/resources/shaders/glsl330/ascii.fs
Normal file
63
examples/shaders/resources/shaders/glsl330/ascii.fs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input from the vertex shader
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
|
||||||
|
// Output color for the screen
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec2 resolution;
|
||||||
|
uniform float fontSize;
|
||||||
|
|
||||||
|
float GreyScale(in vec3 col)
|
||||||
|
{
|
||||||
|
return dot(col, vec3(0.2126, 0.7152, 0.0722));
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetCharacter(float n, vec2 p)
|
||||||
|
{
|
||||||
|
p = floor(p*vec2(4.0, -4.0) + 2.5);
|
||||||
|
|
||||||
|
// Check if the coordinate is inside the 5x5 grid (0 to 4)
|
||||||
|
if (clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y)
|
||||||
|
{
|
||||||
|
if (int(mod(n/exp2(p.x + 5.0 * p.y), 2.0)) == 1)
|
||||||
|
{
|
||||||
|
return 1.0; // The bit is on, so draw this part of the character
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0; // The bit is off, or we are outside the grid
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Main shader logic
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 charPixelSize = vec2(fontSize, fontSize*1.8);
|
||||||
|
vec2 uvCellSize = charPixelSize/resolution;
|
||||||
|
vec2 cellUV = floor(fragTexCoord/uvCellSize)*uvCellSize;
|
||||||
|
|
||||||
|
vec3 cellColor = texture(texture0, cellUV).rgb;
|
||||||
|
float gray = GreyScale(cellColor);
|
||||||
|
|
||||||
|
float n = 4096;
|
||||||
|
|
||||||
|
// Limited character set
|
||||||
|
if (gray > 0.2) n = 65600.0; // :
|
||||||
|
if (gray > 0.3) n = 163153.0; // *
|
||||||
|
if (gray > 0.4) n = 15255086.0; // o
|
||||||
|
if (gray > 0.5) n = 13121101.0; // &
|
||||||
|
if (gray > 0.6) n = 15252014.0; // 8
|
||||||
|
if (gray > 0.7) n = 13195790.0; // @
|
||||||
|
if (gray > 0.8) n = 11512810.0; // #
|
||||||
|
|
||||||
|
vec2 localUV = (fragTexCoord - cellUV)/uvCellSize; // Range [0.0, 1.0]
|
||||||
|
vec2 p = localUV*2.0 - 1.0;
|
||||||
|
|
||||||
|
float charShape = GetCharacter(n, p);
|
||||||
|
|
||||||
|
finalColor = vec4(cellColor*charShape, 1.0);
|
||||||
|
}
|
||||||
117
examples/shaders/shaders_ascii_rendering.c
Normal file
117
examples/shaders/shaders_ascii_rendering.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [shaders] example - ascii rendering
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.5, last time updated with raylib 5.6
|
||||||
|
*
|
||||||
|
* Example contributed by Maicon Santana (@maiconpintoabreu) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
* BSD-like license that allows static linking with closed source software
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2025 Maicon Santana (@maiconpintoabreu)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#define GLSL_VERSION 330
|
||||||
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
|
#define GLSL_VERSION 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - ascii rendering");
|
||||||
|
|
||||||
|
// Texture to test static drawing
|
||||||
|
Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
|
||||||
|
// Texture to test moving drawing
|
||||||
|
Texture2D raysan = LoadTexture("resources/raysan.png");
|
||||||
|
|
||||||
|
// Load shader to be used on postprocessing
|
||||||
|
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/ascii.fs", GLSL_VERSION));
|
||||||
|
|
||||||
|
// These locations are used to send data to the GPU
|
||||||
|
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||||
|
int fontSizeLoc = GetShaderLocation(shader, "fontSize");
|
||||||
|
|
||||||
|
// Set the character size for the ASCII effect
|
||||||
|
float fontSize = 4.0f;
|
||||||
|
|
||||||
|
// Send the updated values to the shader
|
||||||
|
float resolution[2] = { (float)screenWidth, (float)screenHeight };
|
||||||
|
SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);
|
||||||
|
SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
Vector2 circlePos = (Vector2){40.0f, (float)screenHeight * 0.5f};
|
||||||
|
float circleSpeed = 1.0f;
|
||||||
|
|
||||||
|
// RenderTexture to apply the postprocessing later
|
||||||
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
circlePos.x += circleSpeed;
|
||||||
|
|
||||||
|
if ((circlePos.x > 200.0f) || (circlePos.x < 40.0f)) circleSpeed *= -1;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Draw our scene to a render texture first
|
||||||
|
BeginTextureMode(target);
|
||||||
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
|
DrawTexture(fudesumi, 500, -30, WHITE);
|
||||||
|
DrawTextureV(raysan, circlePos, WHITE);
|
||||||
|
|
||||||
|
EndTextureMode();
|
||||||
|
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginShaderMode(shader);
|
||||||
|
// Draw the render texture containing scene
|
||||||
|
// The shader will process every pixel on the screen
|
||||||
|
DrawTextureRec(target.texture,
|
||||||
|
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
|
||||||
|
(Vector2){ 0, 0 }, WHITE);
|
||||||
|
EndShaderMode();
|
||||||
|
|
||||||
|
DrawRectangle(0, 0, screenWidth, 40, BLACK);
|
||||||
|
DrawText("Ascii effect", 120, 10, 20, LIGHTGRAY);
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader); // Unload shader
|
||||||
|
UnloadTexture(fudesumi); // Unload texture
|
||||||
|
UnloadTexture(raysan); // Unload texture
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/shaders/shaders_ascii_rendering.png
Normal file
BIN
examples/shaders/shaders_ascii_rendering.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
6147
src/external/miniaudio.h
vendored
6147
src/external/miniaudio.h
vendored
File diff suppressed because it is too large
Load Diff
3512
src/external/rlsw.h
vendored
3512
src/external/rlsw.h
vendored
File diff suppressed because it is too large
Load Diff
@ -1233,7 +1233,7 @@ void SwapScreenBuffer(void)
|
|||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
// NOTE: We use a preprocessor condition here because `rlCopyFramebuffer` is only declared for software rendering
|
// NOTE: We use a preprocessor condition here because `rlCopyFramebuffer` is only declared for software rendering
|
||||||
SDL_Surface* surface = SDL_GetWindowSurface(platform.window);
|
SDL_Surface *surface = SDL_GetWindowSurface(platform.window);
|
||||||
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, surface->pixels);
|
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, surface->pixels);
|
||||||
SDL_UpdateWindowSurface(platform.window);
|
SDL_UpdateWindowSurface(platform.window);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -818,14 +818,14 @@ void SwapScreenBuffer(void)
|
|||||||
platform.prevBO = bo;
|
platform.prevBO = bo;
|
||||||
#else
|
#else
|
||||||
// Software rendering buffer swap
|
// Software rendering buffer swap
|
||||||
if ((-1 == platform.fd) || !platform.connector || (platform.modeIndex < 0))
|
if ((platform.fd == -1) || !platform.connector || (platform.modeIndex < 0))
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: DRM initialization failed to swap");
|
TRACELOG(LOG_ERROR, "DISPLAY: DRM initialization failed to swap");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the software rendered color buffer
|
// Get the software rendered color buffer
|
||||||
int bufferWidth, bufferHeight;
|
int bufferWidth = 0, bufferHeight = 0;
|
||||||
void *colorBuffer = swGetColorBuffer(&bufferWidth, &bufferHeight);
|
void *colorBuffer = swGetColorBuffer(&bufferWidth, &bufferHeight);
|
||||||
if (!colorBuffer)
|
if (!colorBuffer)
|
||||||
{
|
{
|
||||||
@ -849,7 +849,7 @@ void SwapScreenBuffer(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create a dumb buffer for software rendering
|
// Create a dumb buffer for software rendering
|
||||||
struct drm_mode_create_dumb creq = {0};
|
struct drm_mode_create_dumb creq = { 0 };
|
||||||
creq.width = width;
|
creq.width = width;
|
||||||
creq.height = height;
|
creq.height = height;
|
||||||
creq.bpp = bpp;
|
creq.bpp = bpp;
|
||||||
@ -863,28 +863,25 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Create framebuffer with the correct format
|
// Create framebuffer with the correct format
|
||||||
uint32_t fb = 0;
|
uint32_t fb = 0;
|
||||||
result = drmModeAddFB(platform.fd,
|
result = drmModeAddFB(platform.fd, width, height, depth, bpp, creq.pitch, creq.handle, &fb);
|
||||||
width, height,
|
|
||||||
depth, bpp, creq.pitch,
|
|
||||||
creq.handle, &fb);
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: drmModeAddFB() failed with result: %d (%s)", result, strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: drmModeAddFB() failed with result: %d (%s)", result, strerror(errno));
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the dumb buffer to copy our software rendered buffer
|
// Map the dumb buffer to copy our software rendered buffer
|
||||||
struct drm_mode_map_dumb mreq = {0};
|
struct drm_mode_map_dumb mreq = { 0 };
|
||||||
mreq.handle = creq.handle;
|
mreq.handle = creq.handle;
|
||||||
result = drmIoctl(platform.fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
|
result = drmIoctl(platform.fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: Failed to map dumb buffer: %s", strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: Failed to map dumb buffer: %s", strerror(errno));
|
||||||
drmModeRmFB(platform.fd, fb);
|
drmModeRmFB(platform.fd, fb);
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
@ -896,7 +893,7 @@ void SwapScreenBuffer(void)
|
|||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: Failed to mmap dumb buffer: %s", strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: Failed to mmap dumb buffer: %s", strerror(errno));
|
||||||
drmModeRmFB(platform.fd, fb);
|
drmModeRmFB(platform.fd, fb);
|
||||||
struct drm_mode_destroy_dumb dreq = {0};
|
struct drm_mode_destroy_dumb dreq = { 0 };
|
||||||
dreq.handle = creq.handle;
|
dreq.handle = creq.handle;
|
||||||
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
drmIoctl(platform.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||||
return;
|
return;
|
||||||
@ -919,10 +916,7 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Find a CRTC compatible with the connector
|
// Find a CRTC compatible with the connector
|
||||||
uint32_t crtcId = 0;
|
uint32_t crtcId = 0;
|
||||||
if (platform.crtc)
|
if (platform.crtc) crtcId = platform.crtc->crtc_id;
|
||||||
{
|
|
||||||
crtcId = platform.crtc->crtc_id;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Find a CRTC that's compatible with this connector
|
// Find a CRTC that's compatible with this connector
|
||||||
@ -939,10 +933,7 @@ void SwapScreenBuffer(void)
|
|||||||
|
|
||||||
// Check which CRTCs are compatible with this connector
|
// Check which CRTCs are compatible with this connector
|
||||||
drmModeEncoder *encoder = NULL;
|
drmModeEncoder *encoder = NULL;
|
||||||
if (platform.connector->encoder_id)
|
if (platform.connector->encoder_id) encoder = drmModeGetEncoder(platform.fd, platform.connector->encoder_id);
|
||||||
{
|
|
||||||
encoder = drmModeGetEncoder(platform.fd, platform.connector->encoder_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoder && encoder->crtc_id)
|
if (encoder && encoder->crtc_id)
|
||||||
{
|
{
|
||||||
@ -962,6 +953,7 @@ void SwapScreenBuffer(void)
|
|||||||
platform.crtc = crtc;
|
platform.crtc = crtc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crtc) drmModeFreeCrtc(crtc);
|
if (crtc) drmModeFreeCrtc(crtc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -981,9 +973,7 @@ void SwapScreenBuffer(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set CRTC with better error handling
|
// Set CRTC with better error handling
|
||||||
result = drmModeSetCrtc(platform.fd, crtcId, fb, 0, 0,
|
result = drmModeSetCrtc(platform.fd, crtcId, fb, 0, 0, &platform.connector->connector_id, 1, mode);
|
||||||
&platform.connector->connector_id, 1,
|
|
||||||
mode);
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_ERROR, "DISPLAY: drmModeSetCrtc() failed with result: %d (%s)", result, strerror(errno));
|
TRACELOG(LOG_ERROR, "DISPLAY: drmModeSetCrtc() failed with result: %d (%s)", result, strerror(errno));
|
||||||
@ -1001,10 +991,7 @@ void SwapScreenBuffer(void)
|
|||||||
if (platform.prevFB)
|
if (platform.prevFB)
|
||||||
{
|
{
|
||||||
result = drmModeRmFB(platform.fd, platform.prevFB);
|
result = drmModeRmFB(platform.fd, platform.prevFB);
|
||||||
if (result != 0)
|
if (result != 0) TRACELOG(LOG_WARNING, "DISPLAY: drmModeRmFB() failed with result: %d", result);
|
||||||
{
|
|
||||||
TRACELOG(LOG_WARNING, "DISPLAY: drmModeRmFB() failed with result: %d", result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.prevFB = fb;
|
platform.prevFB = fb;
|
||||||
@ -1249,7 +1236,7 @@ int InitPlatform(void)
|
|||||||
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected
|
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected
|
||||||
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output
|
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output
|
||||||
// WARNING: Accept CONNECTED, UNKNOWN and even those without encoder_id connectors for software mode
|
// WARNING: Accept CONNECTED, UNKNOWN and even those without encoder_id connectors for software mode
|
||||||
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->count_modes > 0)//(con->encoder_id))
|
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->count_modes > 0))
|
||||||
{
|
{
|
||||||
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
// For hardware rendering, we need an encoder_id
|
// For hardware rendering, we need an encoder_id
|
||||||
@ -1259,10 +1246,7 @@ int InitPlatform(void)
|
|||||||
platform.connector = con;
|
platform.connector = con;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i connected but no encoder", i);
|
||||||
{
|
|
||||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i connected but no encoder", i);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
// For software rendering, we can accept even without encoder_id
|
// For software rendering, we can accept even without encoder_id
|
||||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i suitable for software rendering", i);
|
TRACELOG(LOG_TRACE, "DISPLAY: DRM connector %i suitable for software rendering", i);
|
||||||
|
|||||||
24
src/rlgl.h
24
src/rlgl.h
@ -776,8 +776,8 @@ RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attac
|
|||||||
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
||||||
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
RLAPI void rlCopyFramebuffer(int x, int y, int w, int h, int format, void* pixels);
|
RLAPI void rlCopyFramebuffer(int x, int y, int width, int height, int format, void *pixels); // Copy framebuffer pixel data to internal buffer
|
||||||
RLAPI void rlResizeFramebuffer(int width, int height);
|
RLAPI void rlResizeFramebuffer(int width, int height); // Resize internal framebuffer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Shaders management
|
// Shaders management
|
||||||
@ -846,7 +846,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
#define RLSW_IMPL
|
#define RLSW_IMPLEMENTATION
|
||||||
#define SW_MALLOC(sz) RL_MALLOC(sz)
|
#define SW_MALLOC(sz) RL_MALLOC(sz)
|
||||||
#define SW_REALLOC(ptr, newSz) RL_REALLOC(ptr, newSz)
|
#define SW_REALLOC(ptr, newSz) RL_REALLOC(ptr, newSz)
|
||||||
#define SW_FREE(ptr) RL_FREE(ptr)
|
#define SW_FREE(ptr) RL_FREE(ptr)
|
||||||
@ -2357,9 +2357,10 @@ void rlglInit(int width, int height)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
if (!swInit(width, height))
|
int result = swInit(width, height); // Initialize software renderer backend
|
||||||
|
if (result == 0)
|
||||||
{
|
{
|
||||||
TRACELOG(RL_LOG_ERROR, "RLGL: Software renderer initialization failed!");
|
TRACELOG(RL_LOG_ERROR, "RLSW: Software renderer initialization failed!");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2385,14 +2386,14 @@ void rlglClose(void)
|
|||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
rlUnloadRenderBatch(RLGL.defaultBatch);
|
rlUnloadRenderBatch(RLGL.defaultBatch);
|
||||||
|
|
||||||
rlUnloadShaderDefault(); // Unload default shader
|
rlUnloadShaderDefault(); // Unload default shader
|
||||||
|
|
||||||
glDeleteTextures(1, &RLGL.State.defaultTextureId); // Unload default texture
|
glDeleteTextures(1, &RLGL.State.defaultTextureId); // Unload default texture
|
||||||
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture unloaded successfully", RLGL.State.defaultTextureId);
|
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture unloaded successfully", RLGL.State.defaultTextureId);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
swClose();
|
swClose(); // Unload sofware renderer resources
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2703,6 +2704,7 @@ void *rlGetProcAddress(const char *procName)
|
|||||||
int rlGetVersion(void)
|
int rlGetVersion(void)
|
||||||
{
|
{
|
||||||
int glVersion = 0;
|
int glVersion = 0;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
glVersion = RL_OPENGL_11_SOFTWARE;
|
glVersion = RL_OPENGL_11_SOFTWARE;
|
||||||
#elif defined(GRAPHICS_API_OPENGL_11)
|
#elif defined(GRAPHICS_API_OPENGL_11)
|
||||||
@ -3747,13 +3749,15 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
void rlCopyFramebuffer(int x, int y, int w, int h, int format, void* pixels)
|
// Copy framebuffer pixel data to internal buffer
|
||||||
|
void rlCopyFramebuffer(int x, int y, int width, int height, int format, void* pixels)
|
||||||
{
|
{
|
||||||
unsigned int glInternalFormat, glFormat, glType;
|
unsigned int glInternalFormat, glFormat, glType;
|
||||||
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType); // Get OpenGL texture format
|
||||||
swCopyFramebuffer(x, y, w, h, glFormat, glType, pixels);
|
swCopyFramebuffer(x, y, width, height, glFormat, glType, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resize internal framebuffer
|
||||||
void rlResizeFramebuffer(int width, int height)
|
void rlResizeFramebuffer(int width, int height)
|
||||||
{
|
{
|
||||||
swResizeFramebuffer(width, height);
|
swResizeFramebuffer(width, height);
|
||||||
|
|||||||
10
src/rtext.c
10
src/rtext.c
@ -1452,7 +1452,7 @@ Rectangle GetGlyphAtlasRec(Font font, int codepoint)
|
|||||||
char **LoadTextLines(const char *text, int *count)
|
char **LoadTextLines(const char *text, int *count)
|
||||||
{
|
{
|
||||||
int lineCount = 1;
|
int lineCount = 1;
|
||||||
int textSize = strlen(text);
|
int textSize = (int)strlen(text);
|
||||||
|
|
||||||
// Text pass to get required line count
|
// Text pass to get required line count
|
||||||
for (int i = 0; i < textSize; i++)
|
for (int i = 0; i < textSize; i++)
|
||||||
@ -1679,7 +1679,7 @@ char *GetTextBetween(const char *text, const char *begin, const char *end)
|
|||||||
|
|
||||||
if (beginIndex > -1)
|
if (beginIndex > -1)
|
||||||
{
|
{
|
||||||
int beginLen = strlen(begin);
|
int beginLen = (int)strlen(begin);
|
||||||
int endIndex = TextFindIndex(text + beginIndex + beginLen, end);
|
int endIndex = TextFindIndex(text + beginIndex + beginLen, end);
|
||||||
|
|
||||||
if (endIndex > -1)
|
if (endIndex > -1)
|
||||||
@ -1758,15 +1758,15 @@ char *TextReplaceBetween(const char *text, const char *begin, const char *end, c
|
|||||||
|
|
||||||
if (beginIndex > -1)
|
if (beginIndex > -1)
|
||||||
{
|
{
|
||||||
int beginLen = strlen(begin);
|
int beginLen = (int)strlen(begin);
|
||||||
int endIndex = TextFindIndex(text + beginIndex + beginLen, end);
|
int endIndex = TextFindIndex(text + beginIndex + beginLen, end);
|
||||||
|
|
||||||
if (endIndex > -1)
|
if (endIndex > -1)
|
||||||
{
|
{
|
||||||
endIndex += (beginIndex + beginLen);
|
endIndex += (beginIndex + beginLen);
|
||||||
|
|
||||||
int textLen = strlen(text);
|
int textLen = (int)strlen(text);
|
||||||
int replaceLen = (replacement == NULL)? 0 : strlen(replacement);
|
int replaceLen = (replacement == NULL)? 0 : (int)strlen(replacement);
|
||||||
int toreplaceLen = endIndex - beginIndex - beginLen;
|
int toreplaceLen = endIndex - beginIndex - beginLen;
|
||||||
result = (char *)RL_CALLOC(textLen + replaceLen - toreplaceLen + 1, sizeof(char));
|
result = (char *)RL_CALLOC(textLen + replaceLen - toreplaceLen + 1, sizeof(char));
|
||||||
|
|
||||||
|
|||||||
@ -811,8 +811,8 @@ Image GenImageColor(int width, int height, Color color)
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -863,8 +863,8 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start,
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -900,8 +900,8 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner,
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -949,8 +949,8 @@ Image GenImageGradientSquare(int width, int height, float density, Color inner,
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -974,8 +974,8 @@ Image GenImageChecked(int width, int height, int checksX, int checksY, Color col
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -997,8 +997,8 @@ Image GenImageWhiteNoise(int width, int height, float factor)
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -1048,8 +1048,8 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
@ -1113,8 +1113,8 @@ Image GenImageCellular(int width, int height, int tileSize)
|
|||||||
.data = pixels,
|
.data = pixels,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
|
.mipmaps = 1,
|
||||||
.mipmaps = 1
|
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
|||||||
Reference in New Issue
Block a user