Add mosaic pixel shader to engine. Release Build 7485.

pull/35/head
sigonasr2 11 months ago
parent ee215b132c
commit 0fc117235a
  1. 9
      Adventures in Lestoria/State_OverworldMap.cpp
  2. 1
      Adventures in Lestoria/State_OverworldMap.h
  3. 14
      Adventures in Lestoria/TODO.txt
  4. 2
      Adventures in Lestoria/Version.h
  5. 53
      Adventures in Lestoria/olcPixelGameEngine.h
  6. BIN
      x64/Release/Adventures in Lestoria.exe

@ -90,6 +90,15 @@ void State_OverworldMap::OnUserUpdate(AiL*game){
game->UpdateCamera(game->GetElapsedTime()); game->UpdateCamera(game->GetElapsedTime());
game->GetPlayer()->Update(game->GetElapsedTime()); game->GetPlayer()->Update(game->GetElapsedTime());
if(game->GetKey(PGUP).bHeld){
mosaicAmt+=game->GetElapsedTime()*10;
game->SetMosaicEffect(uint8_t(mosaicAmt));
}
if(game->GetKey(PGDN).bHeld){
mosaicAmt-=game->GetElapsedTime()*10;
game->SetMosaicEffect(uint8_t(mosaicAmt));
}
if(game->GetPlayer()->GetPos()!=playerTargetPos){ if(game->GetPlayer()->GetPos()!=playerTargetPos){
if(geom2d::line<float>(game->GetPlayer()->GetPos(),playerTargetPos).length()<2){ if(geom2d::line<float>(game->GetPlayer()->GetPos(),playerTargetPos).length()<2){
game->GetPlayer()->SetPos(playerTargetPos); game->GetPlayer()->SetPos(playerTargetPos);

@ -47,6 +47,7 @@ class State_OverworldMap:public GameState{
vf2d playerTargetPos; vf2d playerTargetPos;
const float playerMoveSpd=48.0; const float playerMoveSpd=48.0;
bool analogMove=false; bool analogMove=false;
float mosaicAmt=0.f;
public: public:
State_OverworldMap(); State_OverworldMap();
static std::vector<ConnectionPoint>connections; static std::vector<ConnectionPoint>connections;

@ -1,7 +1,14 @@
January 1st January 1st
=========== ===========
- Foreground tile depth correction for tiles w/hitboxes
- Add Death screen (Zoom in on fatal blow, slow time down... Display some game over text... Allow retry or return to world map.)
- Track items used during a stage, on death, restore the loadout item quantities used. - Track items used during a stage, on death, restore the loadout item quantities used.
- Icon displays / Proper key displays above skill keys
Add Bonus XP when completing a stage Add Bonus XP when completing a stage
January 31st January 31st
@ -10,17 +17,14 @@ January 31st
- Loading Screen - Loading Screen
- Title Screen setpieces - Title Screen setpieces
- Add Death screen (Zoom in on fatal blow, slow time down... Display some game over text... Allow retry or return to world map.)
- Hide mouse cursor during controller play. Reveal it again during mouse play. - Hide mouse cursor during controller play. Reveal it again during mouse play.
- Resource Packs - Resource Packs
- Hold mouse down to increase quantity
- Icon displays / Proper key displays above skill keys
- Auto aim causes retreat-type moves to aim away from the auto target, and prefer the direction the player's moving in. - Auto aim causes retreat-type moves to aim away from the auto target, and prefer the direction the player's moving in.
- Condense stage track (loading times) - Condense stage track (loading times)
- SNES mosaic effect on stage select/stage transition.
- Credits/Licensing - Credits/Licensing

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 7474 #define VERSION_BUILD 7485
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -376,6 +376,8 @@ return 0;
*/ */
#pragma endregion #pragma endregion
#define OLC_GFX_OPENGL33
#ifndef OLC_PGE_DEF #ifndef OLC_PGE_DEF
#define OLC_PGE_DEF #define OLC_PGE_DEF
@ -1230,6 +1232,8 @@ namespace olc
int32_t TextEntryGetCursor() const; int32_t TextEntryGetCursor() const;
bool IsTextEntryEnabled() const; bool IsTextEntryEnabled() const;
void TextEntrySetCharLimit(const uint8_t charLimit); void TextEntrySetCharLimit(const uint8_t charLimit);
const uint8_t GetMosaicEffect()const;
void SetMosaicEffect(uint8_t effectLevel);
public: public:
static std::map<char,Pixel> charToColor; static std::map<char,Pixel> charToColor;
@ -1340,6 +1344,7 @@ namespace olc
std::vector<std::string> vDroppedFilesCache; std::vector<std::string> vDroppedFilesCache;
olc::vi2d vDroppedFilesPoint; olc::vi2d vDroppedFilesPoint;
olc::vi2d vDroppedFilesPointCache; olc::vi2d vDroppedFilesPointCache;
uint8_t mosaic=1;
uint8_t nTextEntryCharLimit=std::numeric_limits<uint8_t>::max(); uint8_t nTextEntryCharLimit=std::numeric_limits<uint8_t>::max();
// Command Console Specific // Command Console Specific
@ -1505,6 +1510,7 @@ namespace olc
typedef GLint CALLSTYLE locGetUniformLocation_t(GLuint program, const GLchar* name); typedef GLint CALLSTYLE locGetUniformLocation_t(GLuint program, const GLchar* name);
typedef void CALLSTYLE locUniform1f_t(GLint location, GLfloat v0); typedef void CALLSTYLE locUniform1f_t(GLint location, GLfloat v0);
typedef void CALLSTYLE locUniform1i_t(GLint location, GLint v0); typedef void CALLSTYLE locUniform1i_t(GLint location, GLint v0);
typedef void CALLSTYLE locUniform2f_t(GLint location, GLfloat v0, GLfloat v1);
typedef void CALLSTYLE locUniform2fv_t(GLint location, GLsizei count, const GLfloat* value); typedef void CALLSTYLE locUniform2fv_t(GLint location, GLsizei count, const GLfloat* value);
typedef void CALLSTYLE locActiveTexture_t(GLenum texture); typedef void CALLSTYLE locActiveTexture_t(GLenum texture);
typedef void CALLSTYLE locGenFrameBuffers_t(GLsizei n, GLuint* ids); typedef void CALLSTYLE locGenFrameBuffers_t(GLsizei n, GLuint* ids);
@ -4383,6 +4389,12 @@ namespace olc
void PixelGameEngine::TextEntrySetCharLimit(const uint8_t charLimit){ void PixelGameEngine::TextEntrySetCharLimit(const uint8_t charLimit){
nTextEntryCharLimit=charLimit; nTextEntryCharLimit=charLimit;
} }
const uint8_t PixelGameEngine::GetMosaicEffect()const{
return mosaic;
}
void PixelGameEngine::SetMosaicEffect(uint8_t effectLevel){
mosaic=std::max(uint8_t(1),effectLevel);
}
void PixelGameEngine::UpdateTextEntry() void PixelGameEngine::UpdateTextEntry()
{ {
@ -5570,6 +5582,9 @@ namespace olc
locGenVertexArrays_t* locGenVertexArrays = nullptr; locGenVertexArrays_t* locGenVertexArrays = nullptr;
locSwapInterval_t* locSwapInterval = nullptr; locSwapInterval_t* locSwapInterval = nullptr;
locGetShaderInfoLog_t* locGetShaderInfoLog = nullptr; locGetShaderInfoLog_t* locGetShaderInfoLog = nullptr;
locGetUniformLocation_t* locGetUniformLocation = nullptr;
locUniform1i_t* locUniform1i = nullptr;
locUniform2f_t* locUniform2f = nullptr;
uint32_t m_nFS = 0; uint32_t m_nFS = 0;
uint32_t m_nVS = 0; uint32_t m_nVS = 0;
@ -5711,6 +5726,9 @@ namespace olc
locEnableVertexAttribArray = OGL_LOAD(locEnableVertexAttribArray_t, glEnableVertexAttribArray); locEnableVertexAttribArray = OGL_LOAD(locEnableVertexAttribArray_t, glEnableVertexAttribArray);
locUseProgram = OGL_LOAD(locUseProgram_t, glUseProgram); locUseProgram = OGL_LOAD(locUseProgram_t, glUseProgram);
locGetShaderInfoLog = OGL_LOAD(locGetShaderInfoLog_t, glGetShaderInfoLog); locGetShaderInfoLog = OGL_LOAD(locGetShaderInfoLog_t, glGetShaderInfoLog);
locGetUniformLocation = OGL_LOAD(locGetUniformLocation_t, glGetUniformLocation);
locUniform1i = OGL_LOAD(locUniform1i_t, glUniform1i);
locUniform2f = OGL_LOAD(locUniform2f_t, glUniform2f);
#if !defined(OLC_PLATFORM_EMSCRIPTEN) #if !defined(OLC_PLATFORM_EMSCRIPTEN)
locBindVertexArray = OGL_LOAD(locBindVertexArray_t, glBindVertexArray); locBindVertexArray = OGL_LOAD(locBindVertexArray_t, glBindVertexArray);
locGenVertexArrays = OGL_LOAD(locGenVertexArrays_t, glGenVertexArrays); locGenVertexArrays = OGL_LOAD(locGenVertexArrays_t, glGenVertexArrays);
@ -5724,12 +5742,22 @@ namespace olc
const GLchar* strFS = const GLchar* strFS =
#if defined(__arm__) || defined(OLC_PLATFORM_EMSCRIPTEN) #if defined(__arm__) || defined(OLC_PLATFORM_EMSCRIPTEN)
"#version 300 es\n" "#version 300 es\n"
"precision mediump float;" "precision highp float;"
#else #else
"#version 330 core\n" "#version 330 core\n"
#endif #endif
"out vec4 pixel;\n""in vec2 oTex;\n" "out vec4 pixel;\n"
"in vec4 oCol;\n""uniform sampler2D sprTex;\n""void main(){pixel = texture(sprTex, oTex) * oCol;}"; "in vec2 oTex;\n"
"in vec4 oCol;\n"
"uniform int mosaic;\n"
"uniform vec2 size;\n"
"uniform sampler2D sprTex;\n"
"void main(){\n"
"if(mosaic<=1){pixel = texture(sprTex,oTex) * oCol;return;}\n"
"vec2 texelSize = 1.0 / textureSize(sprTex,0); \n"
"vec2 pos = oTex / texelSize; \n""vec2 outputPos = vec2(floor(pos.x/float(mosaic))*float(mosaic),floor(pos.y/float(mosaic))*float(mosaic));\n"
"pixel = texture(sprTex, outputPos*texelSize) * oCol;\n"
"}";
locShaderSource(m_nFS, 1, &strFS, NULL); locShaderSource(m_nFS, 1, &strFS, NULL);
locCompileShader(m_nFS); locCompileShader(m_nFS);
@ -5741,9 +5769,18 @@ namespace olc
#else #else
"#version 330 core\n" "#version 330 core\n"
#endif #endif
"layout(location = 0) in vec3 aPos;\n""layout(location = 1) in vec2 aTex;\n" "layout(location = 0) in vec3 aPos;\n"
"layout(location = 2) in vec4 aCol;\n""out vec2 oTex;\n""out vec4 oCol;\n" "layout(location = 1) in vec2 aTex;\n"
"void main(){ float p = 1.0 / aPos.z; gl_Position = p * vec4(aPos.x, aPos.y, 0.0, 1.0); oTex = p * aTex; oCol = aCol;}"; "layout(location = 2) in vec4 aCol;\n"
"out vec2 oTex;\n"
"out vec4 oCol;\n"
"\n"
"void main(){\n"
"float p = 1.0 / aPos.z;\n"
"gl_Position = p * vec4(aPos.x, aPos.y, 0.0, 1.0);\n"
"oTex = p * aTex;\n"
"oCol = aCol;\n"
"}";
locShaderSource(m_nVS, 1, &strVS, NULL); locShaderSource(m_nVS, 1, &strVS, NULL);
locCompileShader(m_nVS); locCompileShader(m_nVS);
@ -5826,6 +5863,10 @@ namespace olc
nDecalMode = DecalMode::NORMAL; nDecalMode = DecalMode::NORMAL;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
locUseProgram(m_nQuadShader); locUseProgram(m_nQuadShader);
GLint mosaicUniformLoc = locGetUniformLocation(m_nQuadShader, "mosaic");
GLint sizeUniformLoc = locGetUniformLocation(m_nQuadShader, "size");
locUniform1i(mosaicUniformLoc,ptrPGE->GetMosaicEffect());
locUniform2f(sizeUniformLoc,ptrPGE->ScreenWidth(),ptrPGE->ScreenHeight());
locBindVertexArray(m_vaQuad); locBindVertexArray(m_vaQuad);
#if defined(OLC_PLATFORM_EMSCRIPTEN) #if defined(OLC_PLATFORM_EMSCRIPTEN)

Loading…
Cancel
Save