lovr.graphics.getDimensions and friends;

This commit is contained in:
bjorn 2016-09-28 22:10:03 -07:00
parent 44b19b4e37
commit 4679696288
4 changed files with 33 additions and 0 deletions

View File

@ -223,6 +223,10 @@ void lovrGraphicsScale(float x, float y, float z) {
mat4_scale(vec_last(&state.transforms), x, y, z);
}
void lovrGraphicsGetDimensions(int* width, int* height) {
glfwGetFramebufferSize(window, width, height);
}
Buffer* lovrGraphicsNewBuffer(int size, BufferDrawMode drawMode, BufferUsage usage) {
Buffer* buffer = malloc(sizeof(Buffer));

View File

@ -60,6 +60,7 @@ void lovrGraphicsOrigin();
void lovrGraphicsTranslate(float x, float y, float z);
void lovrGraphicsRotate(float w, float x, float y, float z);
void lovrGraphicsScale(float x, float y, float z);
void lovrGraphicsGetDimensions(int* width, int* height);
Buffer* lovrGraphicsNewBuffer(int size, BufferDrawMode drawMode, BufferUsage usage);
Model* lovrGraphicsNewModel(const char* path);
Shader* lovrGraphicsNewShader(const char* vertexSource, const char* fragmentSource);

View File

@ -25,6 +25,9 @@ const luaL_Reg lovrGraphics[] = {
{ "translate", l_lovrGraphicsTranslate },
{ "rotate", l_lovrGraphicsRotate },
{ "scale", l_lovrGraphicsScale },
{ "getWidth", l_lovrGraphicsGetWidth },
{ "getHeight", l_lovrGraphicsGetHeight },
{ "getDimensions", l_lovrGraphicsGetDimensions },
{ "newModel", l_lovrGraphicsNewModel },
{ "newBuffer", l_lovrGraphicsNewBuffer },
{ "newShader", l_lovrGraphicsNewShader },
@ -235,6 +238,28 @@ int l_lovrGraphicsScale(lua_State* L) {
return 0;
}
int l_lovrGraphicsGetWidth(lua_State* L) {
int width;
lovrGraphicsGetDimensions(&width, NULL);
lua_pushnumber(L, width);
return 1;
}
int l_lovrGraphicsGetHeight(lua_State* L) {
int height;
lovrGraphicsGetDimensions(NULL, &height);
lua_pushnumber(L, height);
return 1;
}
int l_lovrGraphicsGetDimensions(lua_State* L) {
int width, height;
lovrGraphicsGetDimensions(&width, &height);
lua_pushnumber(L, width);
lua_pushnumber(L, height);
return 2;
}
int l_lovrGraphicsNewBuffer(lua_State* L) {
const char* userDrawMode = luaL_optstring(L, 2, "fan");
BufferDrawMode* drawMode = (BufferDrawMode*) map_get(&BufferDrawModes, userDrawMode);

View File

@ -28,6 +28,9 @@ int l_lovrGraphicsOrigin(lua_State* L);
int l_lovrGraphicsTranslate(lua_State* L);
int l_lovrGraphicsRotate(lua_State* L);
int l_lovrGraphicsScale(lua_State* L);
int l_lovrGraphicsGetWidth(lua_State* L);
int l_lovrGraphicsGetHeight(lua_State* L);
int l_lovrGraphicsGetDimensions(lua_State* L);
int l_lovrGraphicsNewBuffer(lua_State* L);
int l_lovrGraphicsNewModel(lua_State* L);
int l_lovrGraphicsNewShader(lua_State* L);