From d54aa2aa7e3abe4a039775603e9303684e3843bf Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Thu, 14 Apr 2016 19:39:25 +0200 Subject: [PATCH] Texture kann schon Gezeichnet werden, aber entweder wird der Buffer nicht richtig geschrieben oder gelesen... --- Weave/Graphix/Model/Plane.cpp | 3 ++- Weave/Graphix/Textures/Texture.cpp | 3 +++ Weave/Scene/Scene.cpp | 17 ++++++++++------- shader/basicTexture_FS.hlsl | 4 ++-- shader/basic_FS.hlsl | 5 ++++- shader/lightingTexture_FS.hlsl | 10 +++++----- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Weave/Graphix/Model/Plane.cpp b/Weave/Graphix/Model/Plane.cpp index 300bc25..fb07a86 100644 --- a/Weave/Graphix/Model/Plane.cpp +++ b/Weave/Graphix/Model/Plane.cpp @@ -34,7 +34,8 @@ void Plane::drawModel() const Shader::gActive()->setUniformLocation("uPlain", 1); Shader::gActive()->setUniformLocation("uFar", 0); - glDrawArrays(GL_QUADS, 0, 4); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + //glDrawArrays(GL_QUADS, 0, 4); glBindVertexArray(0); } diff --git a/Weave/Graphix/Textures/Texture.cpp b/Weave/Graphix/Textures/Texture.cpp index 2b7fc58..4276fd3 100644 --- a/Weave/Graphix/Textures/Texture.cpp +++ b/Weave/Graphix/Textures/Texture.cpp @@ -2,6 +2,7 @@ #include #include "../../Message.h" +#include "../Shader.h" #include "tImage.h" @@ -97,6 +98,8 @@ void Texture::useTexture(unsigned int _unit) const /* bind Texture*/ glActiveTexture(GL_TEXTURE0 + _unit); glBindTexture(texture_target, handle); + + Shader::gActive()->setUniformLocation("uColorTexture", _unit); } void Texture::updateSize(unsigned int _width, unsigned int _height) diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index b8e6633..9f136b0 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -57,9 +57,10 @@ lookat(_lookat) bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0)); - blur = new fBufferObject(2); render = new fBufferObject(1); + blur = new fBufferObject(2,false); + blur->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight()); render->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight()); @@ -173,7 +174,8 @@ void Scene::update(float deltaT) void Scene::draw() const { - //render->useBuffer(); + render->useBuffer(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); viewPort.useViewPort(); //Skybox @@ -193,11 +195,12 @@ void Scene::draw() const (*i)->draw(); } - //render->clearBuffer(); - //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //Shader::gBasicTexture()->useShader(); - //render->getTexture(0)->useTexture(0); - //Model::getPlaneModel()->drawModel(mat4(1.f)); + render->clearBuffer(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + Shader::gBasicTexture()->useShader(); + //render->getTexture()->useTexture(); + SceneObjects.front()->gTexture()->useTexture(); + Model::getPlaneModel()->drawModel(mat4(1.f)); } diff --git a/shader/basicTexture_FS.hlsl b/shader/basicTexture_FS.hlsl index db0e01d..302d949 100644 --- a/shader/basicTexture_FS.hlsl +++ b/shader/basicTexture_FS.hlsl @@ -3,11 +3,11 @@ //in worldNormal; in vec2 fUVs; -layout(location = 0) out vec4 gl_FragColor; +layout(location = 0) out vec4 FragColor; uniform sampler2D uColorTexture; void main() { - gl_FragColor = texture(uColorTexture, fUVs); + FragColor = texture(uColorTexture, fUVs); } \ No newline at end of file diff --git a/shader/basic_FS.hlsl b/shader/basic_FS.hlsl index c2b701a..3dc3838 100644 --- a/shader/basic_FS.hlsl +++ b/shader/basic_FS.hlsl @@ -1,7 +1,10 @@ //Fragment Shader #version 330 + +layout(location = 0) out vec4 FragColor; + uniform vec4 uFragmentColor = vec4(0.6, 0, 0, 0.6); void main(){ - gl_FragColor = uFragmentColor; + FragColor = uFragmentColor; } diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 4b7f56a..c3a96a7 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -5,7 +5,7 @@ in vec2 fUVs; in vec3 PointLightPosition1, DirectionalLightDirection1; -layout (location = 0) out vec4 gl_FragColor; +layout (location = 0) out vec4 FragColor; uniform sampler2D uColorTexture; uniform vec4 material; //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3) @@ -37,15 +37,15 @@ void main() float squaredist1 = worldPointLightDir1.x * worldPointLightDir1.x + worldPointLightDir1.y * worldPointLightDir1.y + worldPointLightDir1.z * worldPointLightDir1.z; - gl_FragColor = vec4(uvColor.rgb * (AmbientLightColor * material[0] + FragColor = vec4(uvColor.rgb * (AmbientLightColor * material[0] + PointLightColor1 * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1 + DirectionalLightColor1 * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst)) ), uvColor.a); - //gl_FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f); - //gl_FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f); + //FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f); + //FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f); //vec3 uvColor = texture(uColorTexture, fUVs).rgb; - //gl_FragColor = vec4(uvColor, 1.0); + //FragColor = vec4(uvColor, 1.0); } -- 2.47.3