mirror of https://github.com/bjornbytes/lovr.git
Skybox rough draft;
This commit is contained in:
parent
406eab420c
commit
125e2d0e13
|
@ -1,7 +1,12 @@
|
|||
#include "skybox.h"
|
||||
#include "graphics.h"
|
||||
#include "../util.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// For now
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "../vendor/stb_image.h"
|
||||
|
||||
Skybox* lovrSkyboxCreate(char** filenames) {
|
||||
Skybox* skybox = malloc(sizeof(Skybox));
|
||||
|
||||
|
@ -17,6 +22,7 @@ Skybox* lovrSkyboxCreate(char** filenames) {
|
|||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
@ -29,10 +35,74 @@ Skybox* lovrSkyboxCreate(char** filenames) {
|
|||
}
|
||||
|
||||
void lovrSkyboxDestroy(Skybox* skybox) {
|
||||
glDeleteTextures(1, skybox->texture);
|
||||
glDeleteTextures(1, &skybox->texture);
|
||||
free(skybox);
|
||||
}
|
||||
|
||||
void lovrSkyboxDraw(Skybox* skybox) {
|
||||
//
|
||||
void lovrSkyboxDraw(Skybox* skybox, float angle, float ax, float ay, float az) {
|
||||
float cos2 = cos(angle / 2);
|
||||
float sin2 = sin(angle / 2);
|
||||
float rw = cos2;
|
||||
float rx = sin2 * ax;
|
||||
float ry = sin2 * ay;
|
||||
float rz = sin2 * az;
|
||||
|
||||
lovrGraphicsPrepare();
|
||||
lovrGraphicsPush();
|
||||
lovrGraphicsOrigin();
|
||||
lovrGraphicsRotate(rw, rx, ry, rz);
|
||||
|
||||
float cube[] = {
|
||||
// Front
|
||||
1.f, -1.f, -1.f, 0, 0, 0,
|
||||
1.f, 1.f, -1.f, 0, 0, 0,
|
||||
-1.f, -1.f, -1.f,0, 0, 0,
|
||||
-1.f, 1.f, -1.f, 0, 0, 0,
|
||||
|
||||
// Left
|
||||
-1.f, 1.f, -1.f, 0, 0, 0,
|
||||
-1.f, 1.f, 1.f, 0, 0, 0,
|
||||
-1.f, -1.f, -1.f,0, 0, 0,
|
||||
-1.f, -1.f, 1.f, 0, 0, 0,
|
||||
|
||||
// Back
|
||||
-1.f, -1.f, 1.f, 0, 0, 0,
|
||||
1.f, -1.f, 1.f, 0, 0, 0,
|
||||
-1.f, 1.f, 1.f, 0, 0, 0,
|
||||
1.f, 1.f, 1.f, 0, 0, 0,
|
||||
|
||||
// Right
|
||||
1.f, 1.f, 1.f, 0, 0, 0,
|
||||
1.f, -1.f, 1.f, 0, 0, 0,
|
||||
1.f, 1.f, -1.f, 0, 0, 0,
|
||||
1.f, -1.f, -1.f, 0, 0, 0,
|
||||
|
||||
// Bottom
|
||||
1.f, -1.f, -1.f, 0, 0, 0,
|
||||
1.f, -1.f, 1.f, 0, 0, 0,
|
||||
-1.f, -1.f, -1.f,0, 0, 0,
|
||||
-1.f, -1.f, 1.f, 0, 0, 0,
|
||||
|
||||
// Adjust
|
||||
-1.f, -1.f, 1.f, 0, 0, 0,
|
||||
-1.f, 1.f, -1.f, 0, 0, 0,
|
||||
|
||||
// Top
|
||||
-1.f, 1.f, -1.f, 0, 0, 0,
|
||||
-1.f, 1.f, 1.f, 0, 0, 0,
|
||||
1.f, 1.f, -1.f, 0, 0, 0,
|
||||
1.f, 1.f, 1.f, 0, 0, 0
|
||||
};
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox->texture);
|
||||
|
||||
lovrGraphicsSetShapeData(cube, 156, NULL, 0);
|
||||
lovrGraphicsDrawFilledShape();
|
||||
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
lovrGraphicsPop();
|
||||
}
|
||||
|
|
|
@ -9,4 +9,4 @@ typedef struct {
|
|||
|
||||
Skybox* lovrSkyboxCreate();
|
||||
void lovrSkyboxDestroy(Skybox* skybox);
|
||||
void lovrSkyboxDraw(Skybox* skybox);
|
||||
void lovrSkyboxDraw(Skybox* skybox, float angle, float ax, float ay, float az);
|
||||
|
|
|
@ -28,6 +28,10 @@ const luaL_Reg lovrSkybox[] = {
|
|||
|
||||
int l_lovrSkyboxDraw(lua_State* L) {
|
||||
Skybox* skybox = luax_checkskybox(L, 1);
|
||||
lovrSkyboxDraw(skybox);
|
||||
float angle = luaL_optnumber(L, 2, 0.f);
|
||||
float ax = luaL_optnumber(L, 3, 0.f);
|
||||
float ay = luaL_optnumber(L, 4, 0.f);
|
||||
float az = luaL_optnumber(L, 5, 0.f);
|
||||
lovrSkyboxDraw(skybox, angle, ax, ay, az);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "lovr.h"
|
||||
#include "glfw.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "vendor/stb_image.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
lua_State* L = luaL_newstate();
|
||||
|
|
Loading…
Reference in New Issue