mirror of https://github.com/bjornbytes/lovr.git
Start Skybox;
This commit is contained in:
parent
9f9b2ef7e2
commit
15f69d1d8a
|
@ -0,0 +1,26 @@
|
|||
#include "skybox.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
Skybox* lovrSkyboxCreate(char** filenames) {
|
||||
Skybox* skybox = malloc(sizeof(Skybox));
|
||||
|
||||
glGenTextures(1, &skybox->texture);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->texture);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int width, height, channels;
|
||||
unsigned char* data = stbi_load(filenames[i], &width, &height, &channels, 3);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
return skybox;
|
||||
}
|
||||
|
||||
void lovrSkyboxDestroy(Skybox* skybox) {
|
||||
glDeleteTextures(1, skybox->texture);
|
||||
free(skybox);
|
||||
}
|
||||
|
||||
void lovrSkyboxDraw(Skybox* skybox) {
|
||||
//
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include "../glfw.h"
|
||||
|
||||
#ifndef LOVR_SKYBOX_TYPES
|
||||
#define LOVR_SKYBOX_TYPES
|
||||
typedef struct {
|
||||
GLuint texture;
|
||||
} Skybox;
|
||||
#endif
|
||||
|
||||
Skybox* lovrSkyboxCreate();
|
||||
void lovrSkyboxDestroy(Skybox* skybox);
|
||||
void lovrSkyboxDraw(Skybox* skybox);
|
|
@ -2,6 +2,7 @@
|
|||
#include "buffer.h"
|
||||
#include "model.h"
|
||||
#include "shader.h"
|
||||
#include "skybox.h"
|
||||
#include "../graphics/graphics.h"
|
||||
#include "../util.h"
|
||||
|
||||
|
@ -41,6 +42,7 @@ const luaL_Reg lovrGraphics[] = {
|
|||
{ "newModel", l_lovrGraphicsNewModel },
|
||||
{ "newBuffer", l_lovrGraphicsNewBuffer },
|
||||
{ "newShader", l_lovrGraphicsNewShader },
|
||||
{ "newSkybox", l_lovrGraphicsNewSkybox },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -50,6 +52,7 @@ int l_lovrGraphicsInit(lua_State* L) {
|
|||
luaRegisterType(L, "Buffer", lovrBuffer, luax_destroybuffer);
|
||||
luaRegisterType(L, "Model", lovrModel, luax_destroymodel);
|
||||
luaRegisterType(L, "Shader", lovrShader, luax_destroyshader);
|
||||
luaRegisterType(L, "Skybox", lovrSkybox, luax_destroyskybox);
|
||||
|
||||
map_init(&BufferAttributeTypes);
|
||||
map_set(&BufferAttributeTypes, "float", BUFFER_FLOAT);
|
||||
|
@ -512,3 +515,14 @@ int l_lovrGraphicsNewShader(lua_State* L) {
|
|||
luax_pushshader(L, lovrShaderCreate(vertexSource, fragmentSource));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsNewSkybox(lua_State* L) {
|
||||
const char* filenames[6];
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
filenames[i] = luaL_checkstring(L, i + 1);
|
||||
}
|
||||
|
||||
luax_pushskybox(L, lovrSkyboxCreate(filenames));
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -46,3 +46,4 @@ int l_lovrGraphicsGetDimensions(lua_State* L);
|
|||
int l_lovrGraphicsNewBuffer(lua_State* L);
|
||||
int l_lovrGraphicsNewModel(lua_State* L);
|
||||
int l_lovrGraphicsNewShader(lua_State* L);
|
||||
int l_lovrGraphicsNewSkybox(lua_State* L);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "skybox.h"
|
||||
|
||||
void luax_pushskybox(lua_State* L, Skybox* skybox) {
|
||||
if (skybox == NULL) {
|
||||
return lua_pushnil(L);
|
||||
}
|
||||
|
||||
Skybox** userdata = (Skybox**) lua_newuserdata(L, sizeof(Skybox*));
|
||||
luaL_getmetatable(L, "Skybox");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = skybox;
|
||||
}
|
||||
|
||||
Skybox* luax_checkskybox(lua_State* L, int index) {
|
||||
return *(Skybox**) luaL_checkudata(L, index, "Skybox");
|
||||
}
|
||||
|
||||
int luax_destroyskybox(lua_State* L) {
|
||||
Skybox* skybox = luax_checkskybox(L, 1);
|
||||
lovrSkyboxDestroy(skybox);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrSkybox[] = {
|
||||
{ "draw", l_lovrSkyboxDraw },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int l_lovrSkyboxDraw(lua_State* L) {
|
||||
Skybox* skybox = luax_checkskybox(L, 1);
|
||||
lovrSkyboxDraw(skybox);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "../graphics/skybox.h"
|
||||
|
||||
void luax_pushskybox(lua_State* L, Skybox* skybox);
|
||||
Skybox* luax_checkskybox(lua_State* L, int index);
|
||||
int luax_destroyskybox(lua_State* L);
|
||||
extern const luaL_Reg lovrSkybox[];
|
||||
|
||||
int l_lovrSkyboxDraw(lua_State* L);
|
Loading…
Reference in New Issue