hi, i know that questions where their is alot of code are frowned upon, but ive spent close to three hours trying to debug this and i can’t figure out what is wrong with it. what i am trying to do is push an object through multiple light sources using transform feedback. basically i have a shader program designed for translating the objects vertices into world space coordinates. i then also try to capture that data back into some buffers without drawing anything (i use glEnable(GL_RASTERIZER_DISCARD)) i then pass the world coordinates through 1 ambient light source and capture the colors for each vertex. then i pass it through as many point and directional light sources (im gonna add spot when i debug this) as wanted and continue to capture the colors. i then do glDisable(GL_RASTERIZER_DISCARD) and draw the captured world coordinates with the captured colors. their is quite a bit of copying between bufers to. i copy the captured coordinates and colors to other buffers. i wont put all the code in here just one pass through my world coordinates program, one pass through the ambient program, one pass through the program that draws the captured data to the screen and the corresponding shaders.
GLint ibuffer, nbuffer, vbuffer;
GLuint vao[3];
glGenVertexArrays(3, vao);
glBindVertexArray(vao[0]);
glUseProgram(progtransform);
glEnable(GL_RASTERIZER_DISCARD);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, vertexbufferout);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type3D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 7, vertexbufferout, 0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, normalbufferout);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type3D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 8, normalbufferout, 0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
glTransformFeedbackVaryings(progtransform, 2, varyingstransform, GL_SEPARATE_ATTRIBS);
glLinkProgram(progtransform);
glGenBuffers(1, &ibuffer);
glGenBuffers(1, &nbuffer);
glGenBuffers(1, &vbuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(struct TypeVertexIndexList3) * mesh->MeshIndexListSize, mesh->MeshIndexList, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct Type3D) * mesh->MeshVertexListSize, mesh->MeshVertexList, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, nbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(struct Type3D) * mesh->MeshNormalListSize, mesh->MeshNormalList, GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
glEnableVertexAttribArray(1);
GLint translatemeshloc = glGetUniformLocation(progtransform, "translatemesh");
GLint translatecamloc = glGetUniformLocation(progtransform, "translatecam");
glUniform3fv(translatemeshloc, 1, mesh->WorldCoords.vec);
glUniform3fv(translatecamloc, 1, cam->Pos.vec);
glDrawElements(GL_TRIANGLES, 3 * mesh->MeshIndexListSize, GL_UNSIGNED_INT, (void *)0);
glBindBuffer(GL_COPY_WRITE_BUFFER, vertexbufferin);
glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type3D) * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
glBindBuffer(GL_COPY_READ_BUFFER, vertexbufferout);
//glBindBuffer(GL_COPY_WRITE_BUFFER, vertexbufferin);
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
glBindBuffer(GL_COPY_WRITE_BUFFER, normalbufferin);
glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type3D) * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
glBindBuffer(GL_COPY_READ_BUFFER, normalbufferout);
//glBindBuffer(GL_COPY_WRITE_BUFFER, normalbufferin);
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
//glEnable(GL_RASTERIZER_DISCARD);
glBindVertexArray(vao[1]);
if (lights->ambient != NULL)
{
glUseProgram(progambient);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, colorbufferout);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 9, colorbufferout, 0, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize);
glTransformFeedbackVaryings(progambient, 1, varyingsambient, GL_SEPARATE_ATTRIBS);
glLinkProgram(progambient);
GLint colorobjectloc = glGetUniformLocation(progambient, "colorobject");
GLint colorlightloc = glGetUniformLocation(progambient, "colorlight");
GLint intensityloc = glGetUniformLocation(progambient, "intensity");
glUniform4fv(colorobjectloc, 1, mesh->RGBA);
glUniform4fv(colorlightloc, 1, lights->ambient->colorlight.vec);
glUniform1f(intensityloc, lights->ambient->intensity);
glDrawArrays(GL_TRIANGLES, 0, 3 * mesh->MeshIndexListSize);
glBindBuffer(GL_COPY_WRITE_BUFFER, colorbufferin);
glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
glBindBuffer(GL_COPY_READ_BUFFER, colorbufferout);
//glBindBuffer(GL_COPY_WRITE_BUFFER, colorbufferin);
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type4D) * mesh->MeshIndexListSize);
}
else
{
printf("
##An ambient light is needed
");
exit(1);
}
glBindVertexArray(vao[2]);
glDisable(GL_RASTERIZER_DISCARD);
glUseProgram(progdraw);
GLint perspectiveloc = glGetUniformLocation(progdraw, "perspective");
GLint uvnloc = glGetUniformLocation(progdraw, "uvn");
glUniformMatrix4fv(perspectiveloc, 1, GL_FALSE, cam->ProjectionMat.marray);
glUniformMatrix3fv(uvnloc, 1, GL_FALSE, cam->UVNMat.marray);
glBindBuffer(GL_ARRAY_BUFFER, colorbufferin);
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (void *)0);
glEnableVertexAttribArray(6);
glBindBuffer(GL_ARRAY_BUFFER, vertexbufferin);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
glEnableVertexAttribArray(4);
glDrawArrays(GL_TRIANGLES, 0, 3 * mesh->MeshIndexListSize);
here are the shaders
transform
const char *vshadertransform =
"#version 430 core
"
"layout (location = 0) in vec3 vPosition;
"
"layout (location = 1) in vec3 vNormal;
"
"layout (location = 7) out vec3 verticestfout;
"
"layout (location = 8) out vec3 normalstfout;
"
"uniform vec3 translatemesh;
"
"uniform vec3 translatecam;
"
"void main()
"
"{
"
"verticestfout = vPosition - translatecam + translatemesh;
"
"normalstfout = vNormal;
"
"}
";
ambient
const char *vshaderambient =
"#version 430 core
"
"uniform vec4 colorobject;
"
"uniform vec4 colorlight;
"
"uniform float intensity;
"
"layout (location = 9) out vec4 colorstfout;
"
"void main()
"
"{
"
"colorstfout = min(colorobject + (colorobject + colorlight * intensity), vec4(1, 1, 1, 1));
"
"}
";
drawing program
const char *vshaderdraw =
"#version 430 core
"
"uniform mat4 perspective;
"
"uniform mat3 uvn;
"
"layout (location = 4) in vec3 verticestfin;
"
"layout (location = 6) in vec4 colorstfin;
"
"out vec4 color;
"
"void main()
"
"{
"
"gl_Position = perspective * vec4(uvn * verticestfin, 1);
"
"color = colorstfin;
"
"}
";
const char *fshaderdraw =
"#version 430 core
"
"in vec4 color;
"
"out vec4 colorout;
"
"void main()
"
"{
"
"colorout = color;
"
"}
";
thanks alot
(btw the screen just shows the color that i cleared it to, it doesnt draw the image.)