# HG changeset patch # User František Kučera # Date 1701216679 -3600 # Node ID 3faef2f5128efe734c4b3071dd3eca54dbc8f196 # Parent fb65455622b93d9d63080f9ebb81896eca7fa9db better GLSL variable names diff -r fb65455622b9 -r 3faef2f5128e Shark.cpp --- a/Shark.cpp Tue Nov 28 22:45:33 2023 +0100 +++ b/Shark.cpp Wed Nov 29 01:11:19 2023 +0100 @@ -237,13 +237,13 @@ glm::radians(ctx.fov), width / height, 0.1f, 100.0f); - glUniformMatrix4fv(ProgAttr.projection, 1, GL_FALSE, &projection[0][0]); + glUniformMatrix4fv(ProgAttr.uProjection, 1, GL_FALSE, &projection[0][0]); glm::mat4 view = glm::lookAt( ctx.cameraPos, ctx.cameraPos + ctx.cameraFront, ctx.cameraUp); - glUniformMatrix4fv(ProgAttr.view, 1, GL_FALSE, &view[0][0]); + glUniformMatrix4fv(ProgAttr.uView, 1, GL_FALSE, &view[0][0]); // glBindVertexArray(vao); @@ -252,7 +252,7 @@ // float angle = 20.0f; // glm::vec3 xxx = glm::vec3(1.0f, 0.3f, 0.5f); // model = glm::rotate(model, glm::radians(angle), xxx); - glUniformMatrix4fv(ProgAttr.model, 1, GL_FALSE, &model[0][0]); + glUniformMatrix4fv(ProgAttr.uModel, 1, GL_FALSE, &model[0][0]); glDrawArrays(GL_TRIANGLES, 0, 2 * 3); // viz loadVertices() kde plníme data std::cerr << "GLSL: glDrawArrays()" << std::endl; @@ -286,16 +286,16 @@ }; // Vertex data: - glVertexAttribPointer(ProgAttr.vertexXYZ, 3, // vertex items + glVertexAttribPointer(ProgAttr.aVertexXYZ, 3, // vertex items GL_FLOAT, GL_FALSE, 5 * sizeof (float), (void*) 0); - glEnableVertexAttribArray(ProgAttr.vertexXYZ); + glEnableVertexAttribArray(ProgAttr.aVertexXYZ); // Texture positions: - glVertexAttribPointer(ProgAttr.textureXY, 2, // texture items + glVertexAttribPointer(ProgAttr.aTextureXY, 2, // texture items GL_FLOAT, GL_FALSE, 5 * sizeof (float), (void*) (3 * sizeof (float))); - glEnableVertexAttribArray(ProgAttr.textureXY); + glEnableVertexAttribArray(ProgAttr.aTextureXY); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof (vertices[0]), @@ -415,14 +415,14 @@ glLinkProgram(program); - ProgAttr.vertexXYZ = glGetAttribLocation(program, "vertices"); - ProgAttr.textureXY = glGetAttribLocation(program, "textureCoordinates"); - ProgAttr.model = glGetUniformLocation(program, "model"); - ProgAttr.view = glGetUniformLocation(program, "view"); - ProgAttr.projection = glGetUniformLocation(program, "projection"); - ProgAttr.jazz = glGetUniformLocation(program, "jazz"); - ProgAttr.color = glGetFragDataLocation(program, "outColor"); - glBindFragDataLocation(program, ProgAttr.color, "outColor"); + ProgAttr.aVertexXYZ = glGetAttribLocation(program, "aVertexXYZ"); + ProgAttr.aTextureXY = glGetAttribLocation(program, "aTextureXY"); + ProgAttr.uModel = glGetUniformLocation(program, "uModel"); + ProgAttr.uView = glGetUniformLocation(program, "uView"); + ProgAttr.uProjection = glGetUniformLocation(program, "uProjection"); + ProgAttr.uTexture = glGetUniformLocation(program, "uTexture"); + ProgAttr.fColor = glGetFragDataLocation(program, "fColor"); + glBindFragDataLocation(program, ProgAttr.fColor, "fColor"); // listVariables(program); GLint linkStatus; glGetProgramiv(program, GL_LINK_STATUS, &linkStatus); diff -r fb65455622b9 -r 3faef2f5128e Shark.h --- a/Shark.h Tue Nov 28 22:45:33 2023 +0100 +++ b/Shark.h Wed Nov 29 01:11:19 2023 +0100 @@ -40,15 +40,15 @@ private: struct { - GLint vertexXYZ = -2; - GLint textureXY = -2; + GLint aVertexXYZ = -2; + GLint aTextureXY = -2; - GLint color = -2; + GLint fColor = -2; - GLint model = -2; - GLint view = -2; - GLint projection = -2; - GLint jazz = -2; + GLint uModel = -2; + GLint uView = -2; + GLint uProjection = -2; + GLint uTexture = -2; } ProgAttr; struct { diff -r fb65455622b9 -r 3faef2f5128e shaders/first.frag --- a/shaders/first.frag Tue Nov 28 22:45:33 2023 +0100 +++ b/shaders/first.frag Wed Nov 29 01:11:19 2023 +0100 @@ -1,10 +1,10 @@ #version 330 core -uniform sampler2D jazz; -in vec2 textureCoordinate; -out vec3 outColor; +uniform sampler2D uTexture; +in vec2 vTextureXY; +out vec3 fColor; void main(){ - outColor = texture(jazz, textureCoordinate).xyz; - // outColor *= vec3(0.8, 1., 0.2); + fColor = texture(uTexture, vTextureXY).rgb; + // fColor *= vec3(0.8, 1., 0.2); } diff -r fb65455622b9 -r 3faef2f5128e shaders/first.vert --- a/shaders/first.vert Tue Nov 28 22:45:33 2023 +0100 +++ b/shaders/first.vert Wed Nov 29 01:11:19 2023 +0100 @@ -1,13 +1,13 @@ #version 330 core -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -in vec3 vertices; -in vec2 textureCoordinates; -out vec2 textureCoordinate; +uniform mat4 uModel; +uniform mat4 uView; +uniform mat4 uProjection; +in vec3 aVertexXYZ; +in vec2 aTextureXY; +out vec2 vTextureXY; void main() { - gl_Position = projection * view * model * vec4(vertices, 1.0f); - textureCoordinate = textureCoordinates; + gl_Position = uProjection * uView * uModel * vec4(aVertexXYZ, 1.0f); + vTextureXY = aTextureXY; }