From 9c12598bf5710330cafc21456249ba34ffe25b9b Mon Sep 17 00:00:00 2001 From: Anakin Date: Thu, 3 Nov 2016 19:46:36 +0100 Subject: [PATCH] trying to give MVP via buffer, nothing displayed -.- --- MshViewer/Shader/FragmentColorShader.mv2shdr | 12 ----------- ...xtureShader.mv2shdr => TextureShader.frag} | 0 ...xtureShader.mv2shdr => TextureShader.vert} | 9 ++++++--- MshViewer/Shader/VertexColorShader.mv2shdr | 20 ------------------- MshViewer/Source/OpenGlController.cpp | 16 ++++++++++++--- 5 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 MshViewer/Shader/FragmentColorShader.mv2shdr rename MshViewer/Shader/{FragmentTextureShader.mv2shdr => TextureShader.frag} (100%) rename MshViewer/Shader/{VertexTextureShader.mv2shdr => TextureShader.vert} (61%) delete mode 100644 MshViewer/Shader/VertexColorShader.mv2shdr diff --git a/MshViewer/Shader/FragmentColorShader.mv2shdr b/MshViewer/Shader/FragmentColorShader.mv2shdr deleted file mode 100644 index 5f13d27..0000000 --- a/MshViewer/Shader/FragmentColorShader.mv2shdr +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 core - -// Input -in vec3 fragmentColor; - -// Ouput data -out vec3 color; - -void main() -{ - color = fragmentColor; -} \ No newline at end of file diff --git a/MshViewer/Shader/FragmentTextureShader.mv2shdr b/MshViewer/Shader/TextureShader.frag similarity index 100% rename from MshViewer/Shader/FragmentTextureShader.mv2shdr rename to MshViewer/Shader/TextureShader.frag diff --git a/MshViewer/Shader/VertexTextureShader.mv2shdr b/MshViewer/Shader/TextureShader.vert similarity index 61% rename from MshViewer/Shader/VertexTextureShader.mv2shdr rename to MshViewer/Shader/TextureShader.vert index ada5b7e..20731d1 100644 --- a/MshViewer/Shader/VertexTextureShader.mv2shdr +++ b/MshViewer/Shader/TextureShader.vert @@ -3,18 +3,21 @@ // Input vertex data, different for all executions of this shader. layout(location = 0) in vec3 vertexPosition_modelspace; layout(location = 1) in vec2 vertexUV; -//layout(location = 2) in mat4 mvp; +layout(location = 2) in mat4 mvp; +//layout(location = 3) in mat4 mvp; +//layout(location = 4) in mat4 mvp; +//layout(location = 5) in mat4 mvp; // Output out vec2 UV; // Values that stay constant for the whole mesh. -uniform mat4 MVP; +//uniform mat4 MVP; void main(){ // Output position of the vertex, in clip space : MVP * position - gl_Position = MVP * vec4(vertexPosition_modelspace, 1); + gl_Position = mvp * vec4(vertexPosition_modelspace, 1); UV = vertexUV; diff --git a/MshViewer/Shader/VertexColorShader.mv2shdr b/MshViewer/Shader/VertexColorShader.mv2shdr deleted file mode 100644 index e07d841..0000000 --- a/MshViewer/Shader/VertexColorShader.mv2shdr +++ /dev/null @@ -1,20 +0,0 @@ -#version 450 core - -// Input vertex data, different for all executions of this shader. -layout(location = 0) in vec3 vertexPosition_modelspace; -layout(location = 1) in vec3 vertexColor; - -// Output -out vec3 fragmentColor; - -// Values that stay constant for the whole mesh. -uniform mat4 MVP; - -void main(){ - - // Output position of the vertex, in clip space : MVP * position - gl_Position = MVP * vec4(vertexPosition_modelspace,1); - - fragmentColor = vertexColor; - -} diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index 316cb2c..ffefbef 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -9,8 +9,8 @@ #include "Texture.h" #include -#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr" -#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr" +#define VERTEX_SHADER "Shader/TextureShader.vert" +#define FRAGMENT_SHADER "Shader/TextureShader.frag" ///////////////////////////////////////////////////////////////////////// @@ -91,6 +91,13 @@ void OpenGLController::processInit() glVertexAttribPointer(VERTEX_INDEX_UV, VERTEX_COMPONENTS_UV, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)VERTEX_OFFSET_UV); glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, gluiInstanceBufferID); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 0)); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 4)); + glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 8)); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 12)); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); @@ -245,7 +252,10 @@ void OpenGLController::updateScene() glUseProgram(gluiShaderPrgmID); // tell shader transformation - glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix()[0][0]); + //glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix()[0][0]); + glBindBuffer(GL_UNIFORM_BUFFER, gluiInstanceBufferID); + glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 1, NULL, GL_STREAM_DRAW); + glBindBuffer(GL_UNIFORM_BUFFER, 0); // bind texture in texture unit 0 glActiveTexture(GL_TEXTURE0);