diff --git a/core/Material.cpp b/core/Material.cpp index b037263..c74f74f 100644 --- a/core/Material.cpp +++ b/core/Material.cpp @@ -27,9 +27,9 @@ Texture Texture::FromFile(const char *filename) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); int nrChannels; - unsigned char* data = stbi_load(filename, &tex.width, &tex.height, &nrChannels, 0); + unsigned char* data = stbi_load(filename, &tex.width, &tex.height, &nrChannels, 4); if (data) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); } else { Util::Die("Error loading texture file: ", filename); diff --git a/core/Screen.cpp b/core/Screen.cpp index ef12cab..8f6dcb6 100644 --- a/core/Screen.cpp +++ b/core/Screen.cpp @@ -1,10 +1,10 @@ #include "Screen.h" const Vertex vertices[] = { - Vertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f), Vertex(-1.0f, 1.0f, 0.0f, 0.0f, 1.0f), + Vertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f), Vertex(1.0f, -1.0f, 0.0f, 1.0f, 0.0f), - + Vertex(-1.0f, 1.0f, 0.0f, 0.0f, 1.0f), Vertex(1.0f, -1.0f, 0.0f, 1.0f, 0.0f), Vertex(1.0f, 1.0f, 0.0f, 1.0f, 1.0f) diff --git a/core/couch.cpp b/core/couch.cpp index 6c403e0..0a8d12d 100644 --- a/core/couch.cpp +++ b/core/couch.cpp @@ -85,6 +85,9 @@ int main() { glViewport(0, 0, width, height); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + root = Node::GetRoot(); Input *input = Input::GetInstance(); diff --git a/demo/grate_floor_lowres.png b/demo/grate_floor_lowres.png new file mode 100644 index 0000000..fbd1ba0 Binary files /dev/null and b/demo/grate_floor_lowres.png differ diff --git a/demo/main.lua b/demo/main.lua index 44035ba..44aa2b8 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -36,7 +36,6 @@ function init() ball1:SetupMesh() ball1.material.tex = couch.Texture.FromFile("container.png") ball1.material.usesTex = true - print(ball1.material.tex.width, ball1.material.tex.height) couch.Node.GetRoot().children:Append(ball1) ball1.transform:Translate(0.0, 3.0, 0.0) @@ -47,6 +46,13 @@ function init() trough.material.usesTex = true couch.Node.GetRoot().children:Append(trough) trough.transform:Translate(10.0, 0.0, 0.0) + + scaffold = couch.Mesh.FromFile("scaffold.glb") + scaffold:SetupMesh() + scaffold.material.tex = couch.Texture.FromFile("grate_floor_lowres.png") + scaffold.material.usesTex = true + couch.Node.GetRoot().children:Append(scaffold) + scaffold.transform:Translate(-10.0, 0.0, 0.0) end function update(delta) diff --git a/demo/scaffold.glb b/demo/scaffold.glb new file mode 100644 index 0000000..4d018c5 Binary files /dev/null and b/demo/scaffold.glb differ diff --git a/shaders/flat.frag b/shaders/flat.frag index f77cb12..29b52cf 100644 --- a/shaders/flat.frag +++ b/shaders/flat.frag @@ -2,8 +2,6 @@ in vec3 UV; -out vec4 FragColor; - struct Material { vec3 color; bool usesColor; @@ -14,11 +12,14 @@ struct Material { uniform Material material; void main() { - FragColor = vec4(0.0); + gl_FragColor = vec4(0.0); if (material.usesColor) { - FragColor += vec4(material.color, 1.0); + gl_FragColor += vec4(material.color, 1.0); } if (material.usesTex) { - FragColor += texture(material.tex, UV.xy / UV.z); + gl_FragColor += texture(material.tex, UV.xy / UV.z); + } + if (gl_FragColor.w < 0.99) { + discard; } }