- [FIX] Ja se pot amagar i mostrar el cursor.
- [FIX] Arreglat error al carregar arxius zero_terminated. - [ONGOING] Un poc de treball en shaders més avançats.
This commit is contained in:
141
data/crtpi.glsl
Normal file
141
data/crtpi.glsl
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
crt-pi - A Raspberry Pi friendly CRT shader.
|
||||||
|
|
||||||
|
Copyright (C) 2015-2016 davej
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the Free
|
||||||
|
Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
|
||||||
|
|
||||||
|
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
|
||||||
|
|
||||||
|
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
|
||||||
|
|
||||||
|
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
|
||||||
|
|
||||||
|
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
|
||||||
|
|
||||||
|
BLOOM_FACTOR controls the increase in width for bright scanlines.
|
||||||
|
|
||||||
|
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Haven't put these as parameters as it would slow the code down.
|
||||||
|
#define SCANLINES
|
||||||
|
#define MULTISAMPLE
|
||||||
|
#define GAMMA
|
||||||
|
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
|
||||||
|
#define MASK_TYPE 2
|
||||||
|
|
||||||
|
|
||||||
|
#define COMPAT_PRECISION
|
||||||
|
|
||||||
|
#define MASK_BRIGHTNESS 0.80
|
||||||
|
#define SCANLINE_WEIGHT 6.0
|
||||||
|
#define SCANLINE_GAP_BRIGHTNESS 0.12
|
||||||
|
#define BLOOM_FACTOR 3.5
|
||||||
|
#define INPUT_GAMMA 2.4
|
||||||
|
#define OUTPUT_GAMMA 2.2
|
||||||
|
|
||||||
|
/* COMPATIBILITY
|
||||||
|
- GLSL compilers
|
||||||
|
*/
|
||||||
|
|
||||||
|
uniform vec2 TextureSize;
|
||||||
|
varying vec2 TEX0;
|
||||||
|
varying float filterWidth;
|
||||||
|
|
||||||
|
#if defined(VERTEX)
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
filterWidth = (768.0 / TextureSize.x) / 3.0;
|
||||||
|
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(FRAGMENT)
|
||||||
|
|
||||||
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
float CalcScanLineWeight(float dist)
|
||||||
|
{
|
||||||
|
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcScanLine(float dy)
|
||||||
|
{
|
||||||
|
float scanLineWeight = CalcScanLineWeight(dy);
|
||||||
|
#if defined(MULTISAMPLE)
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
|
||||||
|
scanLineWeight *= 0.3333333;
|
||||||
|
#endif
|
||||||
|
return scanLineWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
//vec2 TextureSize = vec2(320.0, 256.0);
|
||||||
|
vec2 texcoord = TEX0;
|
||||||
|
{
|
||||||
|
vec2 texcoordInPixels = texcoord * TextureSize;
|
||||||
|
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||||
|
float yCoord = tempY / TextureSize.y;
|
||||||
|
float dy = texcoordInPixels.y - tempY;
|
||||||
|
float scanLineWeight = CalcScanLine(dy);
|
||||||
|
float signY = sign(dy);
|
||||||
|
dy = dy * dy;
|
||||||
|
dy = dy * dy;
|
||||||
|
dy *= 8.0;
|
||||||
|
dy /= TextureSize.y;
|
||||||
|
dy *= signY;
|
||||||
|
vec2 tc = vec2(texcoord.x, yCoord + dy);
|
||||||
|
|
||||||
|
vec3 colour = texture2D(Texture, tc).rgb;
|
||||||
|
|
||||||
|
#if defined(SCANLINES)
|
||||||
|
#if defined(GAMMA)
|
||||||
|
colour = pow(colour, vec3(INPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
scanLineWeight *= BLOOM_FACTOR;
|
||||||
|
colour *= scanLineWeight;
|
||||||
|
|
||||||
|
#if defined(GAMMA)
|
||||||
|
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if MASK_TYPE == 0
|
||||||
|
gl_FragColor = vec4(colour, 1.0);
|
||||||
|
#else
|
||||||
|
#if MASK_TYPE == 1
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
|
||||||
|
vec3 mask;
|
||||||
|
if (whichMask < 0.5)
|
||||||
|
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
|
||||||
|
else
|
||||||
|
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
|
||||||
|
#elif MASK_TYPE == 2
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
|
||||||
|
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
|
||||||
|
if (whichMask < 0.3333333)
|
||||||
|
mask.x = 1.0;
|
||||||
|
else if (whichMask < 0.6666666)
|
||||||
|
mask.y = 1.0;
|
||||||
|
else
|
||||||
|
mask.z = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_FragColor = vec4(colour * mask, 1.0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -276,6 +276,18 @@ namespace draw
|
|||||||
shader_enabled ? disableShader() : enableShader();
|
shader_enabled ? disableShader() : enableShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hideCursor()
|
||||||
|
{
|
||||||
|
screen_cursor = false;
|
||||||
|
SDL_HideCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void showCursor()
|
||||||
|
{
|
||||||
|
screen_cursor = true;
|
||||||
|
SDL_ShowCursor();
|
||||||
|
}
|
||||||
|
|
||||||
// Crea una superficie i torna un punter a ella
|
// Crea una superficie i torna un punter a ella
|
||||||
surface *createSurface(const uint16_t w, const uint16_t h)
|
surface *createSurface(const uint16_t w, const uint16_t h)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ namespace draw
|
|||||||
void disableShader();
|
void disableShader();
|
||||||
void toggleShader();
|
void toggleShader();
|
||||||
|
|
||||||
|
void hideCursor();
|
||||||
|
void showCursor();
|
||||||
|
|
||||||
/// @brief Crea una superficie i torna un punter a ella
|
/// @brief Crea una superficie i torna un punter a ella
|
||||||
/// @param w ample de la superficie
|
/// @param w ample de la superficie
|
||||||
/// @param h alt de la superficie
|
/// @param h alt de la superficie
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ namespace file
|
|||||||
|
|
||||||
char *getFileBuffer(const char *resourcename, int& filesize, const bool zero_terminate) {
|
char *getFileBuffer(const char *resourcename, int& filesize, const bool zero_terminate) {
|
||||||
FILE *f = getFilePointer(resourcename, filesize, true);
|
FILE *f = getFilePointer(resourcename, filesize, true);
|
||||||
char* buffer = (char*)malloc(zero_terminate?filesize:filesize+1);
|
char* buffer = (char*)malloc(zero_terminate?filesize+1:filesize);
|
||||||
fread(buffer, filesize, 1, f);
|
fread(buffer, filesize, 1, f);
|
||||||
if (zero_terminate) buffer[filesize]=0;
|
if (zero_terminate) buffer[filesize]=0;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace shader
|
|||||||
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
||||||
PFNGLUSEPROGRAMPROC glUseProgram;
|
PFNGLUSEPROGRAMPROC glUseProgram;
|
||||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
||||||
|
PFNGLUNIFORM2FPROC glUniform2f;
|
||||||
|
|
||||||
bool initGLExtensions() {
|
bool initGLExtensions() {
|
||||||
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
|
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
|
||||||
@@ -66,11 +67,12 @@ namespace shader
|
|||||||
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||||
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
|
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
|
||||||
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation");
|
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)SDL_GL_GetProcAddress("glGetUniformLocation");
|
||||||
|
glUniform2f = (PFNGLUNIFORM2FPROC)SDL_GL_GetProcAddress("glUniform2f");
|
||||||
|
|
||||||
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
||||||
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
||||||
glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv &&
|
glDeleteProgram && glLinkProgram && glValidateProgram && glGetProgramiv &&
|
||||||
glGetProgramInfoLog && glUseProgram && glGetUniformLocation;
|
glGetProgramInfoLog && glUseProgram && glGetUniformLocation && glUniform2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -205,6 +207,7 @@ namespace shader
|
|||||||
can_use_opengl = false;
|
can_use_opengl = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
can_use_opengl = true;
|
can_use_opengl = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -236,6 +239,9 @@ namespace shader
|
|||||||
glUseProgram(programId);
|
glUseProgram(programId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GLint loc = glGetUniformLocation(programId, "TextureSize");
|
||||||
|
//glUniform2f(loc, 320, 256);
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 1);
|
glBindTexture(GL_TEXTURE_2D, 1);
|
||||||
@@ -265,6 +271,7 @@ namespace shader
|
|||||||
SDL_RenderTexture(renderer, backBuffer, NULL, &window);
|
SDL_RenderTexture(renderer, backBuffer, NULL, &window);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
if (glGetError()) { printf("GLERROR!\n"); exit(1); }
|
int glerror = glGetError();
|
||||||
|
if (glerror) { printf("GLERROR: %i\n", glerror); exit(1); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
void game::init()
|
void game::init()
|
||||||
{
|
{
|
||||||
draw::init("Arounders", 320, 200, 3, false, 3.0f/4.0f);
|
draw::init("Arounders", 320, 200, 3, false, 3.0f/4.0f);
|
||||||
draw::setShader("lynx.glsl");
|
draw::setShader("gbc.glsl");
|
||||||
draw::setTrans(0);
|
draw::setTrans(0);
|
||||||
audio::init(48000, SDL_AUDIO_S16, 2);
|
audio::init(48000, SDL_AUDIO_S16, 2);
|
||||||
|
draw::hideCursor();
|
||||||
|
|
||||||
file::setConfigFolder("arounders");
|
file::setConfigFolder("arounders");
|
||||||
font::init();
|
font::init();
|
||||||
|
|||||||
Reference in New Issue
Block a user