Skip to content

Commit

Permalink
Merge pull request #31 from mortennobel/1.0.8
Browse files Browse the repository at this point in the history
1.0.8
  • Loading branch information
mortennobel authored Mar 29, 2018
2 parents 4e25760 + 7a96323 commit fac3ac7
Show file tree
Hide file tree
Showing 70 changed files with 13,062 additions and 229 deletions.
10 changes: 7 additions & 3 deletions em-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi

source ${EMSDK}/emsdk_env.sh

for FILENAME in benchmark64k-heavy matrix-uniforms custom-mesh-layout-ints multiple-materials multiple-lights imgui-color-test pbr-test custom-mesh-layout-default-values imgui_demo multi-cameras particle-sprite particle-test polygon-offset-example spinning-sphere-cubemap sprite-test static_vertex_attribute texture-test
for FILENAME in custom-mesh-layout-ints benchmark64k-heavy matrix-uniforms multiple-materials multiple-lights imgui-color-test pbr-test custom-mesh-layout-default-values imgui_demo multi-cameras particle-sprite particle-test polygon-offset-example spinning-sphere-cubemap sprite-test static_vertex_attribute texture-test
do
echo $FILENAME
emcc -Iinclude src/imgui/imgui.cpp \
Expand All @@ -33,12 +33,14 @@ emcc -Iinclude src/imgui/imgui.cpp \
src/sre/SpriteAtlas.cpp \
src/sre/Inspector.cpp \
src/sre/Log.cpp \
src/sre/Skybox.cpp \
src/sre/impl/UniformSet.cpp \
test/$FILENAME.cpp \
-O2 -std=c++14 -s USE_WEBGL2=1 -s FORCE_FILESYSTEM=1 -s TOTAL_MEMORY=67108864 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file test_data -s USE_SDL=2 -o html/$FILENAME.html
-O2 -s ASSERTIONS=1 -std=c++14 -s USE_WEBGL2=1 -s FORCE_FILESYSTEM=1 -s TOTAL_MEMORY=67108864 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file test_data -s USE_SDL=2 -o html/$FILENAME.html
#-O3 -g4 -s ASSERTIONS=1 -std=c++14 -s USE_WEBGL2=1 -s FORCE_FILESYSTEM=1 -s TOTAL_MEMORY=67108864 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file test_data -s USE_SDL=2 -o html/$FILENAME.html
done

for FILENAME in benchmark64k custom-mesh-layout gui hello-engine hello-engine-raw obj-viewer picking render-to-texture spheres spinning-cube spinning-primitives-tex sprite-example
for FILENAME in skybox-example render-to-texture matcap benchmark64k custom-mesh-layout gui hello-engine hello-engine-raw obj-viewer picking spheres spinning-cube spinning-primitives-tex sprite-example
do
echo $FILENAME
emcc -Iinclude src/imgui/imgui.cpp \
Expand All @@ -63,7 +65,9 @@ emcc -Iinclude src/imgui/imgui.cpp \
src/sre/SpriteAtlas.cpp \
src/sre/Inspector.cpp \
src/sre/Log.cpp \
src/sre/Skybox.cpp \
src/sre/impl/UniformSet.cpp \
examples/$FILENAME.cpp \
-O2 -std=c++14 -s USE_WEBGL2=1 -s FORCE_FILESYSTEM=1 -s TOTAL_MEMORY=33554432 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' --preload-file examples_data -s USE_SDL=2 -o html/$FILENAME.html
done

2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(scr_files spinning-cube spinning-primitives-tex spinning-primitives-openvr hello-engine gui spheres benchmark64k picking render-to-texture obj-viewer hello-engine-raw sprite-example custom-mesh-layout)
SET(scr_files skybox-example matcap spinning-cube spinning-primitives-tex spinning-primitives-openvr hello-engine gui spheres benchmark64k picking render-to-texture obj-viewer hello-engine-raw sprite-example custom-mesh-layout)

# Create custom build targets
FOREACH(scr_file ${scr_files})
Expand Down
14 changes: 11 additions & 3 deletions examples/benchmark64k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Benchmark64KExample {
r.frameRender = [&](){
render();
};
r.mouseEvent = [&](SDL_Event& event){
if (event.type == SDL_MOUSEBUTTONUP){
if (event.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
}
};

r.startEventLoop();
}
Expand Down Expand Up @@ -76,8 +83,9 @@ class Benchmark64KExample {
i++;
static Inspector inspector;
inspector.update();
inspector.gui();

if (showInspector){
inspector.gui();
}

ImGui::SliderInt("Grid size",&gridSize,1,BOX_GRID_DIM);
}
Expand All @@ -97,7 +105,7 @@ class Benchmark64KExample {
glm::mat4 translationMatrix;
} box[BOX_GRID_DIM][BOX_GRID_DIM][BOX_GRID_DIM];
glm::mat4 modelMatrix[BOX_GRID_DIM][BOX_GRID_DIM][BOX_GRID_DIM];

bool showInspector = false;
};

int main() {
Expand Down
29 changes: 20 additions & 9 deletions examples/custom-mesh-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <sre/SDLRenderer.hpp>
#include <sre/impl/GL.hpp>
#include <sre/Inspector.hpp>

using namespace sre;

Expand All @@ -25,29 +26,26 @@ class CustomMeshLayoutExample{
{1, 0,0,1},
{0, 1,0,1},
{0, 0,1,1},

});

mesh = Mesh::create()
.withPositions(positions)
.withAttribute("color",colors)
.withAttribute("vertex_color",colors)
.build();

std::string vertexShaderSource = R"(#version 140
std::string vertexShaderSource = R"(#version 330
in vec4 posxyzw;
in vec4 color;
in vec4 vertex_color;
out vec4 vColor;
uniform mat4 g_model;
uniform mat4 g_view;
uniform mat4 g_projection;
#pragma include "global_uniforms_incl.glsl"
void main(void) {
gl_Position = g_projection * g_view * g_model * posxyzw;
vColor = color;
vColor = vertex_color;
}
)";
std::string fragmentShaderSource = R"(#version 140
std::string fragmentShaderSource = R"(#version 330
out vec4 fragColor;
in vec4 vColor;
Expand All @@ -62,6 +60,13 @@ void main(void)
r.frameRender = [&](){
render();
};
r.mouseEvent = [&](SDL_Event& event){
if (event.type == SDL_MOUSEBUTTONUP){
if (event.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
}
};
r.startEventLoop();
}

Expand All @@ -72,6 +77,11 @@ void main(void)
.build();

rp.draw(mesh, glm::mat4(1), mat1);
static Inspector inspector;
inspector.update();
if (showInspector){
inspector.gui();
}

}
private:
Expand All @@ -80,6 +90,7 @@ void main(void)
Camera camera;
std::shared_ptr<Mesh> mesh;
std::shared_ptr<Material> mat1;
bool showInspector = false;
};

int main() {
Expand Down
10 changes: 9 additions & 1 deletion examples/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class GUIExample {
rotation.x += glm::radians((float)e.motion.xrel);
rotation.y += glm::radians((float)e.motion.yrel);
}
if (e.type == SDL_MOUSEBUTTONUP){
if (e.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
}
};
// start render loop
r.startEventLoop();
Expand Down Expand Up @@ -125,7 +130,9 @@ class GUIExample {
ImGui::End();
}
inspector.update();
inspector.gui();
if (showInspector){
inspector.gui();
}
}
private:
SDLRenderer r;
Expand All @@ -137,6 +144,7 @@ class GUIExample {
std::shared_ptr<Material> material;
Camera camera;
WorldLights worldLights;
bool showInspector = false;
};

int main() {
Expand Down
124 changes: 124 additions & 0 deletions examples/matcap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <iostream>

#include "sre/Texture.hpp"
#include "sre/Renderer.hpp"
#include "sre/Material.hpp"

#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <sre/SDLRenderer.hpp>
#include <sre/impl/GL.hpp>
#include <sre/Inspector.hpp>
#include <sre/ModelImporter.hpp>

using namespace sre;

class MapcapExample{
public:
MapcapExample(){
r.init();

std::vector<std::shared_ptr<Material>> materials_unused;

mesh = sre::ModelImporter::importObj("examples_data/", "suzanne.obj", materials_unused);

camera.setPerspectiveProjection(45,0.1,10);
camera.lookAt({0,0,3.5},{0,0,0},{0,1,0});

for (int i=0;i<4;i++){
textures[i] = sre::Texture::create().withFile(std::string("examples_data/matcap_0000")+std::to_string(i+1)+".png").build();
}
std::string vertexShaderSource = R"(#version 330
in vec4 position;
in vec3 normal;
out vec3 vNormal;
#pragma include "global_uniforms_incl.glsl"
void main(void) {
gl_Position = g_projection * g_view * g_model * position;
vNormal = normalize(mat3(g_view) *g_model_it * normal);
}
)";
std::string fragmentShaderSource = R"(#version 330
out vec4 fragColor;
in vec3 vNormal;
uniform sampler2D tex;
void main(void)
{
vec3 normal = normalize(vNormal);
fragColor = texture(tex,normal.xy * 0.5 + 0.5);
}
)";

mat1 = Shader::create()
.withSourceString(vertexShaderSource,ShaderType::Vertex)
.withSourceString(fragmentShaderSource, ShaderType::Fragment)
.build()->createMaterial();
std::string info;
if (!mat1->getShader()->validateMesh(mesh.get(), info)){
std::cout << info <<std::endl;
} else {
std::cout << "Mesh ok" << std::endl;
}

r.frameRender = [&](){
render();
};
r.mouseEvent = [&](SDL_Event& event){
if (event.type == SDL_MOUSEMOTION){
float mouseSpeed = 1/50.0f;
rotateY = event.motion.x*mouseSpeed;
rotateX = event.motion.y*mouseSpeed;
}
if (event.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
};
r.startEventLoop();
}

void render(){
auto rp = RenderPass::create()
.withCamera(camera)
.withClearColor(true,{0,0,0,1})
.build();

mat1->setTexture(textures[texture]);
rp.draw(mesh, glm::rotate(rotateX, glm::vec3(1,0,0))*glm::rotate(rotateY, glm::vec3(0,1,0)), mat1);

const char* items[] = { "00001", "00002", "00003", "00004"};
ImGui::SetNextWindowPos(ImVec2(0,0));
ImGui::SetNextWindowContentSize(ImVec2(300,100));
ImGui::Begin("Matcap");
ImGui::ListBox("Texture",&texture, items,4);
ImGui::End();

static Inspector inspector;
inspector.update();
if (showInspector){
inspector.gui();
}
}
private:
float time;
SDLRenderer r;
Camera camera;
std::shared_ptr<Mesh> mesh;
std::shared_ptr<Material> mat1;
std::array<std::shared_ptr<sre::Texture>,4> textures;
float rotateX = 0;
float rotateY = 0;
int texture = 0;
bool showInspector = false;
};

int main() {
new MapcapExample();

return 0;
}

14 changes: 13 additions & 1 deletion examples/obj-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <sre/ModelImporter.hpp>
#include <glm/gtx/string_cast.hpp>
#include <sre/Inspector.hpp>

using namespace sre;

Expand Down Expand Up @@ -50,6 +51,12 @@ class ObjViewerExample {
render();
};

r.mouseEvent = [&](SDL_Event& event){
if (event.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
};

r.startEventLoop();
}

Expand Down Expand Up @@ -145,7 +152,11 @@ class ObjViewerExample {
"Drop obj file here"
#endif
);

static Inspector inspector;
inspector.update();
if (showInspector){
inspector.gui();
}
i++;
}

Expand Down Expand Up @@ -224,6 +235,7 @@ class ObjViewerExample {
#else
'/';
#endif
bool showInspector = false;
};

int main() {
Expand Down
13 changes: 13 additions & 0 deletions examples/picking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <glm/gtx/euler_angles.hpp>
#include <sre/SDLRenderer.hpp>
#include <glm/gtx/string_cast.hpp>
#include <sre/Inspector.hpp>

using namespace sre;
using namespace std;
Expand Down Expand Up @@ -61,6 +62,9 @@ class PickingExample {
mouseX = static_cast<int>(pos.x);
mouseY = static_cast<int>(pos.y);
}
if (e.button.button==SDL_BUTTON_RIGHT){
showInspector = true;
}
};
r.startEventLoop();
}
Expand All @@ -80,10 +84,18 @@ class PickingExample {
}
}
drawTopTextAndColor(pixelValue);
static Inspector inspector;
inspector.update();
if (showInspector){
inspector.gui();
}

renderPass.finish();
auto pixelValues = renderPass.readPixels(mouseX, mouseY); // read pixel values from defualt framebuffer (before gui is rendered)

pixelValue = pixelValues[0];


}

void drawTopTextAndColor(sre::Color color){
Expand All @@ -107,6 +119,7 @@ class PickingExample {
int i=0;
int mouseX;
int mouseY;
bool showInspector = false;
};

int main() {
Expand Down
Loading

0 comments on commit fac3ac7

Please sign in to comment.