dbg = -g
opt = -O0
-inc = -Isrc -Iexternal/gmath/src -I/usr/include -Iexternal/libimago/src
+inc = -Isrc -Iexternal/gmath/src -I/usr/include -Iexternal/libimago/src -I/usr/local/include
libs = -lGL -lGLEW -lglfw -lvulkan -lassimp -lgmath -limago
CXX = g++
--- /dev/null
+#version 450
+
+uniform samplerCube stex;
+
+in vec3 normal;
+out vec4 color;
+
+void main()
+{
+ vec4 texel = textureCube(stex, normalize(normal));
+
+ color.rgb = texel.rgb;
+ color.a = 1.0;
+}
\ No newline at end of file
--- /dev/null
+#version 450
+
+uniform mat4 mviewproj;
+
+layout(location = 1) in vec3 attr_pos;
+layout(location = 2) in vec3 attr_normal;
+
+out vec3 normal;
+
+void main()
+{
+ gl_Position = mviewproj * vec4(attr_pos, 1.0);
+ normal = attr_normal;
+}
\ No newline at end of file
void (*gfx_clear)(float r, float g, float b);
void (*gfx_viewport)(int x, int y, int width, int height);
+void (*gfx_zbuffer)(bool enable);
+void (*gfx_cull_face)(Gfx_cull_face cf);
bool gfx_init(Gfx_API api)
GFX_VK
};
+enum Gfx_cull_face {
+ GFX_CULL_NONE,
+ GFX_CULL_FRONT,
+ GFX_CULL_BACK
+};
+
extern void (*gfx_clear)(float r, float g, float b);
extern void (*gfx_viewport)(int x, int y, int width, int height);
+extern void (*gfx_zbuffer)(bool enable);
+extern void (*gfx_cull_face)(Gfx_cull_face cf);
bool gfx_init(Gfx_API api);
void gfx_cleanup();
#include "object.h"
#include "renderer.h"
#include "scene.h"
+#include "texture.h"
#include "opengl/opengl.h"
#include "vulkan/vk.h"
static Scene *scene_ground;
static Renderer *rground; // default renderer
+static Texture *gskybox;
/* *** */
return false;
}
+ gskybox = gfx_create_texture();
+ gskybox->load("data/cubemap/cubemap.jpg");
+ rground->set_sky_tex(gskybox);
+
rcow = new Renderer;
rcow->camera = camera;
rcow->scene = scene_cow;
#include <GL/glew.h>
+#include <GL/gl.h>
#include <gmath/gmath.h>
#include "mesh-gl.h"
static void clear(float r, float g, float b);
static void viewport(int x, int y, int width, int height);
+static void zbuffer(bool enable);
+static void cull_face(Gfx_cull_face cf);
bool init_opengl()
{
gfx_clear = clear;
gfx_viewport = viewport;
+ gfx_zbuffer = zbuffer;
+ gfx_cull_face = cull_face;
return true;
}
static void viewport(int x, int y, int width, int height)
{
glViewport(x, y, width, height);
+}
+
+static void zbuffer(bool enable)
+{
+ if(enable)
+ glEnable(GL_DEPTH_TEST);
+ else
+ glDisable(GL_DEPTH_TEST);
+}
+
+static void cull_face(Gfx_cull_face cf)
+{
+ switch(cf) {
+ case GFX_CULL_NONE:
+ glDisable(GL_CULL_FACE);
+ break;
+ case GFX_CULL_FRONT:
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_FRONT);
+ break;
+ case GFX_CULL_BACK:
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ break;
+ }
}
\ No newline at end of file
if(!camera || !scene)
return;
+ if(skytex) {
+ draw_skybox();
+ }
+
if(!sprog->link())
return;
if(!skyprog) {
if(!(skyprog = sdr_man->create_shader_program("sky.v.glsl", "sky.f.glsl")))
return;
- if((viewproj_loc = skyprog->get_uniform_location("viewproj") == -1))
+ if((viewproj_loc = skyprog->get_uniform_location("mviewproj") == -1))
return;
}
skytex = stex;
dskytex = dstex;
}
-void Renderer::draw_skybox()
+void Renderer::draw_skybox() const
{
if(!skymesh || !skytex)
return;
+ gfx_zbuffer(false);
+ gfx_cull_face(GFX_CULL_NONE);
+
skytex->bind();
skyprog->use();
skyprog->set_uniform_matrix(viewproj_loc, mviewproj);
skymesh->draw();
+
+ gfx_cull_face(GFX_CULL_BACK);
+ gfx_zbuffer(true);
}
\ No newline at end of file
Texture *skytex, *dskytex;
virtual void draw_object(Object *object) const;
- virtual void draw_skybox();
+ virtual void draw_skybox() const;
public:
Scene *scene;