lovr.graphics.isGammaCorrect; conf.lua t.gammacorrect;

This commit is contained in:
bjorn 2017-11-22 20:26:01 -08:00
parent 8bda7a9ed8
commit 3c6437fb20
4 changed files with 32 additions and 2 deletions

View File

@ -172,10 +172,16 @@ int l_lovrGraphicsInit(lua_State* L) {
lovrGraphicsInit();
// Create window
luax_pushconf(L);
lua_getfield(L, -1, "window");
// Set gamma correct
lua_getfield(L, -1, "gammacorrect");
bool gammaCorrect = lua_toboolean(L, -1);
lovrGraphicsSetGammaCorrect(gammaCorrect);
lua_pop(L, 1);
// Create window if needed
lua_getfield(L, -1, "window");
if (!lua_isnil(L, -1)) {
lua_getfield(L, -1, "width");
int width = luaL_checkinteger(L, -1);
@ -360,6 +366,12 @@ int l_lovrGraphicsSetFont(lua_State* L) {
return 0;
}
int l_lovrGraphicsIsGammaCorrect(lua_State* L) {
bool gammaCorrect = lovrGraphicsIsGammaCorrect();
lua_pushboolean(L, gammaCorrect);
return 1;
}
int l_lovrGraphicsGetSystemLimits(lua_State* L) {
GraphicsLimits limits = lovrGraphicsGetLimits();
lua_newtable(L);
@ -855,6 +867,7 @@ const luaL_Reg lovrGraphics[] = {
{ "setDepthTest", l_lovrGraphicsSetDepthTest },
{ "getFont", l_lovrGraphicsGetFont },
{ "setFont", l_lovrGraphicsSetFont },
{ "isGammaCorrect", l_lovrGraphicsIsGammaCorrect },
{ "getSystemLimits", l_lovrGraphicsGetSystemLimits },
{ "getLineWidth", l_lovrGraphicsGetLineWidth },
{ "setLineWidth", l_lovrGraphicsSetLineWidth },

View File

@ -8,6 +8,7 @@ local conf = {
physics = true,
timer = true
},
gammacorrect = false,
headset = {
mirror = true,
offset = 1.7

View File

@ -196,6 +196,11 @@ void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const cha
glEnable(GL_LINE_SMOOTH);
glEnable(GL_PROGRAM_POINT_SIZE);
#endif
if (state.gammaCorrect) {
glEnable(GL_FRAMEBUFFER_SRGB);
} else {
glDisable(GL_FRAMEBUFFER_SRGB);
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -358,6 +363,14 @@ void lovrGraphicsSetFont(Font* font) {
}
}
bool lovrGraphicsIsGammaCorrect() {
return state.gammaCorrect;
}
void lovrGraphicsSetGammaCorrect(bool gammaCorrect) {
state.gammaCorrect = gammaCorrect;
}
GraphicsLimits lovrGraphicsGetLimits() {
if (!state.limits.initialized) {
#ifdef EMSCRIPTEN

View File

@ -92,6 +92,7 @@ typedef struct {
TextureFilter defaultFilter;
CompareMode depthTest;
Font* font;
bool gammaCorrect;
GraphicsLimits limits;
float lineWidth;
Material* material;
@ -139,6 +140,8 @@ CompareMode lovrGraphicsGetDepthTest();
void lovrGraphicsSetDepthTest(CompareMode depthTest);
Font* lovrGraphicsGetFont();
void lovrGraphicsSetFont(Font* font);
bool lovrGraphicsIsGammaCorrect();
void lovrGraphicsSetGammaCorrect(bool gammaCorrect);
GraphicsLimits lovrGraphicsGetLimits();
float lovrGraphicsGetLineWidth();
void lovrGraphicsSetLineWidth(float width);